1 |
3 |
DFC |
--
|
2 |
|
|
-- crc32_gen_tab.vhd: A 32-bit CRC (IEEE) table for processing generic number of bits in parallel
|
3 |
|
|
-- Copyright (C) 2011 CESNET
|
4 |
|
|
-- Author(s): Lukas Kekely <xkekel00@stud.fit.vutbr.cz>
|
5 |
|
|
--
|
6 |
|
|
-- Redistribution and use in source and binary forms, with or without
|
7 |
|
|
-- modification, are permitted provided that the following conditions
|
8 |
|
|
-- are met:
|
9 |
|
|
-- 1. Redistributions of source code must retain the above copyright
|
10 |
|
|
-- notice, this list of conditions and the following disclaimer.
|
11 |
|
|
-- 2. Redistributions in binary form must reproduce the above copyright
|
12 |
|
|
-- notice, this list of conditions and the following disclaimer in
|
13 |
|
|
-- the documentation and/or other materials provided with the
|
14 |
|
|
-- distribution.
|
15 |
|
|
-- 3. Neither the name of the Company nor the names of its contributors
|
16 |
|
|
-- may be used to endorse or promote products derived from this
|
17 |
|
|
-- software without specific prior written permission.
|
18 |
|
|
--
|
19 |
|
|
-- This software is provided ``as is'', and any express or implied
|
20 |
|
|
-- warranties, including, but not limited to, the implied warranties of
|
21 |
|
|
-- merchantability and fitness for a particular purpose are disclaimed.
|
22 |
|
|
-- In no event shall the company or contributors be liable for any
|
23 |
|
|
-- direct, indirect, incidental, special, exemplary, or consequential
|
24 |
|
|
-- damages (including, but not limited to, procurement of substitute
|
25 |
|
|
-- goods or services; loss of use, data, or profits; or business
|
26 |
|
|
-- interruption) however caused and on any theory of liability, whether
|
27 |
|
|
-- in contract, strict liability, or tort (including negligence or
|
28 |
|
|
-- otherwise) arising in any way out of the use of this software, even
|
29 |
|
|
-- if advised of the possibility of such damage.
|
30 |
|
|
--
|
31 |
|
|
-- $Id$
|
32 |
|
|
--
|
33 |
|
|
-- TODO:
|
34 |
|
|
--
|
35 |
|
|
--
|
36 |
|
|
|
37 |
|
|
library IEEE;
|
38 |
|
|
use IEEE.std_logic_1164.all;
|
39 |
|
|
use IEEE.std_logic_arith.all;
|
40 |
|
|
use IEEE.std_logic_unsigned.all;
|
41 |
|
|
use IEEE.numeric_std.all;
|
42 |
|
|
use WORK.math_pack.all;
|
43 |
|
|
-- ----------------------------------------------------------------------------
|
44 |
|
|
-- Entity declaration
|
45 |
|
|
-- ----------------------------------------------------------------------------
|
46 |
|
|
entity crc32_gen_tab_tree is
|
47 |
|
|
generic(
|
48 |
|
|
-- must be power of 2 and higher or equal to 32
|
49 |
|
|
DATA_WIDTH : integer := 64;
|
50 |
|
|
REG_BITMAP : integer := 0
|
51 |
|
|
);
|
52 |
|
|
port(
|
53 |
|
|
CLK : in std_logic;
|
54 |
|
|
DI : in std_logic_vector(DATA_WIDTH-1 downto 0);
|
55 |
|
|
DI_DV : in std_logic;
|
56 |
|
|
MASK : in std_logic_vector(log2(DATA_WIDTH/8)-1 downto 0);
|
57 |
|
|
DO : out std_logic_vector(31 downto 0);
|
58 |
|
|
DO_DV : out std_logic
|
59 |
|
|
);
|
60 |
|
|
end entity crc32_gen_tab_tree;
|
61 |
|
|
|
62 |
|
|
-- ----------------------------------------------------------------------------
|
63 |
|
|
-- Architecture declaration
|
64 |
|
|
-- ----------------------------------------------------------------------------
|
65 |
|
|
architecture crc32_gen_tab_arch of crc32_gen_tab_tree is
|
66 |
|
|
constant MW : integer := log2(DATA_WIDTH/8);
|
67 |
|
|
signal crc_fin : std_logic_vector(31 downto 0);
|
68 |
|
|
type pipe_t is array (0 to MW-2) of std_logic_vector(DATA_WIDTH-1 downto 0);
|
69 |
|
|
type pipe_mask_t is array (0 to MW-2) of std_logic_vector(MW-1 downto 0);
|
70 |
|
|
type pipe_crc_t is array (0 to MW-2) of std_logic_vector(31 downto 0);
|
71 |
|
|
signal indata_pipe : pipe_t;
|
72 |
|
|
signal indata_pipe_MW_2_d : std_logic_vector(DATA_WIDTH-1 downto 0);
|
73 |
|
|
signal outdata_pipe : pipe_t;
|
74 |
|
|
signal xordata_pipe : pipe_t;
|
75 |
|
|
signal mask_pipe : pipe_mask_t;
|
76 |
|
|
signal crc_pipe : pipe_crc_t;
|
77 |
|
|
signal dv_pipe : std_logic_vector(MW-2 downto 0);
|
78 |
|
|
signal crc32 : std_logic_vector(31 downto 0);
|
79 |
|
|
signal crc24 : std_logic_vector(31 downto 0);
|
80 |
|
|
signal crc16 : std_logic_vector(31 downto 0);
|
81 |
|
|
signal crc8 : std_logic_vector(31 downto 0);
|
82 |
|
|
|
83 |
|
|
signal crc32_d : std_logic_vector(31 downto 0);
|
84 |
|
|
signal crc24_d : std_logic_vector(31 downto 0);
|
85 |
|
|
signal crc16_d : std_logic_vector(31 downto 0);
|
86 |
|
|
signal crc8_d : std_logic_vector(31 downto 0);
|
87 |
|
|
|
88 |
|
|
signal do_32 : std_logic_vector(31 downto 0);
|
89 |
|
|
signal do_24 : std_logic_vector(31 downto 0);
|
90 |
|
|
signal do_16 : std_logic_vector(31 downto 0);
|
91 |
|
|
signal do_8 : std_logic_vector(31 downto 0);
|
92 |
|
|
|
93 |
|
|
signal do_dv_d : std_logic;
|
94 |
|
|
signal do_dv_dd : std_logic;
|
95 |
|
|
|
96 |
|
|
signal mask_pipe_d : std_logic_vector(1 downto 0);
|
97 |
|
|
signal mask_pipe_dd : std_logic_vector(1 downto 0);
|
98 |
|
|
|
99 |
|
|
signal xxx : std_logic_vector(MW-1 downto 0);
|
100 |
|
|
|
101 |
|
|
begin
|
102 |
|
|
xxx <= conv_std_logic_vector(REG_BITMAP,MW);
|
103 |
|
|
|
104 |
|
|
process(MASK,DI)
|
105 |
|
|
begin
|
106 |
|
|
indata_pipe(0) <=(DATA_WIDTH-1 downto 32 => '0') & DI(31 downto 0);
|
107 |
|
|
for i in 4 to (DATA_WIDTH/8-1) loop
|
108 |
|
|
if (conv_std_logic_vector(DATA_WIDTH/8-i-1,MW) >= MASK ) then
|
109 |
|
|
indata_pipe(0)((i*8)+7 downto i*8) <= DI((i*8)+7 downto i*8);
|
110 |
|
|
end if;
|
111 |
|
|
end loop;
|
112 |
|
|
end process;
|
113 |
|
|
mask_pipe(0) <= MASK;
|
114 |
|
|
dv_pipe(0) <= DI_DV;
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
-- pipelined CRC tree --------------------------------
|
118 |
|
|
tree_gen : if DATA_WIDTH > 32 generate
|
119 |
|
|
tree_floor_gen : for i in 0 to MW-3 generate
|
120 |
|
|
-- CRC TABLE
|
121 |
|
|
crc32_fast_tab_i: entity work.crc32_fast_tab
|
122 |
|
|
generic map(
|
123 |
|
|
DATA_WIDTH => DATA_WIDTH/(2**(i+1)))
|
124 |
|
|
port map(
|
125 |
|
|
DI => indata_pipe(i)(DATA_WIDTH/(2**(i+1))-1 downto 0),
|
126 |
|
|
DO => crc_pipe(i));
|
127 |
|
|
|
128 |
|
|
-- DATA MUX
|
129 |
|
|
outdata_pipe(i)(max(32,(DATA_WIDTH/(2**(i+1))))-1 downto 0) <= indata_pipe(i)(max(32,(DATA_WIDTH/(2**(i+1))))-1 downto 0) when mask_pipe(i)(MW-i-1) = '1' else
|
130 |
|
|
xordata_pipe(i)(max(32,(DATA_WIDTH/(2**(i+1))))-1 downto 0);
|
131 |
|
|
|
132 |
|
|
-- DATA-CRC XOR
|
133 |
|
|
xor32h_gen : if (DATA_WIDTH/(2**(i+1))) > 32 generate
|
134 |
|
|
xordata_pipe(i)((DATA_WIDTH/(2**(i+1)))-1 downto 0) <= indata_pipe(i)((DATA_WIDTH/(2**(i)))-1 downto 32+(DATA_WIDTH/(2**(i+1)))) & (indata_pipe(i)((32+(DATA_WIDTH/(2**(i+1))))-1 downto (DATA_WIDTH/(2**(i+1)))) XOR crc_pipe(i));
|
135 |
|
|
end generate;
|
136 |
|
|
xor32_gen : if (DATA_WIDTH/(2**(i+1))) = 32 generate
|
137 |
|
|
xordata_pipe(i)(31 downto 0) <= indata_pipe(i)(63 downto 32) XOR crc_pipe(i);
|
138 |
|
|
end generate;
|
139 |
|
|
|
140 |
|
|
-- MASK PIPELINED
|
141 |
|
|
reg_mask_gen : if conv_std_logic_vector(REG_BITMAP,MW)(i)='1' generate
|
142 |
|
|
process(CLK)
|
143 |
|
|
begin
|
144 |
|
|
if CLK'event and CLK='1' then
|
145 |
|
|
mask_pipe(i+1)(MW-i-2 downto 0) <= mask_pipe(i)(MW-i-2 downto 0);
|
146 |
|
|
end if;
|
147 |
|
|
end process;
|
148 |
|
|
end generate;
|
149 |
|
|
noreg_mask_gen : if conv_std_logic_vector(REG_BITMAP,MW)(i)='0' generate
|
150 |
|
|
mask_pipe(i+1)(MW-i-2 downto 0) <= mask_pipe(i)(MW-i-2 downto 0);
|
151 |
|
|
end generate;
|
152 |
|
|
-- DATA PIPELINED
|
153 |
|
|
reg_data_gen : if conv_std_logic_vector(REG_BITMAP,MW)(i)='1' generate
|
154 |
|
|
process(CLK)
|
155 |
|
|
begin
|
156 |
|
|
if CLK'event and CLK='1' then
|
157 |
|
|
indata_pipe(i+1) <= outdata_pipe(i);
|
158 |
|
|
dv_pipe(i+1) <= dv_pipe(i);
|
159 |
|
|
end if;
|
160 |
|
|
end process;
|
161 |
|
|
end generate;
|
162 |
|
|
noreg_data_gen : if conv_std_logic_vector(REG_BITMAP,MW)(i)='0' generate
|
163 |
|
|
indata_pipe(i+1) <= outdata_pipe(i);
|
164 |
|
|
dv_pipe(i+1) <= dv_pipe(i);
|
165 |
|
|
end generate;
|
166 |
|
|
end generate;
|
167 |
|
|
end generate;
|
168 |
|
|
|
169 |
|
|
crc32_fast_tab_32: entity work.crc32_fast_tab
|
170 |
|
|
generic map(
|
171 |
|
|
DATA_WIDTH => 32)
|
172 |
|
|
port map(
|
173 |
|
|
DI => indata_pipe(MW-2)(31 downto 0),
|
174 |
|
|
DO => crc32);
|
175 |
|
|
crc32_fast_tab_24: entity work.crc32_fast_tab
|
176 |
|
|
generic map(
|
177 |
|
|
DATA_WIDTH => 24)
|
178 |
|
|
port map(
|
179 |
|
|
DI => indata_pipe(MW-2)(23 downto 0),
|
180 |
|
|
DO => crc24);
|
181 |
|
|
crc32_fast_tab_16: entity work.crc32_fast_tab
|
182 |
|
|
generic map(
|
183 |
|
|
DATA_WIDTH => 16)
|
184 |
|
|
port map(
|
185 |
|
|
DI => indata_pipe(MW-2)(15 downto 0),
|
186 |
|
|
DO => crc16);
|
187 |
|
|
crc32_fast_tab_8: entity work.crc32_fast_tab
|
188 |
|
|
generic map(
|
189 |
|
|
DATA_WIDTH => 8)
|
190 |
|
|
port map(
|
191 |
|
|
DI => indata_pipe(MW-2)(7 downto 0),
|
192 |
|
|
DO => crc8);
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
do_pipeline_proc : process (CLK)
|
196 |
|
|
begin
|
197 |
|
|
if rising_edge(CLK) then
|
198 |
|
|
crc8_d <= crc8;
|
199 |
|
|
crc16_d <= crc16;
|
200 |
|
|
crc24_d <= crc24;
|
201 |
|
|
crc32_d <= crc32;
|
202 |
|
|
do_dv_d <= dv_pipe(MW-2);
|
203 |
|
|
|
204 |
|
|
indata_pipe_MW_2_d <= indata_pipe(MW-2);
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
do_8 <= ((X"00" & indata_pipe_MW_2_d(31 downto 8)) XOR crc8_d);
|
208 |
|
|
do_16 <= ((X"0000" & indata_pipe_MW_2_d(31 downto 16)) XOR crc16_d);
|
209 |
|
|
do_24 <= ((X"000000" & indata_pipe_MW_2_d(31 downto 24)) XOR crc24_d);
|
210 |
|
|
do_32 <= (crc32_d);
|
211 |
|
|
do_dv_dd <= do_dv_d;
|
212 |
|
|
|
213 |
|
|
mask_pipe_d <= mask_pipe(MW-2)(1 downto 0);
|
214 |
|
|
mask_pipe_dd <= mask_pipe_d;
|
215 |
|
|
|
216 |
|
|
end if;
|
217 |
|
|
end process;
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
DO <= do_8 when mask_pipe_dd ="11" else
|
223 |
|
|
do_16 when mask_pipe_dd ="10" else
|
224 |
|
|
do_24 when mask_pipe_dd ="01" else
|
225 |
|
|
do_32;
|
226 |
|
|
|
227 |
|
|
DO_DV <= do_dv_dd;
|
228 |
|
|
|
229 |
|
|
end architecture crc32_gen_tab_arch;
|
230 |
|
|
|
231 |
|
|
|
232 |
|
|
|