AnsweredAssumed Answered

How to reverse bitfield arrangement?

Question asked by Meimei Ouyang on Jul 31, 2017
Latest reply on Aug 2, 2017 by Alexander Fedotov

Hi,

 

I have a structure that contains bitfields in code. The question is on how to change the arrangement order of the bitfields within the byte.

Instead of having it arranged from MSB  to LSB, (What S32 DS doing by default)

typedef struct

{

   uint8_t    a:4;

   uint8_t    b:3;

} test;

 

LSB    0    1    2    3    4    5    6    7    MSB

       none b0  b1  b2  a0  a1  a2  a3

I would like to make it arranged from LSB to MSB,

typedef struct

{

   uint8_t    a:4;

   uint8_t    b:3;

} test;

 

LSB    0    1    2    3    4    5    6    7    MSB

          a0  a1  a2  a3  b0  b1  b2 none

 

 

This issue caused very serious problems on CAN communication legacy code as all the signals are defined as bitfields. 

 

In CodeWarrior, there was an option to config the compiler:

#pragma reverse_bitfields on

http://www.nxp.com/docs/en/reference-manual/CCOMPILERRM.pdf  Page 192

 

I would like how to do the same settings in S32 DS. Thanks in advance!

Outcomes