AVR Libc Home Page | AVR Libc Development Pages | |||
Main Page | FAQ | Library Reference | Additional Documentation | Example Projects |
#include <util/crc16.h>
This header file provides a optimized inline functions for calculating cyclic redundancy checks (CRC) using common polynomials.
A typical application would look like:
// Dallas iButton test vector. uint8_t serno[] = { 0x02, 0x1c, 0xb8, 0x01, 0, 0, 0, 0xa2 }; int checkcrc(void) { uint8_t crc = 0, i; for (i = 0; i < sizeof serno / sizeof serno[0]; i++) crc = _crc_ibutton_update(crc, serno[i]); return crc; // must be 0 }
Functions | |
static __inline__ uint16_t | _crc16_update (uint16_t __crc, uint8_t __data) |
static __inline__ uint16_t | _crc_xmodem_update (uint16_t __crc, uint8_t __data) |
static __inline__ uint16_t | _crc_ccitt_update (uint16_t __crc, uint8_t __data) |
static __inline__ uint8_t | _crc_ibutton_update (uint8_t __crc, uint8_t __data) |
|
Optimized CRC-16 calculation.
Polynomial: x^16 + x^15 + x^2 + 1 (0xa001) This CRC is normally used in disk-drive controllers. The following is the equivalent functionality written in C.
|
|
Optimized CRC-CCITT calculation.
Polynomial: x^16 + x^12 + x^5 + 1 (0x8408) This is the CRC used by PPP and IrDA. See RFC1171 (PPP protocol) and IrDA IrLAP 1.1
|
|
Optimized Dallas (now Maxim) iButton 8-bit CRC calculation.
Polynomial: x^8 + x^5 + x^4 + 1 (0x8C) See http://www.maxim-ic.com/appnotes.cfm/appnote_number/27 The following is the equivalent functionality written in C.
uint8_t _crc_ibutton_update(uint8_t crc, uint8_t data) { uint8_t i; crc = crc ^ data; for (i = 0; i < 8; i++) { if (crc & 0x01) crc = (crc >> 1) ^ 0x8C; else crc >>= 1; } return crc; } |
|
Optimized CRC-XMODEM calculation.
Polynomial: x^16 + x^12 + x^5 + 1 (0x1021) This is the CRC used by the Xmodem-CRC protocol. The following is the equivalent functionality written in C.
|