2.2 CRC Computation

The algorithm used to compute the two different CRC’s are described below.

The CRC is either set to 0 or a CRC “seed”. This is explained below.
  1. Find the "logical exclusive or" (XOR) between the LSB of the CRC and the LSB of the data.
  2. If this value is 0. Right shift CRC.
  3. If the value was 1:
    1. Find the new CRC value by taking the "logical exclusive or" (XOR) of the CRC and the CRC polynomial.
    2. Right shift CRC.
    3. Set the MSB of the CRC to 1.
  4. Right-shift the data.
  5. Repeat the complete sequence eight times.

This algorithm can be used to compute both CRC8 and CRC16. The only difference is the width of the CRC shift register (eight bits for CRC8, 16 bits for CRC16) and the value of the polynomial. This number will simulate the connection of the XOR gates in hardware. The value of the polynomial is 18h for CRC8 and 4002h for CRC16.

The algorithms are implemented to find the CRC value of one byte at a time, but a CRC “seed” can be passed as an argument to the CRC routines. In this way, the result of one CRC operation can be passed to the next one along with the next byte, in effect computing the CRC of an arbitrary number of bytes.

CRC checking of 64-bit identifiers is implemented in OWI_CheckRomCRC. It simply computes the CRC8 value of the first 56 bits and compares it to the last eight bits of the identifier.