staticuint16_t_crc16_update(uint16_t__crc,uint8_t__data)[inline],[static]
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.
uint16_t
crc16_update (uint16_t crc, uint8_t a)
{
crc ^= a;
for (int i = 0; i < 8; ++i)
{
if (crc & 1)
crc = (crc >> 1) ^ 0xA001;
else
crc = crc >> 1;
}
return crc;
}
staticuint8_t_crc8_ccitt_update(uint8_t__crc,uint8_t__data)[inline],[static]
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.
uint8_t
_crc8_ccitt_update (uint8_t inCrc, uint8_t inData)
{
uint8_t data = inCrc ^ inData;
for (int i = 0; i < 8; i++)
{
if ((data & 0x80) != 0)
{
data <<= 1;
data ^= 0x07;
}
else
{
data <<= 1;
}
}
return data;
}
staticuint16_t_crc_ccitt_update(uint16_t__crc,uint8_t__data)[inline],[static]
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
Note
Although the CCITT polynomial is the same as that used by the Xmodem protocol, they are quite
different. The difference is in how the bits are shifted through the alorgithm. Xmodem shifts the MSB
of the CRC and the input first, while CCITT shifts the LSB of the CRC and the input first.
The following is the equivalent functionality written in C.
uint16_t
crc_ccitt_update (uint16_t crc, uint8_t data)
{
data ^= lo8 (crc);
data ^= data << 4;
return ((((uint16_t)data << 8) | hi8 (crc)) ^ (uint8_t)(data >> 4)
^ ((uint16_t)data << 3));
}
staticuint8_t_crc_ibutton_update(uint8_t__crc,uint8_t__data)[inline],[static]
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.
uint8_t
_crc_ibutton_update (uint8_t crc, uint8_t data)
{
crc = crc ^ data;
for (uint8_t i = 0; i < 8; i++)
{
if (crc & 0x01)
crc = (crc >> 1) ^ 0x8C;
else
crc >>= 1;
}
return crc;
}
staticuint16_t_crc_xmodem_update(uint16_t__crc,uint8_t__data)[inline],[static]
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.
uint16_t
crc_xmodem_update (uint16_t crc, uint8_t data)
{
crc = crc ^ ((uint16_t)data << 8);
for (int i = 0; i < 8; i++)
{
if (crc & 0x8000)
crc = (crc << 1) ^ 0x1021;
else
crc <<= 1;
}
return crc;
}