前人遗留的项目中一个uart的帧协议上用到的,没有用循环计算和查表,看不懂这一坨位运算
。
https://avrdudes.github.io/avr-l ... oup__util__crc.html
Optimized CRC-CCITT calculation. Polynomial: x16 + x12 + x5 + 1 (0x8408, big-endian)
Initial value: 0xffff This is the CRC used by PPP and IrDA. See RFC1171 (PPP protocol) and IrDA IrLAP 1.1 NoteAlthough 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 algorithm. Xmodem shifts the MSB of the CRC and the input first, while CCITT shifts the LSB of the CRC and the input first.static inline 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));
}
|