查看: 2729|回复: 2

[求助] Kinetis硬件计算crc,小端所有模式都对不上结果

[复制链接]

该用户从未签到

3

主题

14

帖子

0

新手上路

Rank: 1

积分
37
最后登录
1970-1-1
发表于 2014-2-28 14:34:32 | 显示全部楼层 |阅读模式
 采用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++
我知道答案 目前已有1人回答
回复

使用道具 举报

该用户从未签到

145

主题

4926

帖子

0

金牌会员

Rank: 6Rank: 6

积分
9267
最后登录
1970-1-1
发表于 2014-3-24 17:32:51 | 显示全部楼层

RE:Kinetis硬件计算crc,小端所有模式都对不上结果

你这个问题已经创建了SR,而且我们的技术人员已经回了你。
回复 支持 反对

使用道具 举报

该用户从未签到

16

主题

705

帖子

0

金牌会员

Rank: 6Rank: 6

积分
1745
最后登录
1970-1-1
发表于 2014-3-24 17:35:33 | 显示全部楼层

RE:Kinetis硬件计算crc,小端所有模式都对不上结果

CRC官方有例程的,楼主你可以参考看看。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2025-7-19 04:52 , Processed in 0.217641 second(s), 23 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

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