硬汉嵌入式论坛

 找回密码
 立即注册
搜索
查看: 283|回复: 1
收起左侧

avr libc 的ccitt crc,原理是啥

[复制链接]

1

主题

1

回帖

4

积分

新手上路

积分
4
发表于 2026-8-25 13:04:12 | 显示全部楼层 |阅读模式
前人遗留的项目中一个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));
}


回复

使用道具 举报

1万

主题

7万

回帖

12万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
124153
QQ
发表于 2026-8-25 13:19:01 | 显示全部楼层
串口 XMODEM有用这个
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2026-9-22 18:41 , Processed in 0.434549 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表