Hello
The problem with bitfields in ANSI C is that they are not portable across compiler vendor or architecture.
The ANSI C standard does not specify i how a bitfield might be allocated in memory.
Depending on the vendor and architecture it might be LSB first or MSB first.
There might also be some padding bits between the fields.
CodeWarrior for Coldfire uses MSB first as allocation scheme.
With the syntax you are using, the compiler will allocate the bits as follows:
Source : bit 15-10
msg_id: Bit 0-8
msg_type: Bit 7
request_type: bit 6
dataType: bit 0-5
If you wish to get Source allocated on bit 0-4 you need to define your bitfield as follows:
typedef struct {
unsigned int data_type: 6;
unsigned int request_type: 1;
unsigned int msg_type: 1;
unsigned int msg_id: 3;
unsigned int source : 5;
} BitFields_T;
CrasyCat