1 ------------------------------------------------------------------------------- 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2013-05-01 5 -- Last update: 2017-02-23 6 ------------------------------------------------------------------------------- 8 -- VHDL source file for CRC32 calculation to replace macro of Virtex5 in Virtex6 and Spartan6. 9 -- assuming clock positive edge, reset positive edge, LSB first, data width is 32, 10 -- polynomial CRC32 IEEE802.3 type X32+X26+X23+x22+x16+X12+X11+X10+X8+X7+X5+X4+X2+X1+1 11 -- with CRCRESETial value of 0xffffffff 12 -- similar equation can be derived from 13 -- http://www.xilinx.com/support/documentation/application_notes/xapp209.pdf 14 -- and related app notes 15 -- http://www.xilinx.com/support/documentation/application_notes/xapp562.pdf 16 ------------------------------------------------------------------------------- 17 -- This file is part of 'SLAC Firmware Standard Library'. 18 -- It is subject to the license terms in the LICENSE.txt file found in the 19 -- top-level directory of this distribution and at: 20 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. 21 -- No part of 'SLAC Firmware Standard Library', including this file, 22 -- may be copied, modified, propagated, or distributed except according to 23 -- the terms contained in the LICENSE.txt file. 24 ------------------------------------------------------------------------------- 27 use ieee.std_logic_1164.
all;
28 use ieee.std_logic_arith.
all;
29 use ieee.std_logic_unsigned.
all;
32 --! @ingroup base_general 37 CRCOUT : out (31 downto 0);
-- CRC output 40 CRCDATAVALID : in ;
-- indicate that new data arrived and CRC can be computed 41 CRCDATAWIDTH : in (2 downto 0);
-- indicate width in bytes minus 1, 0 - 1 byte, 1 - 2 bytes 42 CRCIN : in (31 downto 0);
-- input data for CRC calculation 43 CRCRESET : in );
-- to set CRC logic to value in crc_cNIT 49 signal data : (31 downto 0);
50 signal crc : (31 downto 0);
51 signal CRCDATAVALID_d : ;
52 signal CRCDATAWIDTH_d : (2 downto 0);
53 constant Polyval : (31 downto 0) := X"04C11DB7";
54 type fb_array is array (32 downto 0) of (31 downto 0);
55 signal MSBVect, TempXOR : fb_array;
57 -- Register delay for simulation 58 constant tpd : := 0.
5 ns;
61 TempXOR(0) <= crc xor data;
63 MS0 : for i in 0 to 31 generate 64 MS1 : for j in 0 to 31 generate 65 MSBVect(i)(j) <= TempXOR(i)(31);
69 MS2 : for i in 0 to 31 generate 70 TempXOR(i+1) <= ((TempXOR(i)(30 downto 0) & '0') xor (Polyval and MSBVect(i)));
76 for i in 24 to 31 loop 77 data(31 - (i - 24)) <= (CRCIN(i));
80 for i in 16 to 23 loop 81 data(23 - (i - 16)) <= (CRCIN(i));
86 data(15 - (i - 8)) <= (CRCIN(i));
91 data(7 - (i)) <= (CRCIN(i));
96 data(23 downto 0) <= (others => '0');
98 data(15 downto 0) <= (others => '0');
100 data(7 downto 0) <= (others => '0');
109 if rising_edge(CRCCLK) then 112 elsif (CRCDATAVALID_d = '1') and (CRCCLKEN = '1') then 113 if (CRCDATAWIDTH_d = "000") then 115 elsif (CRCDATAWIDTH_d = "001") then 117 elsif (CRCDATAWIDTH_d = "010") then 119 elsif (CRCDATAWIDTH_d = "011") then 126 -- Trasposing CRC bytes 127 CRCOUT <= not(crc(24) & crc(25) & crc(26) & crc(27) & crc(28) & crc(29) & crc(30) & crc(31) 128 & crc(16) & crc(17) & crc(18) & crc(19) & crc(20) & crc(21) & crc(22) & crc(23) 129 & crc(8) & crc(9) & crc(10) & crc(11) & crc(12) & crc(13) & crc(14) & crc(15) 130 & crc(0) & crc(1) & crc(2) & crc(3) & crc(4) & crc(5) & crc(6) & crc(7));
out CRCOUTstd_logic_vector( 31 downto 0)
in CRCINstd_logic_vector( 31 downto 0)
in CRCCLKENstd_logic := '1'
CRC_INITbit_vector := x"FFFFFFFF"
in CRCDATAWIDTHstd_logic_vector( 2 downto 0)