2016年3月2日 星期三

TI CCStudio Bit-Field Definitions

Bit-Field Definitions
- Bit field members are stored from right to left in memory. (LSB 開始放置)

例如:
struct SCICCR_BITS {        // bit description
    Uint16 SCICHAR:3;       // 2:0 Character length control (LSB)
    Uint16 ADDRIDLE_MODE:1; // 3 ADDR/IDLE Mode control
    Uint16 LOOPBKENA:1;     // 4 Loop Back enable
    Uint16 PARITYENA:1;     // 5 Parity enable
    Uint16 PARITY:1;        // 6 Even or Odd Parity
    Uint16 STOPBITS:1;      // 7 Number of Stop Bits
    Uint16 rsvd1:8;         // 15:8 reserved
};


- The C28x compiler limits the maximum number of bits within a bit field to the size of an integer; no bit field can be greater than 16 bits in length.
 - If the total number of bits defined by bit fields within a structure grows above 16 bits, then the next bit field is stored consecutively in the next word of memory.

要注意的是, 例如寫入單一個成員變數, CPU 是執行 read-modify-write; 也就是說在有些 register 寫入 1 是清除的指令, 當成員變數在同一個 structure 中時, 寫入 A 成員, 可能會造成 B 成員也被清除. 這時候可能要用整個 structure 寫入的方式.
 以下的 register 在執行 read-modify-write 動作時, 要注意:
1) Registers with bits that hardware can change after the read, but before the write
2) Registers with write 1-to-clear bits
3) Registers that have bits that must be written with a value different from what the bits read back

ref: TI SPRAA85D, Programming TMS320x28xx and 28xxx Peripherals in C/C++ (Rev. D)
p.16

沒有留言:

張貼留言