在线时间0 小时
UID141376
注册时间2008-3-21
NXP金币0
该用户从未签到
新手上路

- 积分
- 37
- 最后登录
- 1970-1-1
|
采用Kinetis硬件计算crc,如果是使用大端计算都可得到正确结果。但是使用小端时,计算结果都是错误的。
以下u32 crc32_le(u32 crc, unsigned char const *p, size_t len)从linux内核移植。
/*
* There are multiple 16-bit CRC polynomials in common use, but this is
* *the* standard CRC-32 polynomial, first popularized by Ethernet.
* x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0
*/
#define CRCPOLY_LE 0xedb88320
#define CRCPOLY_BE 0x04c11db7
/**
* crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
* @crc: seed value for computation. ~0 for Ethernet, sometimes 0 for
* other uses, or the previous crc32 value if computing incrementally.
* @p: pointer to buffer over which CRC is run
* @len: length of buffer @p
* In fact, the table-based code will work in this case, but it can be
* simplified by inlining the table in ?: form.
*/
u32 crc32_le(u32 crc, unsigned char const *p, size_t len)
{
int i;
while (len--) {
crc ^= *p++;
for (i = 0; i < 8; i++)
crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
}
return crc;
}
/**
* crc32_be() - Calculate bitwise big-endian Ethernet AUTODIN II CRC32
* @crc: seed value for computation. ~0 for Ethernet, sometimes 0 for
* other uses, or the previous crc32 value if computing incrementally.
* @p: pointer to buffer over which CRC is run
* @len: length of buffer @p
* In fact, the table-based code will work in this case, but it can be
* simplified by inlining the table in ?: form.
*/
u32 crc32_be(u32 crc, unsigned char const *p, size_t len)
{
int i;
while (len--) {
<span style="color: rgb(34, 34, 34); font-family: sans-serif; font-size: 14px; line-height: 21px; background-color: rgb(238, 238, 238);"> crc ^= *p++
|
|