library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; library lpm; use lpm.lpm_components.all; -- polynomial: (0 2 15 16) 1-8005 -- data width: 16 -- K J Anderson Univ of Chicago -- based on http://www.easics.com example entity CRC16 is port( crc_clk : in std_logic; crc_step : in std_logic; crc_start : in std_logic; crc_data : in std_logic_vector(31 downto 0); crc_error : out std_logic_vector(31 downto 0) ); end CRC16; architecture CRC16 of CRC16 is signal C1 : std_logic_vector(15 downto 0); signal C2 : std_logic_vector(15 downto 0); signal b31 : std_logic; signal cclr : std_logic; signal creset : std_logic; signal D1 : std_logic_vector(15 downto 0); signal D2 : std_logic_vector(15 downto 0); signal NewCRC1 : std_logic_vector(15 downto 0); signal NewCRC2 : std_logic_vector(15 downto 0); signal count : std_logic_vector(3 downto 0); begin process(crc_step,crc_start,crc_clk,crc_data) begin b31 <= crc_data(31); D1(0) <= crc_data(30); D1(1) <= crc_data(28); D1(2) <= crc_data(26); D1(3) <= crc_data(24); D1(4) <= crc_data(22); D1(5) <= crc_data(20); D1(6) <= crc_data(18); D1(7) <= crc_data(16); D1(8) <= crc_data(14); D1(9) <= crc_data(12); D1(10) <= crc_data(10); D1(11) <= crc_data(8); D1(12) <= crc_data(6); D1(13) <= crc_data(4); D1(14) <= crc_data(2); D1(15) <= crc_data(0); D2(0) <= crc_data(31); D2(1) <= crc_data(29); D2(2) <= crc_data(27); D2(3) <= crc_data(25); D2(4) <= crc_data(23); D2(5) <= crc_data(21); D2(6) <= crc_data(19); D2(7) <= crc_data(17); D2(8) <= crc_data(15); D2(9) <= crc_data(13); D2(10) <= crc_data(11); D2(11) <= crc_data(9); D2(12) <= crc_data(7); D2(13) <= crc_data(5); D2(14) <= crc_data(3); D2(15) <= crc_data(1); if(crc_start = '1') then count <= (others => '1'); crc_error <= (others => '0'); c1 <= (others => '0'); c2 <= (others => '0'); end if; if(crc_clk'event and crc_clk = '0') then if(crc_step = '1') then if(b31 = '1') then count <= count + 1; c1 <= (others => '0'); c2 <= (others => '0'); else c1 <= NewCRC1; c2 <= NewCRC2; end if; end if; if(crc_step = '0') then NewCRC1(0) <= D1(15) xor D1(13) xor D1(12) xor D1(11) xor D1(10) xor D1(9) xor D1(8) xor D1(7) xor D1(6) xor D1(5) xor D1(4) xor D1(3) xor D1(2) xor D1(1) xor D1(0) xor C1(0) xor C1(1) xor C1(2) xor C1(3) xor C1(4) xor C1(5) xor C1(6) xor C1(7) xor C1(8) xor C1(9) xor C1(10) xor C1(11) xor C1(12) xor C1(13) xor C1(15); NewCRC1(1) <= D1(14) xor D1(13) xor D1(12) xor D1(11) xor D1(10) xor D1(9) xor D1(8) xor D1(7) xor D1(6) xor D1(5) xor D1(4) xor D1(3) xor D1(2) xor D1(1) xor C1(1) xor C1(2) xor C1(3) xor C1(4) xor C1(5) xor C1(6) xor C1(7) xor C1(8) xor C1(9) xor C1(10) xor C1(11) xor C1(12) xor C1(13) xor C1(14); NewCRC1(2) <= D1(14) xor D1(1) xor D1(0) xor C1(0) xor C1(1) xor C1(14); NewCRC1(3) <= D1(15) xor D1(2) xor D1(1) xor C1(1) xor C1(2) xor C1(15); NewCRC1(4) <= D1(3) xor D1(2) xor C1(2) xor C1(3); NewCRC1(5) <= D1(4) xor D1(3) xor C1(3) xor C1(4); NewCRC1(6) <= D1(5) xor D1(4) xor C1(4) xor C1(5); NewCRC1(7) <= D1(6) xor D1(5) xor C1(5) xor C1(6); NewCRC1(8) <= D1(7) xor D1(6) xor C1(6) xor C1(7); NewCRC1(9) <= D1(8) xor D1(7) xor C1(7) xor C1(8); NewCRC1(10) <= D1(9) xor D1(8) xor C1(8) xor C1(9); NewCRC1(11) <= D1(10) xor D1(9) xor C1(9) xor C1(10); NewCRC1(12) <= D1(11) xor D1(10) xor C1(10) xor C1(11); NewCRC1(13) <= D1(12) xor D1(11) xor C1(11) xor C1(12); NewCRC1(14) <= D1(13) xor D1(12) xor C1(12) xor C1(13); NewCRC1(15) <= D1(15) xor D1(14) xor D1(12) xor D1(11) xor D1(10) xor D1(9) xor D1(8) xor D1(7) xor D1(6) xor D1(5) xor D1(4) xor D1(3) xor D1(2) xor D1(1) xor D1(0) xor C1(0) xor C1(1) xor C1(2) xor C1(3) xor C1(4) xor C1(5) xor C1(6) xor C1(7) xor C1(8) xor C1(9) xor C1(10) xor C1(11) xor C1(12) xor C1(14) xor C1(15); NewCRC2(0) <= D2(15) xor D2(13) xor D2(12) xor D2(11) xor D2(10) xor D2(9) xor D2(8) xor D2(7) xor D2(6) xor D2(5) xor D2(4) xor D2(3) xor D2(2) xor D2(1) xor D2(0) xor C2(0) xor C2(1) xor C2(2) xor C2(3) xor C2(4) xor C2(5) xor C2(6) xor C2(7) xor C2(8) xor C2(9) xor C2(10) xor C2(11) xor C2(12) xor C2(13) xor C2(15); NewCRC2(1) <= D2(14) xor D2(13) xor D2(12) xor D2(11) xor D2(10) xor D2(9) xor D2(8) xor D2(7) xor D2(6) xor D2(5) xor D2(4) xor D2(3) xor D2(2) xor D2(1) xor C2(1) xor C2(2) xor C2(3) xor C2(4) xor C2(5) xor C2(6) xor C2(7) xor C2(8) xor C2(9) xor C2(10) xor C2(11) xor C2(12) xor C2(13) xor C2(14); NewCRC2(2) <= D2(14) xor D2(1) xor D2(0) xor C2(0) xor C2(1) xor C2(14); NewCRC2(3) <= D2(15) xor D2(2) xor D2(1) xor C2(1) xor C2(2) xor C2(15); NewCRC2(4) <= D2(3) xor D2(2) xor C2(2) xor C2(3); NewCRC2(5) <= D2(4) xor D2(3) xor C2(3) xor C2(4); NewCRC2(6) <= D2(5) xor D2(4) xor C2(4) xor C2(5); NewCRC2(7) <= D2(6) xor D2(5) xor C2(5) xor C2(6); NewCRC2(8) <= D2(7) xor D2(6) xor C2(6) xor C2(7); NewCRC2(9) <= D2(8) xor D2(7) xor C2(7) xor C2(8); NewCRC2(10) <= D2(9) xor D2(8) xor C2(8) xor C2(9); NewCRC2(11) <= D2(10) xor D2(9) xor C2(9) xor C2(10); NewCRC2(12) <= D2(11) xor D2(10) xor C2(10) xor C2(11); NewCRC2(13) <= D2(12) xor D2(11) xor C2(11) xor C2(12); NewCRC2(14) <= D2(13) xor D2(12) xor C2(12) xor C2(13); NewCRC2(15) <= D2(15) xor D2(14) xor D2(12) xor D2(11) xor D2(10) xor D2(9) xor D2(8) xor D2(7) xor D2(6) xor D2(5) xor D2(4) xor D2(3) xor D2(2) xor D2(1) xor D2(0) xor C2(0) xor C2(1) xor C2(2) xor C2(3) xor C2(4) xor C2(5) xor C2(6) xor C2(7) xor C2(8) xor C2(9) xor C2(10) xor C2(11) xor C2(12) xor C2(14) xor C2(15); if (crc_data(30 downto 16) = c1(14 downto 0)) then if(count = "0000") then crc_error(0) <= '1'; end if; if(count = "0001") then crc_error(1) <= '1'; end if; if(count = "0010") then crc_error(2) <= '1'; end if; if(count = "0011") then crc_error(3) <= '1'; end if; if(count = "0100") then crc_error(4) <= '1'; end if; if(count = "00101") then crc_error(5) <= '1'; end if; if(count = "0110") then crc_error(6) <= '1'; end if; if(count = "0111") then crc_error(7) <= '1'; end if; if(count = "1000") then crc_error(8) <= '1'; end if; if(count = "1001") then crc_error(9) <= '1'; end if; if(count = "1010") then crc_error(10) <= '1'; end if; if(count = "1011") then crc_error(11) <= '1'; end if; if(count = "1100") then crc_error(12) <= '1'; end if; if(count = "1101") then crc_error(13) <= '1'; end if; if(count = "1110") then crc_error(14) <= '1'; end if; if(count = "1111") then crc_error(15) <= '1'; end if; end if; if (crc_data(14 downto 0) = c2(14 downto 0)) then if(count = "0000") then crc_error(16) <= '1'; end if; if(count = "0001") then crc_error(17) <= '1'; end if; if(count = "0010") then crc_error(18) <= '1'; end if; if(count = "0011") then crc_error(19) <= '1'; end if; if(count = "0100") then crc_error(20) <= '1'; end if; if(count = "00101") then crc_error(21) <= '1'; end if; if(count = "0110") then crc_error(22) <= '1'; end if; if(count = "0111") then crc_error(23) <= '1'; end if; if(count = "1000") then crc_error(24) <= '1'; end if; if(count = "1001") then crc_error(25) <= '1'; end if; if(count = "1010") then crc_error(26) <= '1'; end if; if(count = "1011") then crc_error(27) <= '1'; end if; if(count = "1100") then crc_error(28) <= '1'; end if; if(count = "1101") then crc_error(29) <= '1'; end if; if(count = "1110") then crc_error(30) <= '1'; end if; if(count = "1111") then crc_error(31) <= '1'; end if; end if; end if; end if; end process; end CRC16;