This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

bit field order

Hi,

I am using the TMS570 with CCS6 and Halcogen 4.1.

 

I have the following bit structure that I am porting from a different processor, and it looks like the order of the bit structure is reversed.  For example, I would expect frameid_out to be bit 0, and pip closed to be bit 13.  But when I toggle pip closed, the 13th bit from the right toggles, not the 13th bit from the left.  I believe the old processor is little endian, and the TMS570 is big endian.

 

Is there a way to force the bit order?

 

typedef union FrameIn_Obj
{
   uint32_t   lword;
   struct
    {
      unsigned int  frameid_out     : 1;
      unsigned int  encoder2_id     : 1;
      unsigned int  rlypwr_ok       : 1;
      unsigned int  estop_ok        : 1;
      unsigned int  upperTravLmt    : 1;
      unsigned int  lowerTravLmt    : 1;
      unsigned int  drv_enabled     : 1;
      unsigned int  pwramp_ok       : 1;
      unsigned int  motortmp_ok     : 1;
      unsigned int  topgrip_closed  : 1;
      unsigned int  botgrip_closed  : 1;
      unsigned int  closegrip_req   : 1;
      unsigned int  intrlock_ok     : 1;
      unsigned int  pip_closed      : 1;
      unsigned int  handset_up      : 1;
      unsigned int  handset_dn      : 1;
      unsigned int  clutch_switch   : 1;
      unsigned int  FIBFrameFault   : 1;
      unsigned int  shieldDoorOpen  : 1;
      unsigned int  shieldDoorClosed: 1;
      unsigned int  safeMode        : 1;
      unsigned int  setupMode       : 1;
      unsigned int  FIBWdog         : 1;
      unsigned int  high_clutch     : 1;
    } bits;
} FrameIn_Obj;
  • Hi David,

    I believe the C standard leaves bit order up to compiler implementation. That is, it is not defined in the standard itself. Many compilers have a command line argument flags to reverse the default order for a given compiler. That is, if the compiler default is LSB at the bottom of the structure, it can be reversed.

    Perhaps the TI compiler has this capability. I cannot specifically answer that though.

    Regards,

    Jim

  • David Sabol said:
    Is there a way to force the bit order?

    No.  The bit field order is documented in the section titled Bit Fields in the ARM compiler manual.  It generally follows the byte ordering of the device.

    Thanks and regards,

    -George