Recommended Programming Style

The use of a union of a member that can hold the whole register (the “Word” member above) and a struct that can access the bits of the register (the “Bits” member above) is a good idea.

What is recommended is to read the whole memory mapped register (using the “Word” union member) into a local instance of the union, do the bit-manipulation on the local, and then write the result as a whole word into the memory mapped register. So the C code would look something like:

#define word int



union SCICR_union{

  word Word;

  struct {

    word SBK  :1;

    word RWU  :1;

    word RE   :1;

    word TE   :1;

    word REIE :1;

    word RFIE :1;

    word TIIE :1;

    word TEIE :1;

    word PT   :1;

    word PE   :1;

    word POL  :1;

    word WAKE :1;

    word M    :1;

    word RSRC :1;

    word SWAI :1;

    word LOOP :1;

  } Bits;

} SCICR;





/* Code: */



 union SCICR_union localSCICR;

 localSCICR.Word = SCICR.Word;



/*  generated codes

P:00000083:F07C022C    move.w      X:#SCICR,A

P:00000085:907F        move.w      A1, X: (SP-1)

*/

 

 localSCICR.Bits.TE = 1;



/*  generated codes

P:00000086:8AB4FFFF    adda        #-1,SP,R0

P:00000088:F0E00000    move.b      X:(R0),A

P:0000008A:83500008    bfset       #8,A1

P:0000008C:9800        move.b      A1,X: (R0)

*/

 

 localSCICR.Bits.PE = 1;



/*  generated codes

P:0000008D:F0E00001    move.b      X: (R0+1),A

P:0000008F:83500002    bfset       #2,A1

P:00000091:9804        move.b      A1,x: (R0+1)

*/



 SCICR.Word = localSCICR.Word;



*/ generated codes

P:00000092:B67F022C    move.w      X:(SP-1),X:#SCICR

*/