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 an 1-to-8-byte input CRC32 calculation. 9 -- The polynomial is fixed to 0x04C11DB7, the "standard CRC32 polynomial." 10 -- The initialization value is configurable, but defaults to 0xFFFFFFFF. 12 -- This implementation is direct, so no bytes need to be appended to the data. 14 -- Bytes are reversed on input before being used for the CRC calculation, 15 -- and the CRC register is reversed on output just before a final XOR with 18 -- This version utilizes parallel CRC calculations, and as a result generally 19 -- should meet much tighter timing constraints and run at higher frequencies. 20 -- (relative to Crc32.vhd and CRC32Rtl.vhd). 22 -- With a data input size of 4 bytes, this module is compatible with the 23 -- previous CRC32Rtl.vhdl module in the StdLib. 24 ------------------------------------------------------------------------------- 25 -- This file is part of 'SLAC Firmware Standard Library'. 26 -- It is subject to the license terms in the LICENSE.txt file found in the 27 -- top-level directory of this distribution and at: 28 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. 29 -- No part of 'SLAC Firmware Standard Library', including this file, 30 -- may be copied, modified, propagated, or distributed except according to 31 -- the terms contained in the LICENSE.txt file. 32 ------------------------------------------------------------------------------- 35 use ieee.std_logic_1164.
all;
36 use ieee.std_logic_arith.
all;
37 use ieee.std_logic_unsigned.
all;
42 --! @ingroup base_general 52 crcDataValid : in sl;
-- indicate that new data arrived and CRC can be computed 53 crcDataWidth : in slv(2 downto 0);
-- indicate width in bytes minus 1, 0 - 1 byte, 1 - 2 bytes ... , 7 - 8 bytes 55 crcReset : in sl -- initializes CRC logic to CRC_INIT_G 61 type RegType is record 62 crc : slv(31 downto 0);
65 byteWidth : slv(2 downto 0);
68 constant REG_INIT_C : RegType := ( 70 data => (others => '0'), 72 byteWidth => (others => '0') 75 signal r : RegType := REG_INIT_C;
84 variable prevCrc : slv(31 downto 0);
91 -- Transpose the input data 95 v.data((byte+1)*8-1-b) := crcIn(byte*8+b);
98 v.data((byte+1)*8-1 downto byte*8) := (others => '0');
108 -- Calculate CRC in parallel - implementation used depends on the 109 -- byte width in use. 110 if (r.valid = '1') then 142 when others => v.crc := (others => '0');
150 -- Transpose each byte in the data out and invert 151 -- This inversion is equivalent to an XOR of the CRC register with xFFFFFFFF 152 for byte in 0 to 3 loop 154 crcOut(byte*8+b) <= not(r.crc((byte+1)*8-1-b));
162 if (rising_edge(crcClk)) then 163 r <= rin after TPD_G;
out crcOutslv( 31 downto 0)
in crcDataWidthslv( 2 downto 0)
CRC_INIT_Gslv( 31 downto 0) := x"FFFFFFFF"
in crcInslv(( BYTE_WIDTH_G* 8- 1) downto 0)