-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathudp_build_status.vhd
263 lines (250 loc) · 7.05 KB
/
udp_build_status.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
-- Builds outbound status packet
--
-- Dave Sankey, Jan 2013
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity udp_build_status is
port (
mac_clk: in std_logic;
rx_reset: in std_logic;
mac_rx_data: in std_logic_vector(7 downto 0);
mac_rx_valid: in std_logic;
mac_rx_last: in std_logic;
mac_rx_error: in std_logic;
pkt_drop_status: in std_logic;
status_block: in std_logic_vector(127 downto 0);
status_request: out std_logic;
status_data: out std_logic_vector(7 downto 0);
status_addr: out std_logic_vector(12 downto 0);
status_we: out std_logic;
status_end_addr: out std_logic_vector(12 downto 0);
status_send: out std_logic
);
end udp_build_status;
architecture rtl of udp_build_status is
signal set_addr: std_logic;
signal send_pending, send_buf, load_buf: std_logic;
signal address, addr_to_set: unsigned(6 downto 0);
begin
status_addr <= std_logic_vector("000000" & address);
send_packet: process (mac_clk)
variable end_addr_i: std_logic_vector(12 downto 0);
begin
if rising_edge(mac_clk) then
if send_pending = '1' then
end_addr_i := std_logic_vector(to_unsigned(105, 13));
else
end_addr_i := (Others => '0');
end if;
status_end_addr <= end_addr_i
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
status_send <= send_pending
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
send_pending <= mac_rx_last and not (pkt_drop_status or mac_rx_error)
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
end if;
end process;
good_packet_block: process (mac_clk)
begin
if rising_edge(mac_clk) then
status_we <= mac_rx_valid and not pkt_drop_status
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
end if;
end process;
-- UDP status packet:
-- Ethernet DST_MAC(6), SRC_MAC(6), Ether_Type = x"0800"
-- IP VERS = x"4", HL = x"5", TOS = x"00"
-- IP LEN
-- IP ID
-- IP FLAG-FRAG = x"4000"
-- IP TTL, PROTO = x"11"
-- IP CKSUM
-- IP SPA(4)
-- IP DPA(4)
-- UDP SRCPORT
-- UDP DSTPORT (50002)
-- UDP LEN
-- UDP CKSUM
-- UDP data...
address_block: process (mac_clk)
variable addr_to_set_int: unsigned(6 downto 0);
variable set_addr_int: std_logic;
begin
if rising_edge(mac_clk) then
if (rx_reset = '1') then
set_addr_int := '1';
addr_to_set_int := to_unsigned(6, 7);
elsif (mac_rx_valid = '1') and (pkt_drop_status = '0') then
-- Because address is buffered this logic needs to switch a byte early...
case to_integer(address) is
-- RX Ethernet Dest MAC bytes 0 to 5 => TX copy to Source MAC bytes 6 to 11...
when 10 =>
set_addr_int := '1';
addr_to_set_int := to_unsigned(0, 7);
-- RX Ethernet Source MAC bytes 6 to 11 => TX copy to Dest MAC bytes 0 to 5...
when 4 =>
set_addr_int := '1';
addr_to_set_int := to_unsigned(12, 7);
-- RX Eth_Type tho' to IP cksum bytes 12 to 25 => TX copy data bytes 12 to 25...
when 24 =>
set_addr_int := '1';
addr_to_set_int := to_unsigned(30, 7);
-- RX IP sender addr bytes 26 to 29 => TX copy to target addr bytes 30 to 33...
when 32 =>
set_addr_int := '1';
addr_to_set_int := to_unsigned(26, 7);
-- RX IP target addr bytes 30 to 33 => TX write sender addr bytes 26 to 29...
when 28 =>
set_addr_int := '1';
addr_to_set_int := to_unsigned(36, 7);
-- RX UDP source port bytes 34 to 35 => TX copy to dest port bytes 36 to 37...
when 36 =>
set_addr_int := '1';
addr_to_set_int := to_unsigned(34, 7);
-- RX UDP dest port bytes 36 to 37 => TX write source port bytes 34 to 35...
when 34 =>
set_addr_int := '1';
addr_to_set_int := to_unsigned(38, 7);
-- RX rest of packet => TX copy rest of packet...
when Others =>
addr_to_set_int := (Others => '0');
set_addr_int := '0';
end case;
else
addr_to_set_int := (Others => '0');
set_addr_int := '0';
end if;
set_addr <= set_addr_int
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
addr_to_set <= addr_to_set_int
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
end if;
end process;
next_addr: process(mac_clk)
variable addr_int, next_addr, addr_to_set_buf: unsigned(6 downto 0);
variable set_addr_buf: std_logic;
begin
if rising_edge(mac_clk) then
if set_addr = '1' then
addr_to_set_buf := addr_to_set;
set_addr_buf := '1';
end if;
if rx_reset = '1' or mac_rx_valid = '1' then
if set_addr_buf = '1' then
addr_int := addr_to_set_buf;
set_addr_buf := '0';
elsif pkt_drop_status = '0' then
addr_int := next_addr;
end if;
end if;
address <= addr_int
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
next_addr := addr_int + 1;
end if;
end process;
load_data: process (mac_clk)
variable load_buf_int, next_load, send_buf_int, request_int: std_logic;
begin
if rising_edge(mac_clk) then
if rx_reset = '1' then
request_int := '0';
send_buf_int := '0';
next_load := '0';
elsif (mac_rx_valid = '1') and (pkt_drop_status = '0') then
load_buf_int := next_load;
-- Because address is buffered this logic needs to switch a byte early...
case to_integer(address) is
-- End of header, start sending (zeros for cksum)...
when 38 =>
request_int := '0';
send_buf_int := '1';
next_load := '0';
-- And prepare to load header buffer...
when 39 =>
request_int := '0';
next_load := '1';
-- request history buffer...
when 55 =>
request_int := '1';
next_load := '1';
-- request ipbus_in buffer...
when 71 =>
request_int := '1';
next_load := '1';
-- request ipbus_out buffer...
when 87 =>
request_int := '1';
next_load := '1';
when Others =>
request_int := '0';
next_load := '0';
end case;
else
request_int := '0';
load_buf_int := '0';
end if;
load_buf <= load_buf_int
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
send_buf <= send_buf_int
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
status_request <= request_int
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
end if;
end process;
write_data: process(mac_clk)
variable shift_buf: std_logic_vector(127 downto 0);
variable data_to_send: std_logic_vector(7 downto 0);
begin
if rising_edge(mac_clk) then
if load_buf = '1' then
shift_buf := status_block;
end if;
if mac_rx_valid = '1' and pkt_drop_status = '0' then
if send_buf = '1' then
data_to_send := shift_buf(127 downto 120);
else
data_to_send := mac_rx_data;
end if;
shift_buf := shift_buf(119 downto 0) & x"00";
else
data_to_send := (Others => '0');
end if;
status_data <= data_to_send
-- pragma translate_off
after 4 ns
-- pragma translate_on
;
end if;
end process;
end rtl;