-2

I'm looking for some advice on writing a C function to calculate a 16 bit CRC for an LTO RFID chip.

The spec says:

For commands and data that are protected by the 16-bit CRC, the generator polynomial shall be G(x) = x16 + x12 + x5 + 1 The CRC bytes shall be generated by processing all bytes through a generator circuit. See figure F.11. Registers R0 to R15 shall be 1 bit wide where R0 shall be the least significant bit and R15 the most significant bit. These registers shall be set to (6363) prior to the beginning of processing. The bytes shall be fed sequentially into the encoder, least significant bit first. After the bytes have been processed, the content of R0 is CRC0 and shall be the least significant bit. The content of R15 is CRC15 and shall be the most significant bit.

But I've just a humble self taught C programmer and that means nothing to me.

Can anybody help me with some code, or an explanation of the formula?

  • Sorry, but the request is off-topic. However, read about CRC, possibly start on Wikipedia, but also google. There are quite some resources to be found, an older, yet good one is "A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS" (uppercase is from title, not yelling). – too honest for this site Feb 18 '16 at 00:37

1 Answers1

0

The diagram in the ECMA 319 Standard shows what to do:

shift register

though it contains an error. The exclusive-or between R11 and R10 should have another input tapped off the wire going to R15.

The bits from the input come in the wire at the top, starting with the least significant bit from the first input byte. At each clock, each register is set to its input. The plus signs in circles are exclusive-or gates.

You can implement this in C with the bit-wise operations ^, &, and >>. Enjoy!

Mark Adler
  • 101,978
  • 13
  • 118
  • 158