SWCU193A April 2023 – August 2024 CC2340R2 , CC2340R5 , CC2340R5-Q1
Many proprietary radio systems require a specific CRC or whitening algorithm. This is done through the static configuration which can be exported from SmartRF™ Studio. The registers and fields in the following description can only be manipulated with SmartRF Studio. However to be able to configure the relevant registers correctly a detailed explanation of the implementation is included here for reference. The CRC and whitening are done using the Packet Handling Accelerator (PHA). The PHA is implemented as linear-feedback shift registers (LFSRs) with programmable polynomials.
There are 2 LSFR cores, numbered 0 and 1. In the description below, the value k is used to identify the core. Each LSFR core consists of two 32-bit registers: One is the 32-bit polynomial POLYk[31:0], identified as p0–p31 in Figure 22-2; POLYk[n] corresponds to pn. The other is the 32-bit value register LFSRkVAL[31:0], identified as d0–d31 in Figure 22-2; LFSRkVAL[n] corresponds to dn.
The LFSR0 core can be in CRC mode or whitener mode. LFSR1 can only be in CRC mode. The mode of LFSR0 is selected through the PHACFG MODE0 bit.
An LFSR core is assumed to be operated in a bit-serial way. For each new bit, the shift register d0–d31 is clocked once as shown in the block diagram above. In CRC mode, the crc_input line corresponds to the bit that is entered, while output is ignored so that w_input is don’t-care. In whitener mode, w_input corresponds to the bit that is entered, while crc_input is always 0. The polynomial register p0–p31 defines where there are taps in the shift register. A C equivalent of the operation is given below:
int j, fb;
fb = crc_input ^ LFSRVAL[31]; /* feedback */
for (j = 31; j >= 1; j--)
{
LFSRVAL[j] = LFSRVAL[j-1] ^ (fb & POLY[j]); /* LFSRVAL[j-1] XOR (fb AND POLY[j]) */
}
LFSRVAL[0] = fb & POLY[0]; /* fb AND POLY[0] */
output = w_input ^ fb; /* w_input XOR fb */
Two LFSRs can be run in parallel or in a chain. This is configured through the bits PHACFG[0:1] MODE1 bit field. If MODE1[1:0] is 00, the operation of LFSR 0 and LFSR 1 shall be independent.
If MODE1[1:0] is 01, the output of LFSR0 shall be input to LFSR1 in addition to the output register, and LFSR1 shall be clocked whenever a bit is output from LFSR0. This mode is only allowed when LFSR0 is in whitener mode.
If MODE1[1:0] is 10, the input to LFSR0 shall also be input to LFSR1, and the both these LFSR cores shall be clocked whenever a bit is input to LFSR0. This mode is allowed regardless of the mode of LFSR0.
This section describes how the PHA can be configured to implement certain common CRC and whitening schemes.
The PHA can support any CRC up to 32 bits. A 32-bit CRC polynomial can be described by the polynomial x32 + a31x31 + … + a1x1 + 1, where all an are 0 or 1. To represent this, each POLYk[n] bit in the register POLYk are set to an, and POLYk [0] is set to 1. For a polynomial of order m, described by xm + am−1xm−1 + … + a1x1 + 1, POLYk[32−m+n] are set to an, for all n=1..m−1, POLYk[32−m] are set to 1, and POLYk[31−m:0] are set to all zeros.
Together with the polynomial the start state of the LFSR also needs to be defined. This is done through RCL, see SDK documentation for details. Bit ordering through the CRC calculation is also handled by the radio firmware, and is controlled through the RCL.
System | Bit ordering | CRC | POLYk[31:0] | Initialization of LFSRk[31:0] |
---|---|---|---|---|
msb first |
CRC-8-ATM x8 + x2 + x + 1 |
0x0700 0000 | 0xFF00 0000 | |
CC2500, CC2510 | msb first |
CRC-16 x16 + x15 + x2 + 1 |
0x8005 0000 | 0xFFFF 0000 |
IEEE 802.15.4, OQPSK 2.4GHz |
lsb first |
CRC-16-CCITT x16 + x12 + x5 + 1 |
0x1021 0000 | 0x0000 0000 |
BLE | lsb first |
CRC-24-BLE x24 + x10 + x9 + x6 + x4 + x3 + x + 1 |
0x0006 5B00 |
0x5555 5500 (on advertising channels) |
CRC-32-IEEE 802.3 x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 |
0x04C1 1DB7 |
0xFFFF FFFF (for example) |
Each LFSR can be used to generate pseudo-random bit sequences, LFSR0 which supports whitener mode can collect the output in a vector. The LFSR supports generator polynomials up to order 32. A 32-bit generator polynomial can be described by the equation x32 + a31x31 + … + a1x1 + 1, where all an are 0 or 1. To represent this, each POLYk[n] bit in the register POLYk is set to an, and POLYk[0] is be set to 1. For a polynomial of order m, described by xm + am−1xm−1 + … + a1x1 + 1, POLYk [32−m+n] are set to an, for all n=1..m−1, POLYk[32−m] are set to 1, and POLYk[32−m:0] are set to all zeros.
In whitener mode, the output of the shift register is XORed with the input bit sequence.
The LFSRs use a Galois structure. Many whitening specifications assume a Fibonacci structure. These are equivalent, but the initialization value for the shift registers must be different to get the same start point of the sequence. The whitener initialization state is handled by the radio firmware, see the SDK documentation for details.
In Bluetooth Low Energy, a whitener with polynomial x7 + x4 + 1 is specified. The whitener is specified with a Galois structure and with an initialization as follows:
Position 0 is set to one.
Positions 1 to 6 are set to the channel index of the channel used when transmitting or receiving, from the most significant bit in position 1 to the least significant bit in position 6.
This whitening scheme can be obtained by setting POLYk to 0x22000000 and initializing the register by writing the channel index OR’ed by 0x40 into LFSRkBR.
In TI’s 2.4 GHz products CC2500, CC2510, CC2511, the whitener has a polynomial of x9 + x4 + 1. The whitener is specified with a Fibonacci structure that is initialized with all ones. To obtain the legacy TI whitening, the PHAPOLYk register is set to 0x08800000. Initialization of the register is done by setting LFSRk to 0xF8000000, as this is equivalent to the all ones initialization with the structure used in CC25xx.