AnsweredAssumed Answered

Bit field operation issue.

Question asked by Charudatta Ingale on Apr 6, 2016
Latest reply on Apr 11, 2016 by lama

Hi, I am using MC9S12ZVL family controller and CW IDE, facing problem with bit field operations. When I do some anding operation on particular bit it’s changing others bit value too.

 

Bit field structure:-

typedef struct _c_test_bit

{

  uint16_t test_bit_1 : 1;

  uint16_t test_bit_2 : 1;

  uint16_t test_bit_3 : 1;

  uint16_t test_bit_4 : 1; 

  uint16_t test_bit_5 : 1;

  uint16_t test_bit_6 : 1;

  uint16_t test_bit_7 : 1;

  uint16_t test_bit_8 : 1; 

  uint16_t test_bit_9 : 1;

  uint16_t test_bit_10 : 1;

  uint16_t test_bit_11 : 1;

  uint16_t test_bit_12 : 1; 

  uint16_t test_bit_13 : 1;

  uint16_t test_bit_14 : 1;

  uint16_t test_bit_15 : 1;

  uint16_t test_bit_16 : 1; 

  uint16_t test_bit_17 : 1;

  uint16_t test_bit_18 : 1;

  uint16_t unused0 : 6;

  uint16_t unused1 : 8;

  uint16_t unused2 : 8;

  uint16_t unused3 : 8;

  uint16_t unused4 : 8;

  uint16_t unused5 : 8;

} _c_test_bit;

 

Declaration:-

typedef union _c_test_bufTag

{

  uint8_t _c[8];

  _c_test_bit test_var;

} _c_test_buf;

 

_c_test_buf test_ver_1;

 

Anding operation:-

 

test_ver_1.test_var.test_bit_16 = ((uint8_t) (((uint8_t) (a)) & 0x01));  /* Note:- a can be 0 or 1 based on set or clear operation */

 

This operation is causing to change other bitfields values.

 

Below compiler options are used:-

CFLAGS += -nostdinc

CFLAGS += -nosyspath

CFLAGS += -w illpragmas

CFLAGS += -w possible

CFLAGS += -w extended

CFLAGS += -w extracomma

CFLAGS += -w emptydecl

CFLAGS += -w structclass

CFLAGS += -w notinlined

CFLAGS += -model small

CFLAGS += -bfield_lsbit_first

CFLAGS += -bfield_reduce_type

CFLAGS += -opt level=0

CFLAGS += -opt space

CFLAGS += -requireprotos

CFLAGS += -Cpp_Exceptions off

CFLAGS += -char unsigned

CFLAGS += -msgstyle parseable

CFLAGS += -sym full

 

Thanks and Regards,

Charudatta

Outcomes