1 ------------------------------------------------------------------------------- 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2013-05-01 5 -- Last update: 2017-02-23 6 ------------------------------------------------------------------------------- 8 -- This is an implementation of a generic N-byte input CRC32 calculation. 9 -- The polynomial and CRC register initialization are generic configurable, but 10 -- default to the commonly used 0x04C11DB7 and 0xFFFFFFFF, respectively. 11 -- This implementation is direct, so no bytes need to be appended to the data. 12 -- Bytes are reversed on input before being used for the CRC calculation, 13 -- and the CRC register is reversed on output just before a final XOR with 16 -- With a data input size of 4 bytes, this module is compatible with the 17 -- previous CRC32Rtl.vhdl module in the StdLib. 18 ------------------------------------------------------------------------------- 19 -- This file is part of 'SLAC Firmware Standard Library'. 20 -- It is subject to the license terms in the LICENSE.txt file found in the 21 -- top-level directory of this distribution and at: 22 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. 23 -- No part of 'SLAC Firmware Standard Library', including this file, 24 -- may be copied, modified, propagated, or distributed except according to 25 -- the terms contained in the LICENSE.txt file. 26 ------------------------------------------------------------------------------- 29 use ieee.std_logic_1164.
all;
30 use ieee.std_logic_arith.
all;
31 use ieee.std_logic_unsigned.
all;
36 --! @ingroup base_general 46 crcDataValid : in sl;
-- indicate that new data arrived and CRC can be computed 47 crcDataWidth : in slv(2 downto 0);
-- indicate width in bytes minus 1, 0 - 1 byte, 1 - 2 bytes ... , 7 - 8 bytes 49 crcReset : in sl);
-- initializes CRC logic to CRC_INIT_G 52 architecture rtl
of Crc32 is
54 type RegType is record 55 crc : slv(31 downto 0);
58 byteWidth : slv(2 downto 0);
61 constant REG_INIT_C : RegType := ( 63 data => (others => '0'), 65 byteWidth => (others => '0') 68 signal r : RegType := REG_INIT_C;
75 variable byteXor : slv(7 downto 0);
81 byteXor := (others => '0');
83 -- Transpose the input data 87 v.data((byte+1)*8-1-b) := crcIn(byte*8+b);
89 v.data((byte+1)*8-1-b) := '0';
101 -- Calculate CRC byte-by-byte 102 if (r.valid = '1') then 105 byteXor := v.crc(31 downto 24) xor r.data( (byte+1)*8-1 downto byte*8);
106 v.crc := (v.crc(23 downto 0) & x"00") xor crcByteLookup(byteXor,CRC_POLY_G);
113 -- Transpose each byte in the data out and invert 114 -- This inversion is equivalent to an XOR of the CRC register with xFFFFFFFF 115 for byte in 0 to 3 loop 117 crcOut(byte*8+b) <= not(r.crc((byte+1)*8-1-b));
125 if (rising_edge(crcClk)) then 126 r <= rin after TPD_G;
out crcOutslv( 31 downto 0)
CRC_POLY_Gslv( 31 downto 0) := x"04C11DB7"
in crcInslv(( BYTE_WIDTH_G* 8- 1) downto 0)
CRC_INIT_Gslv( 31 downto 0) := x"FFFFFFFF"
in crcDataWidthslv( 2 downto 0)