在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 3197|回复: 9

[求助] 网站上生成的crc

[复制链接]
发表于 2012-10-25 17:25:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
http://www.easics.com/webtools/crctool这个网站中计算crc是验证我设计模块计算的正不正确,还是提供crc校验的模块啊,我用网站生成的模块中的crc输入不知道是什么啊
library ieee;
use ieee.std_logic_1164.all;
package PCK_CRC32_D8 is
  -- polynomial: (0 1 2 4 5 7 8 10 11 12 16 22 23 26 32)
  -- data width: 8
  -- convention: the first serial bit is D[7]
  function nextCRC32_D8
    (Data: std_logic_vector(7 downto 0);
     crc:  std_logic_vector(31 downto 0))
    return std_logic_vector;
end PCK_CRC32_D8;

package body PCK_CRC32_D8 is
  -- polynomial: (0 1 2 4 5 7 8 10 11 12 16 22 23 26 32)
  -- data width: 8
  -- convention: the first serial bit is D[7]
  function nextCRC32_D8
    (Data: std_logic_vector(7 downto 0);
     crc:  std_logic_vector(31 downto 0))
    return std_logic_vector is
    variable d:      std_logic_vector(7 downto 0);
    variable c:      std_logic_vector(31 downto 0);
    variable newcrc: std_logic_vector(31 downto 0);
  begin
    d := Data;
    c := crc;
    newcrc(0) := d(6) xor d(0) xor c(24) xor c(30);
    newcrc(1) := d(7) xor d(6) xor d(1) xor d(0) xor c(24) xor c(25) xor c(30) xor c(31);
    newcrc(2) := d(7) xor d(6) xor d(2) xor d(1) xor d(0) xor c(24) xor c(25) xor c(26) xor c(30) xor c(31);
    newcrc(3) := d(7) xor d(3) xor d(2) xor d(1) xor c(25) xor c(26) xor c(27) xor c(31);
    newcrc(4) := d(6) xor d(4) xor d(3) xor d(2) xor d(0) xor c(24) xor c(26) xor c(27) xor c(28) xor c(30);
    newcrc(5) := d(7) xor d(6) xor d(5) xor d(4) xor d(3) xor d(1) xor d(0) xor c(24) xor c(25) xor c(27) xor c(28) xor c(29) xor c(30) xor c(31);
    newcrc(6) := d(7) xor d(6) xor d(5) xor d(4) xor d(2) xor d(1) xor c(25) xor c(26) xor c(28) xor c(29) xor c(30) xor c(31);
    newcrc(7) := d(7) xor d(5) xor d(3) xor d(2) xor d(0) xor c(24) xor c(26) xor c(27) xor c(29) xor c(31);
    newcrc(8) := d(4) xor d(3) xor d(1) xor d(0) xor c(0) xor c(24) xor c(25) xor c(27) xor c(28);
    newcrc(9) := d(5) xor d(4) xor d(2) xor d(1) xor c(1) xor c(25) xor c(26) xor c(28) xor c(29);
    newcrc(10) := d(5) xor d(3) xor d(2) xor d(0) xor c(2) xor c(24) xor c(26) xor c(27) xor c(29);
    newcrc(11) := d(4) xor d(3) xor d(1) xor d(0) xor c(3) xor c(24) xor c(25) xor c(27) xor c(28);
    newcrc(12) := d(6) xor d(5) xor d(4) xor d(2) xor d(1) xor d(0) xor c(4) xor c(24) xor c(25) xor c(26) xor c(28) xor c(29) xor c(30);
    newcrc(13) := d(7) xor d(6) xor d(5) xor d(3) xor d(2) xor d(1) xor c(5) xor c(25) xor c(26) xor c(27) xor c(29) xor c(30) xor c(31);
    newcrc(14) := d(7) xor d(6) xor d(4) xor d(3) xor d(2) xor c(6) xor c(26) xor c(27) xor c(28) xor c(30) xor c(31);
    newcrc(15) := d(7) xor d(5) xor d(4) xor d(3) xor c(7) xor c(27) xor c(28) xor c(29) xor c(31);
    newcrc(16) := d(5) xor d(4) xor d(0) xor c(8) xor c(24) xor c(28) xor c(29);
    newcrc(17) := d(6) xor d(5) xor d(1) xor c(9) xor c(25) xor c(29) xor c(30);
    newcrc(18) := d(7) xor d(6) xor d(2) xor c(10) xor c(26) xor c(30) xor c(31);
    newcrc(19) := d(7) xor d(3) xor c(11) xor c(27) xor c(31);
    newcrc(20) := d(4) xor c(12) xor c(28);
    newcrc(21) := d(5) xor c(13) xor c(29);
    newcrc(22) := d(0) xor c(14) xor c(24);
    newcrc(23) := d(6) xor d(1) xor d(0) xor c(15) xor c(24) xor c(25) xor c(30);
    newcrc(24) := d(7) xor d(2) xor d(1) xor c(16) xor c(25) xor c(26) xor c(31);
    newcrc(25) := d(3) xor d(2) xor c(17) xor c(26) xor c(27);
    newcrc(26) := d(6) xor d(4) xor d(3) xor d(0) xor c(18) xor c(24) xor c(27) xor c(28) xor c(30);
    newcrc(27) := d(7) xor d(5) xor d(4) xor d(1) xor c(19) xor c(25) xor c(28) xor c(29) xor c(31);
    newcrc(28) := d(6) xor d(5) xor d(2) xor c(20) xor c(26) xor c(29) xor c(30);
    newcrc(29) := d(7) xor d(6) xor d(3) xor c(21) xor c(27) xor c(30) xor c(31);
    newcrc(30) := d(7) xor d(4) xor c(22) xor c(28) xor c(31);
    newcrc(31) := d(5) xor c(23) xor c(29);
    return newcrc;
  end nextCRC32_D8;
end PCK_CRC32_D8;
 楼主| 发表于 2012-10-26 09:25:40 | 显示全部楼层
没人见过这个吗?不知道这个功能啊,可也用来计算crc吗
发表于 2012-10-26 14:00:07 | 显示全部楼层
这就是用来并行计算crc的,d是输入的数据,c是前面一拍的crc计算结果,如果是第一拍,c就是crc初值
 楼主| 发表于 2012-10-27 09:31:28 | 显示全部楼层
回复 3# kulalabala


    如果这样就可以理解了,只是我不会用,如果我生成的代码是crc32,8位数据输入,那么我想算0x5c的crc时我的crc初始值是多少,我的数据输入应该是一直是0x5c,我要经过多少次计算,什么时候输出的crc的值是我0x5c的正确的crc,我需要怎么处理这个crc函数,谢谢指导
发表于 2012-10-27 12:44:10 | 显示全部楼层
kankankan
发表于 2012-10-27 14:14:56 | 显示全部楼层
Use a standard vector testing
发表于 2012-10-29 20:43:36 | 显示全部楼层
回复 4# 574920045


    如果只算一个字节,直接把d[7:0]=0x5c,c[31:0]=初值 代入到公式计算得到的new_crc[31:0]就是结果,如果计算多个字节,d就依次输入各字节,c用上个字节算出的new_crc,最后迭代计算出的new_crc就是最终结果。初值一般是全0,也有全f的,一般是应用的协议在规定生成多项式的时候规定的。
 楼主| 发表于 2012-10-30 09:17:30 | 显示全部楼层
我现在知道了,计算一个值的crc需要值的输入和crc的输入,通常这个crc的输入是上一个值的crc输出,如果是第一个数时,是初始化的全1,只是我输入第一个数5c,通过初始化crc是全1,然后得到的crc的值是0x03938fd7,但是通过网上下载的crc计算器,得到的5c的crc值是0xb0dff252,我不知道为什么会不一样,因为都是第一个数,crc的初始化值都是全1,应该一样的,除非算法有点不同的。或者crc代码生成的crc还需要处理。谢谢
 楼主| 发表于 2012-10-30 09:18:23 | 显示全部楼层
回复 7# kulalabala


     我现在知道了,计算一个值的crc需要值的输入和crc的输入,通常这个crc的输入是上一个值的crc输出,如果是第一个数时,是初始化的全1,只是我输入第一个数5c,通过初始化crc是全1,然后得到的crc的值是0x03938fd7,但是通过网上下载的crc计算器,得到的5c的crc值是0xb0dff252,我不知道为什么会不一样,因为都是第一个数,crc的初始化值都是全1,应该一样的,除非算法有点不同的。或者crc代码生成的crc还需要处理。
发表于 2012-10-31 10:37:55 | 显示全部楼层
检查你的生成多项式是否一样,即便是同一个位宽的crc算法,比如crc32,也可能有个不同的生成多项式,比如你的这个生成多项式是 polynomial: (0 1 2 4 5 7 8 10 11 12 16 22 23 26 32);
另外初值不一样算出来的crc也可能不一样。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

X

小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-6-9 22:06 , Processed in 0.031614 second(s), 9 queries , Gzip On, MemCached On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表