S12Z 32bit struct with bitfields

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S12Z 32bit struct with bitfields

901 Views
ecorini
Contributor I

Hello, 

I'm using S12Z microcontroller on CW 10.6 with these code generation options:

Memory Model: Small

Bit-field gap limit: 255

Bit-filed byte allocation from LSB to MSB: enabled

Bit-filed type size reduction: disabled

This struct:

typedef struct _TestStruct
{
   unsigned long field1 : 1;
   unsigned long filed2 : 31;
} tTestStruct;

has size of 5bytes in map file. What is the reason?

thanks for your response!

Tags (3)
0 Kudos
3 Replies

569 Views
stanish
NXP Employee
NXP Employee

Hello,

Thanks for the question.

I've discussed this behavior with our compiler expert.

It is caused by the S12Z compiler behavior when allocating structures. It allocates bitfields within 8 and 16-bit wide (with direct impact from the options described in the compiler manual).  Everything that exceeds 16 bit is allocated as a different field.

The bitfield allocation unit is byte and if things don't fit in byte (or too large gaps), the allocation can be extended to word. For 3 or 4 bytes, the allocation is done differently and does not allow merging other fields in a bitfield larger than a word (2-bytes)

So no matter how you arrange the structure, or the bit-field options you use, a bitfield larger than 16-bits will always be allocated alone.

Hope it helps to clarify this issue.

Stan

0 Kudos

569 Views
ecorini
Contributor I

Thank you for the reply

0 Kudos

569 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

the issue is being solved. There were some test done and it was reported to a CodeWarrior application team.

now it looks like "feature" but unacceptable. The CW Apps engineer has promised to get some info.

Best regards,

Ladislav

0 Kudos