网站上生成的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;
没人见过这个吗?不知道这个功能啊,可也用来计算crc吗
这就是用来并行计算crc的,d是输入的数据,c是前面一拍的crc计算结果,如果是第一拍,c就是crc初值
如果这样就可以理解了,只是我不会用,如果我生成的代码是crc32,8位数据输入,那么我想算0x5c的crc时我的crc初始值是多少,我的数据输入应该是一直是0x5c,我要经过多少次计算,什么时候输出的crc的值是我0x5c的正确的crc,我需要怎么处理这个crc函数,谢谢指导
kankankan
Use a standard vector testing
如果只算一个字节,直接把d[7:0]=0x5c,c[31:0]=初值 代入到公式计算得到的new_crc[31:0]就是结果,如果计算多个字节,d就依次输入各字节,c用上个字节算出的new_crc,最后迭代计算出的new_crc就是最终结果。初值一般是全0,也有全f的,一般是应用的协议在规定生成多项式的时候规定的。
我现在知道了,计算一个值的crc需要值的输入和crc的输入,通常这个crc的输入是上一个值的crc输出,如果是第一个数时,是初始化的全1,只是我输入第一个数5c,通过初始化crc是全1,然后得到的crc的值是0x03938fd7,但是通过网上下载的crc计算器,得到的5c的crc值是0xb0dff252,我不知道为什么会不一样,因为都是第一个数,crc的初始化值都是全1,应该一样的,除非算法有点不同的。或者crc代码生成的crc还需要处理。谢谢
我现在知道了,计算一个值的crc需要值的输入和crc的输入,通常这个crc的输入是上一个值的crc输出,如果是第一个数时,是初始化的全1,只是我输入第一个数5c,通过初始化crc是全1,然后得到的crc的值是0x03938fd7,但是通过网上下载的crc计算器,得到的5c的crc值是0xb0dff252,我不知道为什么会不一样,因为都是第一个数,crc的初始化值都是全1,应该一样的,除非算法有点不同的。或者crc代码生成的crc还需要处理。
检查你的生成多项式是否一样,即便是同一个位宽的crc算法,比如crc32,也可能有个不同的生成多项式,比如你的这个生成多项式是 polynomial: (0 1 2 4 5 7 8 10 11 12 16 22 23 26 32);
另外初值不一样算出来的crc也可能不一样。
