Hi - This is a follow up from my last post: http://cboard.cprogramming.com/showthread.php?t=109945
but need help with my code. I would like to test that accessing the HW reg using a struct unionized with a UINT32 word, will actually use 32-bits. Here is my code:
Code:
#include <stdio.h>
typedef union
{
struct {
/// Reserved - read as 0
unsigned reserved : 30;
/** This bit contains the interrupt status. Reading this register
* clears this bit.
*/
unsigned stats : 1;
/** This field masks the interrupt.
* 0 - Masked
* 1 - Enabled
*/
unsigned maskn : 1;
} bits;
unsigned long word;
} volatile RegStruct;
RegStruct *hwReg = (RegStruct *)0x08002000
void SetReg0(void)
{
int newVal = 0;
RegStruct val;
val.word = hwReg->word;
val.bits.maskn = newVal;
hwReg->word = val.word;
}
void SetReg1(void)
{
int newVal = 1;
RegStruct val;
val.word = hwReg->word;
val.bits.maskn = newVal;
hwReg->word = val.word;
}
int main(void)
{
RegStruct reg;
SetReg0();
int x = reg.bits.maskn;
printf("This is setting to 0: %d \n",x);
SetReg1();
int y = reg.bits.maskn;
printf("This is setting to 1 : %d \n", y);
return 0;
}
...but when I run gcc, I get the following errors:
testdriver2.c:31: error: syntax error before 'void'
testdriver2.c:35: error: syntax error before '.' token
Why is this simple test failing? Please help.