TLE5012B
Interfaces
User’s Manual 40 Rev. 1.2, 2018-02
//In case the crc MSB is 0.
else
//“crc” advances one position (this step is to ensure that the XOR operation is only
//done when the generator polynomial is aligned with a MSB of the message that is “1”.
crc <<= 1;
}
}
//Return the inverted “crc” remainder(“~” is the invertion operator). An alternative
//to the “~” operator would be a XOR operation between “crc” and a 0xFF polynomial.
return(~crc);
}
Example 2:
The function that generates the CRC:
//“message” is the data transfer for which a CRC has to be calculated.
//A typical “message” consists of 2 bytes for the command word plus 2 bytes for the
//data word plus 2 bytes for the safety word.
//“Bytelength” is the number of bytes in the “message”. A typical “message” has 6
//bytes.
//*Table CRC is the pointer to the look-up table (LUT)
unsigned char CRC8(unsigned char *message, unsigned char Bytelength, unsigned char
* TableCRC)
{
//“crc” defined as the 8-bits that will be generated through the message till the
//final crc is generated. In the example above this are the blue lines out of the
//XOR operation.
unsigned char crc;
//“Byteidx” is a counter to compare the bytes used for the CRC calculation and
//“Bytelength”.
unsigned char Byteid;
//Initially the CRC remainder has to be set with the original seed (0xFF for the
//TLE5012B).
crc = 0xFF;
//For all the bytes of the message.
for(Byteidx=0; Byteidx<Bytelength; Byteidx++)
{
//“crc” is the value in the look-up table TableCRC[x] at the position “x”.
//The position “x” is determined as the XOR operation between the previous “crc” and
//the next byte of the “message”.
//“^” is the XOR operator.
crc = TableCRC[crc ^ *(message+Byteidx)];
}
//Return the inverted “crc” remainder(“~” is the invertion operator). An alternative
//to the “~” operator would be a XOR operation between “crc” and a 0xFF polynomial.