Lichen Wang wrote:
I am not very good at mathematics, but I think IAR is using the "wrong" algorithm to generate CRC16 and CRC32. I think IrDA is using the "correct" algorithm. Any one care to discuss about this? I do not care who did it is this way and who did it that way. I like to know what is the "correct" way mathematically.

*/David Peters <[email protected]>/* wrote:

    Is it possible for the GCC tools to generate a
    checksum from the generated code and embed it into the
    hex file at a specific address? I've done this in the
    past using the IAR compiler and need it for the
    bootloader to check the new code being loaded into
    flash.
    Thank you!


Just to stir the pot a bit... CRCs were originally done in hardware on a serial bit stream. Well maybe not originally, but a long time ago. As such, they operated on data as it appeared bit-by-bit. If the data was being transmitted via a UART it appeared LSbit first. If it was some form of synchronous serial data stream, it might appear MSbit first. Because of that history, table driven CRCs many times have two tables which operate on bytes. One assumes the data arrives LSbit first while the other table assumes the data arrives MSbit first. Both are correct.

Regards
-Bill Knight
R O SoftWare

PS - If the CRC of a data stream is appended to the data stream, when the receiving end computes the CRC of the data stream and the additional CRC byte(s), the result will be ZERO. However, if the bit-wise inversion of the CRC is appended to the data stream, when the receiving end does the calculation, the result will be a constant. The value of the constant is dependent upon both the polynomial and the seed (initial preload of the CRC). The constant value is know as the residue. That can be helpful in the receiving end does not need to extract the transmitted CRC from the data stream in order to do a comparison. It need only compare the calculated value against either ZERO or a constant. Be a bit cautious however in using a ZERO seed and the non-inverted CRC. A failed data stream could deliver all zeros as the data stream and it will pass the CRC test (for ZERO).

PPS - This info is as I know it and is subject to clarification and correction. If anyone wants to argue the semantics or pick the details, then never-mind.

Reply via email to