SBAA106A June 2020 – August 2021 ADS112C04 , ADS112U04 , ADS114S06 , ADS114S08 , ADS122C04 , ADS122U04 , ADS1235 , ADS1235-Q1 , ADS124S06 , ADS124S08 , ADS1259 , ADS1259-Q1 , ADS125H01 , ADS125H02 , ADS1260 , ADS1260-Q1 , ADS1261 , ADS1262 , ADS1263 , ADS127L01 , ADS131A02 , ADS131A04 , ADS131M04 , ADS131M06 , ADS131M08
Instead of using multiple XOR operations, the byte value is retrieved from the CRC table previously initialized and stored in memory.
/**
* CRC computation based on a lookup table previously stored in memory.
*
* \details CRC value is computed by an XOR of table data stored from
* the bitwise XOR of the polynomial.
*
* \param uint8_t *data, pointer to data array.
* \param uint32_t length, of data array.
*
* \returns crc_t remainder, of CRC computation.
*/
crc_t tableCRCcalc(uint8_t *data, uint32_t length)
{
crc_t remainder = REMAINDER_INIT;
uint32_t byte, u32i;
for(u32i = 0; u32i < length; u32i++) // For each byte in the data packet
{
byte = data[u32i] ^ (remainder >> (WIDTH - 8));
remainder = crcTable[byte] ^ (remainder << 8); // Perform table lookup
// for the byte remainder
}
return remainder;
}