1 |
2 |
dimamali |
------------------------------------------------------------------------------
|
2 |
|
|
-- This file is a part of the GRLIB VHDL IP LIBRARY
|
3 |
|
|
-- Copyright (C) 2003, Gaisler Research
|
4 |
|
|
--
|
5 |
|
|
-- This program is free software; you can redistribute it and/or modify
|
6 |
|
|
-- it under the terms of the GNU General Public License as published by
|
7 |
|
|
-- the Free Software Foundation; either version 2 of the License, or
|
8 |
|
|
-- (at your option) any later version.
|
9 |
|
|
--
|
10 |
|
|
-- This program is distributed in the hope that it will be useful,
|
11 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
-- GNU General Public License for more details.
|
14 |
|
|
--
|
15 |
|
|
-- You should have received a copy of the GNU General Public License
|
16 |
|
|
-- along with this program; if not, write to the Free Software
|
17 |
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
|
|
------------------------------------------------------------------------------
|
19 |
|
|
library ieee;
|
20 |
|
|
use ieee.std_logic_1164.all;
|
21 |
|
|
library grlib;
|
22 |
|
|
use grlib.stdlib.all;
|
23 |
|
|
|
24 |
|
|
package grethpkg is
|
25 |
|
|
--gigabit sync types
|
26 |
|
|
type data_sync_type is array (0 to 3) of std_logic_vector(31 downto 0);
|
27 |
|
|
type ctrl_sync_type is array (0 to 3) of std_logic_vector(1 downto 0);
|
28 |
|
|
|
29 |
|
|
constant HTRANS_IDLE: std_logic_vector(1 downto 0) := "00";
|
30 |
|
|
constant HTRANS_NONSEQ: std_logic_vector(1 downto 0) := "10";
|
31 |
|
|
constant HTRANS_SEQ: std_logic_vector(1 downto 0) := "11";
|
32 |
|
|
|
33 |
|
|
constant HBURST_INCR: std_logic_vector(2 downto 0) := "001";
|
34 |
|
|
|
35 |
|
|
constant HSIZE_WORD: std_logic_vector(2 downto 0) := "010";
|
36 |
|
|
|
37 |
|
|
constant HRESP_OKAY: std_logic_vector(1 downto 0) := "00";
|
38 |
|
|
constant HRESP_ERROR: std_logic_vector(1 downto 0) := "01";
|
39 |
|
|
constant HRESP_RETRY: std_logic_vector(1 downto 0) := "10";
|
40 |
|
|
constant HRESP_SPLIT: std_logic_vector(1 downto 0) := "11";
|
41 |
|
|
|
42 |
|
|
--receiver constants
|
43 |
|
|
constant maxsizerx : std_logic_vector(15 downto 0) :=
|
44 |
|
|
conv_std_logic_vector(1500, 16);
|
45 |
|
|
constant minpload : std_logic_vector(10 downto 0) :=
|
46 |
|
|
conv_std_logic_vector(60, 11);
|
47 |
|
|
|
48 |
|
|
type ahb_fifo_in_type is record
|
49 |
|
|
renable : std_ulogic;
|
50 |
|
|
raddress : std_logic_vector(4 downto 0);
|
51 |
|
|
write : std_ulogic;
|
52 |
|
|
data : std_logic_vector(31 downto 0);
|
53 |
|
|
waddress : std_logic_vector(4 downto 0);
|
54 |
|
|
end record;
|
55 |
|
|
|
56 |
|
|
type ahb_fifo_out_type is record
|
57 |
|
|
data : std_logic_vector(31 downto 0);
|
58 |
|
|
end record;
|
59 |
|
|
|
60 |
|
|
type nchar_fifo_in_type is record
|
61 |
|
|
renable : std_ulogic;
|
62 |
|
|
raddress : std_logic_vector(5 downto 0);
|
63 |
|
|
write : std_ulogic;
|
64 |
|
|
data : std_logic_vector(8 downto 0);
|
65 |
|
|
waddress : std_logic_vector(5 downto 0);
|
66 |
|
|
end record;
|
67 |
|
|
|
68 |
|
|
type nchar_fifo_out_type is record
|
69 |
|
|
data : std_logic_vector(8 downto 0);
|
70 |
|
|
end record;
|
71 |
|
|
|
72 |
|
|
type rmapbuf_in_type is record
|
73 |
|
|
renable : std_ulogic;
|
74 |
|
|
raddress : std_logic_vector(7 downto 0);
|
75 |
|
|
write : std_ulogic;
|
76 |
|
|
data : std_logic_vector(7 downto 0);
|
77 |
|
|
waddress : std_logic_vector(7 downto 0);
|
78 |
|
|
end record;
|
79 |
|
|
|
80 |
|
|
type rmapbuf_out_type is record
|
81 |
|
|
data : std_logic_vector(7 downto 0);
|
82 |
|
|
end record;
|
83 |
|
|
|
84 |
|
|
type ahbc_mst_in_type is record
|
85 |
|
|
hgrant : std_ulogic; -- bus grant
|
86 |
|
|
hready : std_ulogic; -- transfer done
|
87 |
|
|
hresp : std_logic_vector(1 downto 0); -- response type
|
88 |
|
|
hrdata : std_logic_vector(31 downto 0); -- read data bus
|
89 |
|
|
end record;
|
90 |
|
|
|
91 |
|
|
type ahbc_mst_out_type is record
|
92 |
|
|
hbusreq : std_ulogic; -- bus request
|
93 |
|
|
hlock : std_ulogic; -- lock request
|
94 |
|
|
htrans : std_logic_vector(1 downto 0); -- transfer type
|
95 |
|
|
haddr : std_logic_vector(31 downto 0); -- address bus (byte)
|
96 |
|
|
hwrite : std_ulogic; -- read/write
|
97 |
|
|
hsize : std_logic_vector(2 downto 0); -- transfer size
|
98 |
|
|
hburst : std_logic_vector(2 downto 0); -- burst type
|
99 |
|
|
hprot : std_logic_vector(3 downto 0); -- protection control
|
100 |
|
|
hwdata : std_logic_vector(31 downto 0); -- write data bus
|
101 |
|
|
end record;
|
102 |
|
|
|
103 |
|
|
type apbc_slv_in_type is record
|
104 |
|
|
psel : std_ulogic; -- slave select
|
105 |
|
|
penable : std_ulogic; -- strobe
|
106 |
|
|
paddr : std_logic_vector(31 downto 0); -- address bus (byte)
|
107 |
|
|
pwrite : std_ulogic; -- write
|
108 |
|
|
pwdata : std_logic_vector(31 downto 0); -- write data bus
|
109 |
|
|
end record;
|
110 |
|
|
|
111 |
|
|
type apbc_slv_out_type is record
|
112 |
|
|
prdata : std_logic_vector(31 downto 0); -- read data bus
|
113 |
|
|
end record;
|
114 |
|
|
|
115 |
|
|
type eth_tx_ahb_in_type is record
|
116 |
|
|
req : std_ulogic;
|
117 |
|
|
write : std_ulogic;
|
118 |
|
|
addr : std_logic_vector(31 downto 0);
|
119 |
|
|
data : std_logic_vector(31 downto 0);
|
120 |
|
|
end record;
|
121 |
|
|
|
122 |
|
|
type eth_tx_ahb_out_type is record
|
123 |
|
|
grant : std_ulogic;
|
124 |
|
|
data : std_logic_vector(31 downto 0);
|
125 |
|
|
ready : std_ulogic;
|
126 |
|
|
error : std_ulogic;
|
127 |
|
|
retry : std_ulogic;
|
128 |
|
|
end record;
|
129 |
|
|
|
130 |
|
|
type eth_rx_ahb_in_type is record
|
131 |
|
|
req : std_ulogic;
|
132 |
|
|
write : std_ulogic;
|
133 |
|
|
addr : std_logic_vector(31 downto 0);
|
134 |
|
|
data : std_logic_vector(31 downto 0);
|
135 |
|
|
end record;
|
136 |
|
|
|
137 |
|
|
type eth_rx_ahb_out_type is record
|
138 |
|
|
grant : std_ulogic;
|
139 |
|
|
ready : std_ulogic;
|
140 |
|
|
error : std_ulogic;
|
141 |
|
|
retry : std_ulogic;
|
142 |
|
|
data : std_logic_vector(31 downto 0);
|
143 |
|
|
end record;
|
144 |
|
|
|
145 |
|
|
type eth_rx_gbit_ahb_in_type is record
|
146 |
|
|
req : std_ulogic;
|
147 |
|
|
write : std_ulogic;
|
148 |
|
|
addr : std_logic_vector(31 downto 0);
|
149 |
|
|
data : std_logic_vector(31 downto 0);
|
150 |
|
|
size : std_logic_vector(1 downto 0);
|
151 |
|
|
end record;
|
152 |
|
|
|
153 |
|
|
type gbit_host_tx_type is record
|
154 |
|
|
full_duplex : std_ulogic;
|
155 |
|
|
start : std_ulogic;
|
156 |
|
|
read_ack : std_ulogic;
|
157 |
|
|
data : std_logic_vector(31 downto 0);
|
158 |
|
|
valid : std_ulogic;
|
159 |
|
|
len : std_logic_vector(10 downto 0);
|
160 |
|
|
rx_col : std_ulogic;
|
161 |
|
|
rx_crs : std_ulogic;
|
162 |
|
|
end record;
|
163 |
|
|
|
164 |
|
|
type gbit_tx_host_type is record
|
165 |
|
|
txd : std_logic_vector(3 downto 0);
|
166 |
|
|
tx_en : std_ulogic;
|
167 |
|
|
done : std_ulogic;
|
168 |
|
|
read : std_ulogic;
|
169 |
|
|
restart : std_ulogic;
|
170 |
|
|
status : std_logic_vector(1 downto 0);
|
171 |
|
|
end record;
|
172 |
|
|
|
173 |
|
|
type gbit_rx_host_type is record
|
174 |
|
|
sync_start : std_ulogic;
|
175 |
|
|
done : std_ulogic;
|
176 |
|
|
write : std_logic_vector(3 downto 0);
|
177 |
|
|
dataout : data_sync_type;
|
178 |
|
|
byte_count : std_logic_vector(10 downto 0);
|
179 |
|
|
status : std_logic_vector(3 downto 0);
|
180 |
|
|
gotframe : std_ulogic;
|
181 |
|
|
end record;
|
182 |
|
|
|
183 |
|
|
type gbit_host_rx_type is record
|
184 |
|
|
full_duplex : std_ulogic;
|
185 |
|
|
gbit : std_ulogic;
|
186 |
|
|
doneack : std_ulogic;
|
187 |
|
|
writeack : std_logic_vector(3 downto 0);
|
188 |
|
|
speed : std_ulogic;
|
189 |
|
|
writeok : std_logic_vector(3 downto 0);
|
190 |
|
|
rxenable : std_ulogic;
|
191 |
|
|
rxd : std_logic_vector(7 downto 0);
|
192 |
|
|
rx_dv : std_ulogic;
|
193 |
|
|
rx_er : std_ulogic;
|
194 |
|
|
rx_col : std_ulogic;
|
195 |
|
|
rx_crs : std_ulogic;
|
196 |
|
|
end record;
|
197 |
|
|
|
198 |
|
|
type gbit_gtx_host_type is record
|
199 |
|
|
txd : std_logic_vector(7 downto 0);
|
200 |
|
|
tx_en : std_ulogic;
|
201 |
|
|
tx_er : std_ulogic;
|
202 |
|
|
done : std_ulogic;
|
203 |
|
|
restart : std_ulogic;
|
204 |
|
|
read : std_logic_vector(3 downto 0);
|
205 |
|
|
status : std_logic_vector(2 downto 0);
|
206 |
|
|
end record;
|
207 |
|
|
|
208 |
|
|
type gbit_host_gtx_type is record
|
209 |
|
|
rx_col : std_ulogic;
|
210 |
|
|
rx_crs : std_ulogic;
|
211 |
|
|
full_duplex : std_ulogic;
|
212 |
|
|
burstmode : std_ulogic;
|
213 |
|
|
txen : std_ulogic;
|
214 |
|
|
start_sync : std_ulogic;
|
215 |
|
|
readack : std_logic_vector(3 downto 0);
|
216 |
|
|
valid : std_logic_vector(3 downto 0);
|
217 |
|
|
data : data_sync_type;
|
218 |
|
|
len : std_logic_vector(10 downto 0);
|
219 |
|
|
end record;
|
220 |
|
|
|
221 |
|
|
type host_tx_type is record
|
222 |
|
|
rx_col : std_ulogic;
|
223 |
|
|
rx_crs : std_ulogic;
|
224 |
|
|
full_duplex : std_ulogic;
|
225 |
|
|
start : std_ulogic;
|
226 |
|
|
readack : std_ulogic;
|
227 |
|
|
speed : std_ulogic;
|
228 |
|
|
data : std_logic_vector(31 downto 0);
|
229 |
|
|
valid : std_ulogic;
|
230 |
|
|
len : std_logic_vector(10 downto 0);
|
231 |
|
|
end record;
|
232 |
|
|
|
233 |
|
|
type tx_host_type is record
|
234 |
|
|
txd : std_logic_vector(3 downto 0);
|
235 |
|
|
tx_en : std_ulogic;
|
236 |
|
|
tx_er : std_ulogic;
|
237 |
|
|
done : std_ulogic;
|
238 |
|
|
read : std_ulogic;
|
239 |
|
|
restart : std_ulogic;
|
240 |
|
|
status : std_logic_vector(1 downto 0);
|
241 |
|
|
end record;
|
242 |
|
|
|
243 |
|
|
type rx_host_type is record
|
244 |
|
|
dataout : std_logic_vector(31 downto 0);
|
245 |
|
|
start : std_ulogic;
|
246 |
|
|
done : std_ulogic;
|
247 |
|
|
write : std_ulogic;
|
248 |
|
|
status : std_logic_vector(3 downto 0);
|
249 |
|
|
gotframe : std_ulogic;
|
250 |
|
|
byte_count : std_logic_vector(10 downto 0);
|
251 |
|
|
lentype : std_logic_vector(15 downto 0);
|
252 |
|
|
end record;
|
253 |
|
|
|
254 |
|
|
type host_rx_type is record
|
255 |
|
|
writeack : std_ulogic;
|
256 |
|
|
doneack : std_ulogic;
|
257 |
|
|
speed : std_ulogic;
|
258 |
|
|
writeok : std_ulogic;
|
259 |
|
|
rxd : std_logic_vector(3 downto 0);
|
260 |
|
|
rx_dv : std_ulogic;
|
261 |
|
|
rx_crs : std_ulogic;
|
262 |
|
|
rx_er : std_ulogic;
|
263 |
|
|
enable : std_ulogic;
|
264 |
|
|
end record;
|
265 |
|
|
|
266 |
|
|
component greth_rx is
|
267 |
|
|
generic(
|
268 |
|
|
nsync : integer range 1 to 2 := 2;
|
269 |
|
|
rmii : integer range 0 to 1 := 0);
|
270 |
|
|
port(
|
271 |
|
|
rst : in std_ulogic;
|
272 |
|
|
clk : in std_ulogic;
|
273 |
|
|
rxi : in host_rx_type;
|
274 |
|
|
rxo : out rx_host_type
|
275 |
|
|
);
|
276 |
|
|
end component;
|
277 |
|
|
|
278 |
|
|
component greth_tx is
|
279 |
|
|
generic(
|
280 |
|
|
ifg_gap : integer := 24;
|
281 |
|
|
attempt_limit : integer := 16;
|
282 |
|
|
backoff_limit : integer := 10;
|
283 |
|
|
nsync : integer range 1 to 2 := 2;
|
284 |
|
|
rmii : integer range 0 to 1 := 0);
|
285 |
|
|
port(
|
286 |
|
|
rst : in std_ulogic;
|
287 |
|
|
clk : in std_ulogic;
|
288 |
|
|
txi : in host_tx_type;
|
289 |
|
|
txo : out tx_host_type
|
290 |
|
|
);
|
291 |
|
|
end component;
|
292 |
|
|
|
293 |
|
|
component eth_rstgen is
|
294 |
|
|
generic(acthigh : integer := 0);
|
295 |
|
|
port (
|
296 |
|
|
rstin : in std_ulogic;
|
297 |
|
|
clk : in std_ulogic;
|
298 |
|
|
clklock : in std_ulogic;
|
299 |
|
|
rstout : out std_ulogic;
|
300 |
|
|
rstoutraw : out std_ulogic
|
301 |
|
|
);
|
302 |
|
|
end component;
|
303 |
|
|
|
304 |
|
|
component greth_gbit_tx is
|
305 |
|
|
generic(
|
306 |
|
|
ifg_gap : integer := 24;
|
307 |
|
|
attempt_limit : integer := 16;
|
308 |
|
|
backoff_limit : integer := 10;
|
309 |
|
|
nsync : integer range 1 to 2 := 2);
|
310 |
|
|
port(
|
311 |
|
|
rst : in std_ulogic;
|
312 |
|
|
clk : in std_ulogic;
|
313 |
|
|
txi : in gbit_host_tx_type;
|
314 |
|
|
txo : out gbit_tx_host_type);
|
315 |
|
|
end component;
|
316 |
|
|
|
317 |
|
|
component greth_gbit_gtx is
|
318 |
|
|
generic(
|
319 |
|
|
ifg_gap : integer := 24;
|
320 |
|
|
attempt_limit : integer := 16;
|
321 |
|
|
backoff_limit : integer := 10;
|
322 |
|
|
nsync : integer range 1 to 2 := 2);
|
323 |
|
|
port(
|
324 |
|
|
rst : in std_ulogic;
|
325 |
|
|
clk : in std_ulogic;
|
326 |
|
|
gtxi : in gbit_host_gtx_type;
|
327 |
|
|
gtxo : out gbit_gtx_host_type
|
328 |
|
|
);
|
329 |
|
|
end component;
|
330 |
|
|
|
331 |
|
|
component greth_gbit_rx is
|
332 |
|
|
generic(
|
333 |
|
|
nsync : integer range 1 to 2 := 2);
|
334 |
|
|
port(
|
335 |
|
|
rst : in std_ulogic;
|
336 |
|
|
clk : in std_ulogic;
|
337 |
|
|
rxi : in gbit_host_rx_type;
|
338 |
|
|
rxo : out gbit_rx_host_type);
|
339 |
|
|
end component;
|
340 |
|
|
|
341 |
|
|
component eth_ahb_mst is
|
342 |
|
|
port(
|
343 |
|
|
rst : in std_ulogic;
|
344 |
|
|
clk : in std_ulogic;
|
345 |
|
|
ahbmi : in ahbc_mst_in_type;
|
346 |
|
|
ahbmo : out ahbc_mst_out_type;
|
347 |
|
|
tmsti : in eth_tx_ahb_in_type;
|
348 |
|
|
tmsto : out eth_tx_ahb_out_type;
|
349 |
|
|
rmsti : in eth_rx_ahb_in_type;
|
350 |
|
|
rmsto : out eth_rx_ahb_out_type
|
351 |
|
|
);
|
352 |
|
|
end component;
|
353 |
|
|
|
354 |
|
|
component eth_ahb_mst_gbit is
|
355 |
|
|
port(
|
356 |
|
|
rst : in std_ulogic;
|
357 |
|
|
clk : in std_ulogic;
|
358 |
|
|
ahbmi : in ahbc_mst_in_type;
|
359 |
|
|
ahbmo : out ahbc_mst_out_type;
|
360 |
|
|
tmsti : in eth_tx_ahb_in_type;
|
361 |
|
|
tmsto : out eth_tx_ahb_out_type;
|
362 |
|
|
rmsti : in eth_rx_gbit_ahb_in_type;
|
363 |
|
|
rmsto : out eth_rx_ahb_out_type);
|
364 |
|
|
end component;
|
365 |
|
|
|
366 |
|
|
function mirror(din : in std_logic_vector) return std_logic_vector;
|
367 |
|
|
|
368 |
|
|
function crc32_4(d : in std_logic_vector(3 downto 0);
|
369 |
|
|
crc : in std_logic_vector(31 downto 0))
|
370 |
|
|
return std_logic_vector;
|
371 |
|
|
function crc16_2(d1 : in std_logic_vector(15 downto 0);
|
372 |
|
|
d2 : in std_logic_vector(25 downto 0))
|
373 |
|
|
return std_logic_vector;
|
374 |
|
|
function crc16(d1 : in std_logic_vector(15 downto 0);
|
375 |
|
|
d2 : in std_logic_vector(15 downto 0))
|
376 |
|
|
return std_logic_vector;
|
377 |
|
|
|
378 |
|
|
function validlen(len : in std_logic_vector(10 downto 0);
|
379 |
|
|
bcnt : in std_logic_vector(10 downto 0);
|
380 |
|
|
usesz : in std_ulogic)
|
381 |
|
|
return std_ulogic;
|
382 |
|
|
|
383 |
|
|
function getfifosize(edcl, fifosize, ebufsize : in integer) return integer;
|
384 |
|
|
|
385 |
|
|
function setburstlength(fifosize : in integer) return integer;
|
386 |
|
|
|
387 |
|
|
function calccrc(d : in std_logic_vector(3 downto 0);
|
388 |
|
|
crc : in std_logic_vector(31 downto 0))
|
389 |
|
|
return std_logic_vector;
|
390 |
|
|
|
391 |
|
|
--16-bit one's complement adder
|
392 |
|
|
function crcadder(d1 : in std_logic_vector(15 downto 0);
|
393 |
|
|
d2 : in std_logic_vector(17 downto 0))
|
394 |
|
|
return std_logic_vector;
|
395 |
|
|
|
396 |
|
|
end package;
|
397 |
|
|
|
398 |
|
|
package body grethpkg is
|
399 |
|
|
|
400 |
|
|
function mirror(din : in std_logic_vector)
|
401 |
|
|
return std_logic_vector is
|
402 |
|
|
variable do : std_logic_vector(din'high downto din'low);
|
403 |
|
|
begin
|
404 |
|
|
for i in 0 to din'length-1 loop
|
405 |
|
|
do(din'high-i) := din(i+din'low);
|
406 |
|
|
end loop;
|
407 |
|
|
return do;
|
408 |
|
|
end function;
|
409 |
|
|
|
410 |
|
|
function crc32_4(d : in std_logic_vector(3 downto 0);
|
411 |
|
|
crc : in std_logic_vector(31 downto 0))
|
412 |
|
|
return std_logic_vector is
|
413 |
|
|
variable ncrc : std_logic_vector(31 downto 0);
|
414 |
|
|
variable tc : std_logic_vector(3 downto 0);
|
415 |
|
|
begin
|
416 |
|
|
tc(0) := d(0) xor crc(31); tc(1) := d(1) xor crc(30);
|
417 |
|
|
tc(2) := d(2) xor crc(29); tc(3) := d(3) xor crc(28);
|
418 |
|
|
ncrc(31) := crc(27);
|
419 |
|
|
ncrc(30) := crc(26);
|
420 |
|
|
ncrc(29) := tc(0) xor crc(25);
|
421 |
|
|
ncrc(28) := tc(1) xor crc(24);
|
422 |
|
|
ncrc(27) := tc(2) xor crc(23);
|
423 |
|
|
ncrc(26) := tc(0) xor tc(3) xor crc(22);
|
424 |
|
|
ncrc(25) := tc(0) xor tc(1) xor crc(21);
|
425 |
|
|
ncrc(24) := tc(1) xor tc(2) xor crc(20);
|
426 |
|
|
ncrc(23) := tc(2) xor tc(3) xor crc(19);
|
427 |
|
|
ncrc(22) := tc(3) xor crc(18);
|
428 |
|
|
ncrc(21) := crc(17);
|
429 |
|
|
ncrc(20) := crc(16);
|
430 |
|
|
ncrc(19) := tc(0) xor crc(15);
|
431 |
|
|
ncrc(18) := tc(1) xor crc(14);
|
432 |
|
|
ncrc(17) := tc(2) xor crc(13);
|
433 |
|
|
ncrc(16) := tc(3) xor crc(12);
|
434 |
|
|
ncrc(15) := tc(0) xor crc(11);
|
435 |
|
|
ncrc(14) := tc(0) xor tc(1) xor crc(10);
|
436 |
|
|
ncrc(13) := tc(0) xor tc(1) xor tc(2) xor crc(9);
|
437 |
|
|
ncrc(12) := tc(1) xor tc(2) xor tc(3) xor crc(8);
|
438 |
|
|
ncrc(11) := tc(0) xor tc(2) xor tc(3) xor crc(7);
|
439 |
|
|
ncrc(10) := tc(0) xor tc(1) xor tc(3) xor crc(6);
|
440 |
|
|
ncrc(9) := tc(1) xor tc(2) xor crc(5);
|
441 |
|
|
ncrc(8) := tc(0) xor tc(2) xor tc(3) xor crc(4);
|
442 |
|
|
ncrc(7) := tc(0) xor tc(1) xor tc(3) xor crc(3);
|
443 |
|
|
ncrc(6) := tc(1) xor tc(2) xor crc(2);
|
444 |
|
|
ncrc(5) := tc(0) xor tc(2) xor tc(3) xor crc(1);
|
445 |
|
|
ncrc(4) := tc(0) xor tc(1) xor tc(3) xor crc(0);
|
446 |
|
|
ncrc(3) := tc(0) xor tc(1) xor tc(2);
|
447 |
|
|
ncrc(2) := tc(1) xor tc(2) xor tc(3);
|
448 |
|
|
ncrc(1) := tc(2) xor tc(3);
|
449 |
|
|
ncrc(0) := tc(3);
|
450 |
|
|
return ncrc;
|
451 |
|
|
end function;
|
452 |
|
|
|
453 |
|
|
--16-bit one's complement adder
|
454 |
|
|
function crc16(d1 : in std_logic_vector(15 downto 0);
|
455 |
|
|
d2 : in std_logic_vector(15 downto 0))
|
456 |
|
|
return std_logic_vector is
|
457 |
|
|
variable vd1 : std_logic_vector(16 downto 0);
|
458 |
|
|
variable vd2 : std_logic_vector(16 downto 0);
|
459 |
|
|
variable sum : std_logic_vector(16 downto 0);
|
460 |
|
|
begin
|
461 |
|
|
vd1 := '0' & d1; vd2 := '0' & d2;
|
462 |
|
|
sum := vd1 + vd2;
|
463 |
|
|
sum(15 downto 0) := sum(15 downto 0) + sum(16);
|
464 |
|
|
return sum(15 downto 0);
|
465 |
|
|
end function;
|
466 |
|
|
|
467 |
|
|
--16-bit one's complement adder for ip/tcp checksum detection
|
468 |
|
|
function crc16_2(d1 : in std_logic_vector(15 downto 0);
|
469 |
|
|
d2 : in std_logic_vector(25 downto 0))
|
470 |
|
|
return std_logic_vector is
|
471 |
|
|
variable vd1 : std_logic_vector(25 downto 0);
|
472 |
|
|
variable vd2 : std_logic_vector(25 downto 0);
|
473 |
|
|
variable sum : std_logic_vector(25 downto 0);
|
474 |
|
|
begin
|
475 |
|
|
vd1 := "0000000000" & d1; vd2 := d2;
|
476 |
|
|
sum := vd1 + vd2;
|
477 |
|
|
return sum;
|
478 |
|
|
end function;
|
479 |
|
|
|
480 |
|
|
function validlen(len : in std_logic_vector(10 downto 0);
|
481 |
|
|
bcnt : in std_logic_vector(10 downto 0);
|
482 |
|
|
usesz : in std_ulogic)
|
483 |
|
|
return std_ulogic is
|
484 |
|
|
variable valid : std_ulogic;
|
485 |
|
|
begin
|
486 |
|
|
valid := '1';
|
487 |
|
|
if usesz = '1' then
|
488 |
|
|
if len > minpload then
|
489 |
|
|
if bcnt /= len then
|
490 |
|
|
valid := '0';
|
491 |
|
|
end if;
|
492 |
|
|
else
|
493 |
|
|
if bcnt /= minpload then
|
494 |
|
|
valid := '0';
|
495 |
|
|
end if;
|
496 |
|
|
end if;
|
497 |
|
|
end if;
|
498 |
|
|
return valid;
|
499 |
|
|
end function;
|
500 |
|
|
|
501 |
|
|
function setburstlength(fifosize : in integer) return integer is
|
502 |
|
|
begin
|
503 |
|
|
if fifosize <= 64 then
|
504 |
|
|
return fifosize/2;
|
505 |
|
|
else
|
506 |
|
|
return 32;
|
507 |
|
|
end if;
|
508 |
|
|
end function;
|
509 |
|
|
|
510 |
|
|
function getfifosize(edcl, fifosize, ebufsize : in integer) return integer is
|
511 |
|
|
begin
|
512 |
|
|
if (edcl /= 0) and (ebufsize > fifosize) then
|
513 |
|
|
return ebufsize;
|
514 |
|
|
else
|
515 |
|
|
return fifosize;
|
516 |
|
|
end if;
|
517 |
|
|
end function;
|
518 |
|
|
|
519 |
|
|
function calccrc(d : in std_logic_vector(3 downto 0);
|
520 |
|
|
crc : in std_logic_vector(31 downto 0))
|
521 |
|
|
return std_logic_vector is
|
522 |
|
|
variable ncrc : std_logic_vector(31 downto 0);
|
523 |
|
|
variable tc : std_logic_vector(3 downto 0);
|
524 |
|
|
begin
|
525 |
|
|
tc(0) := d(0) xor crc(31); tc(1) := d(1) xor crc(30);
|
526 |
|
|
tc(2) := d(2) xor crc(29); tc(3) := d(3) xor crc(28);
|
527 |
|
|
ncrc(31) := crc(27);
|
528 |
|
|
ncrc(30) := crc(26);
|
529 |
|
|
ncrc(29) := tc(0) xor crc(25);
|
530 |
|
|
ncrc(28) := tc(1) xor crc(24);
|
531 |
|
|
ncrc(27) := tc(2) xor crc(23);
|
532 |
|
|
ncrc(26) := tc(0) xor tc(3) xor crc(22);
|
533 |
|
|
ncrc(25) := tc(0) xor tc(1) xor crc(21);
|
534 |
|
|
ncrc(24) := tc(1) xor tc(2) xor crc(20);
|
535 |
|
|
ncrc(23) := tc(2) xor tc(3) xor crc(19);
|
536 |
|
|
ncrc(22) := tc(3) xor crc(18);
|
537 |
|
|
ncrc(21) := crc(17);
|
538 |
|
|
ncrc(20) := crc(16);
|
539 |
|
|
ncrc(19) := tc(0) xor crc(15);
|
540 |
|
|
ncrc(18) := tc(1) xor crc(14);
|
541 |
|
|
ncrc(17) := tc(2) xor crc(13);
|
542 |
|
|
ncrc(16) := tc(3) xor crc(12);
|
543 |
|
|
ncrc(15) := tc(0) xor crc(11);
|
544 |
|
|
ncrc(14) := tc(0) xor tc(1) xor crc(10);
|
545 |
|
|
ncrc(13) := tc(0) xor tc(1) xor tc(2) xor crc(9);
|
546 |
|
|
ncrc(12) := tc(1) xor tc(2) xor tc(3) xor crc(8);
|
547 |
|
|
ncrc(11) := tc(0) xor tc(2) xor tc(3) xor crc(7);
|
548 |
|
|
ncrc(10) := tc(0) xor tc(1) xor tc(3) xor crc(6);
|
549 |
|
|
ncrc(9) := tc(1) xor tc(2) xor crc(5);
|
550 |
|
|
ncrc(8) := tc(0) xor tc(2) xor tc(3) xor crc(4);
|
551 |
|
|
ncrc(7) := tc(0) xor tc(1) xor tc(3) xor crc(3);
|
552 |
|
|
ncrc(6) := tc(1) xor tc(2) xor crc(2);
|
553 |
|
|
ncrc(5) := tc(0) xor tc(2) xor tc(3) xor crc(1);
|
554 |
|
|
ncrc(4) := tc(0) xor tc(1) xor tc(3) xor crc(0);
|
555 |
|
|
ncrc(3) := tc(0) xor tc(1) xor tc(2);
|
556 |
|
|
ncrc(2) := tc(1) xor tc(2) xor tc(3);
|
557 |
|
|
ncrc(1) := tc(2) xor tc(3);
|
558 |
|
|
ncrc(0) := tc(3);
|
559 |
|
|
return ncrc;
|
560 |
|
|
end function;
|
561 |
|
|
|
562 |
|
|
--16-bit one's complement adder
|
563 |
|
|
function crcadder(d1 : in std_logic_vector(15 downto 0);
|
564 |
|
|
d2 : in std_logic_vector(17 downto 0))
|
565 |
|
|
return std_logic_vector is
|
566 |
|
|
variable vd1 : std_logic_vector(17 downto 0);
|
567 |
|
|
variable vd2 : std_logic_vector(17 downto 0);
|
568 |
|
|
variable sum : std_logic_vector(17 downto 0);
|
569 |
|
|
begin
|
570 |
|
|
vd1 := "00" & d1; vd2 := d2;
|
571 |
|
|
sum := vd1 + vd2;
|
572 |
|
|
return sum;
|
573 |
|
|
end function;
|
574 |
|
|
|
575 |
|
|
end package body;
|