AVR-LibC
2.2.0
Standard C library for AVR-GCC
|
AVR-LibC Documentation |
AVR-LibC Development Pages |
||||
Main Page |
User Manual |
Library Reference |
FAQ |
Example Projects |
File List |
Functions | |
static uint16_t | _crc16_update (uint16_t __crc, uint8_t __data) |
static uint16_t | _crc_xmodem_update (uint16_t __crc, uint8_t __data) |
static uint16_t | _crc_ccitt_update (uint16_t __crc, uint8_t __data) |
static uint8_t | _crc_ibutton_update (uint8_t __crc, uint8_t __data) |
static uint8_t | _crc8_ccitt_update (uint8_t __crc, uint8_t __data) |
This header file provides a optimized inline functions for calculating cyclic redundancy checks (CRC) using common polynomials.
See the Dallas Semiconductor app note 27 for 8051 assembler example and general CRC optimization suggestions. The table on the last page of the app note is the key to understanding these implementations.
Jack Crenshaw's "Implementing CRCs" article in the January 1992 isue of Embedded Systems Programming. This may be difficult to find, but it explains CRC's in very clear and concise terms. Well worth the effort to obtain a copy.
A typical application would look like:
Optimized CRC-16 calculation.
Polynomial: x16 + x15 + x2 + 1 (0xa001)
Initial value: 0xffff
This CRC is normally used in disk-drive controllers.
The following is the equivalent functionality written in C.
Optimized CRC-8-CCITT calculation.
Polynomial: x8 + x2 + x + 1 (0xE0)
For use with simple CRC-8
Initial value: 0x0
For use with CRC-8-ROHC
Initial value: 0xff
Reference: http://tools.ietf.org/html/rfc3095#section-5.9.1
For use with CRC-8-ATM/ITU
Initial value: 0xff
Final XOR value: 0x55
Reference: http://www.itu.int/rec/T-REC-I.432.1-199902-I/en
The C equivalent has been originally written by Dave Hylands. Assembly code is based on _crc_ibutton_update optimization.
The following is the equivalent functionality written in C.
Optimized CRC-CCITT calculation.
Polynomial: x16 + x12 + x5 + 1 (0x8408)
Initial value: 0xffff
This is the CRC used by PPP and IrDA.
See RFC1171 (PPP protocol) and IrDA IrLAP 1.1
The following is the equivalent functionality written in C.
Optimized Dallas (now Maxim) iButton 8-bit CRC calculation.
Polynomial: x8 + x5 + x4 + 1 (0x8C)
Initial value: 0x0
See http://www.maxim-ic.com/appnotes.cfm/appnote_number/27
The following is the equivalent functionality written in C.
Optimized CRC-XMODEM calculation.
Polynomial: x16 + x12 + x5 + 1 (0x1021)
Initial value: 0x0
This is the CRC used by the Xmodem-CRC protocol.
The following is the equivalent functionality written in C.