S12Z 32bit struct with bitfields

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

S12Z 32bit struct with bitfields

1,170件の閲覧回数
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!

タグ(3)
0 件の賞賛
返信
3 返答(返信)

838件の閲覧回数
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 件の賞賛
返信

838件の閲覧回数
ecorini
Contributor I

Thank you for the reply

0 件の賞賛
返信

838件の閲覧回数
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 件の賞賛
返信