J
jlara
Working on an embedded controller, I generally find it convenient to
define the following de-referenced pointer:
#define portb (*(unsigned char *)(0x03u))
This enable me to write to a port as follows:
portb = 0x0f;
But when I want to define a register as follows, the code does not
compile:
typedef union
{
uint8 byte;
struct
{
uint8 : 4;
uint8 tffca : 1;
uint8 tsfrz : 1;
uint8 tswai : 1;
uint8 ten : 1; /* timer enable */
}bit;
}tSCR1;
#define scr1 (*(tSCR1 *)(0x4c))
useage:
scr1.bit.ten = 1; /* the compiler complains about this */
I find it very convenient to use this scheme if possible. It is very
clear what is being manipulated just by reading the code. I prefer
this over: "scr1 = 0x01;". Is it possible to dereference this union
in the same fashion as the first example? Thanks very much in advance.
define the following de-referenced pointer:
#define portb (*(unsigned char *)(0x03u))
This enable me to write to a port as follows:
portb = 0x0f;
But when I want to define a register as follows, the code does not
compile:
typedef union
{
uint8 byte;
struct
{
uint8 : 4;
uint8 tffca : 1;
uint8 tsfrz : 1;
uint8 tswai : 1;
uint8 ten : 1; /* timer enable */
}bit;
}tSCR1;
#define scr1 (*(tSCR1 *)(0x4c))
useage:
scr1.bit.ten = 1; /* the compiler complains about this */
I find it very convenient to use this scheme if possible. It is very
clear what is being manipulated just by reading the code. I prefer
this over: "scr1 = 0x01;". Is it possible to dereference this union
in the same fashion as the first example? Thanks very much in advance.