3.3 Adding Bit-Field Definitions
Accessing specific bits within the register is often useful; bit-field definitions provide this flexibility. Bit fields are defined within a C/C++ structure by providing a list of bit-field names, each followed by colon and the number of bits the field occupies.
Bit fields are a convenient way to express many difficult operations in C or C++. Bit fields do, however, suffer from a lack of portability between hardware platforms. On the C28x devices, the following rules apply to bit fields:
- Bit field members are stored from right to left in memory. That is, the least significant bit, or bit zero, of the register corresponds to the first bit field.
- 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.
The SCICCR and SCICTL1 registers in Figure 1 and Figure 2 translate into the C/C++ bit-field definitions in Example 8. Reserved locations within the register are held with bit fields that are not used except as place holders, i.e., rsvd, rsvd1, rsvd2, et cetera. As with other structures, each member is accessed using the dot operator in C or C++.
Figure 1. SCI SCICCR Register
STOPBITS |
EVEN/ODD PARITY |
PRIORITY ENABLE |
LOOPBACK ENA |
ADDR/IDLE Mode |
SCICHAR |
R-0 |
R/W-0 |
R/W-0 |
R-0 |
R/W-0 |
R/W-0 |
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset |
Figure 2. SCI SCICTL1 Register
Reserved |
RXERRINTENA |
SWRESET |
Reserved |
TXWAKE |
SLEEP |
TXENA |
RXENA |
R-0 |
R/W-0 |
R/W-0 |
R-0 |
R/W-0 |
R/W-0 |
R/W-0 |
R/W-0 |
LEGEND: R/W = Read/Write; R = Read only; -n = value after reset |