otsdaq_prepmodernization  v2_05_02_indev
arp_reply.vhd
1 -------------------------------------------------------------------------------
2 --
3 -- Title : Arp Reply
4 -- Design : ethernet_controller
5 -- Author : Ryan Rivera
6 -- Company : FNAL
7 --
8 -------------------------------------------------------------------------------
9 --
10 -- File : d:\Projects\otsdaq\OtS Ethernet MAC firmware\ActiveHDL_proj\ethernet_controller\compile\arp_reply.vhd
11 -- Generated : 02/29/16 11:09:18
12 -- From : d:/Projects/otsdaq/OtS Ethernet MAC firmware/ActiveHDL_proj/ethernet_controller/src/arp_reply.asf
13 -- By : FSM2VHDL ver. 5.0.7.2
14 --
15 -------------------------------------------------------------------------------
16 --
17 -- Description :
18 --
19 -------------------------------------------------------------------------------
20 
21 library IEEE;
22 use IEEE.std_logic_1164.all;
23 use IEEE.std_logic_arith.all;
24 use IEEE.std_logic_unsigned.all;
25 
26 entity arp_reply is
27  port (
28  addrs: in STD_LOGIC_VECTOR (31 downto 0);
29  arp_announce: in STD_LOGIC;
30  clk: in STD_LOGIC;
31  four_bit_mode: in STD_LOGIC;
32  mac: in STD_LOGIC_VECTOR (47 downto 0);
33  reset: in STD_LOGIC;
34  tip: in STD_LOGIC_VECTOR (31 downto 0);
35  tmac: in STD_LOGIC_VECTOR (47 downto 0);
36  trigger: in STD_LOGIC;
37  udp_busy: in STD_LOGIC;
38  arp_busy: out STD_LOGIC;
39  crc_gen_en: out STD_LOGIC;
40  crc_gen_init: out STD_LOGIC;
41  crc_gen_rd: out STD_LOGIC;
42  dataout: out STD_LOGIC_VECTOR (7 downto 0);
43  tx_en: out STD_LOGIC;
44  tx_er: out STD_LOGIC);
45 end arp_reply;
46 
47 architecture arp_reply_arch of arp_reply is
48 
49 -- diagram signals declarations
50 signal announce_sig: STD_LOGIC;
51 signal clken: STD_LOGIC;
52 signal delay_count: INTEGER range 0 to 65535;
53 signal old_trig: STD_LOGIC;
54 signal trigger_sig: STD_LOGIC;
55 
56 -- SYMBOLIC ENCODED state machine: Sreg0
57 type Sreg0_type is (
58  idle, delay, ArpResponse_ARP_Payload_PType2, ArpResponse_ARP_Payload_HLen, ArpResponse_ARP_Payload_PLen, ArpResponse_ARP_Payload_SMac1,
59  ArpResponse_ARP_Payload_SMac2, ArpResponse_ARP_Payload_SMac3, ArpResponse_ARP_Payload_SMac4, ArpResponse_ARP_Payload_SMac5, ArpResponse_ARP_Payload_SMac6,
60  ArpResponse_ARP_Payload_Sip1, ArpResponse_ARP_Payload_Sip2, ArpResponse_ARP_Payload_Sip3, ArpResponse_ARP_Payload_Sip4, ArpResponse_ARP_Payload_TMac1,
61  ArpResponse_ARP_Payload_TMac2, ArpResponse_ARP_Payload_TMac3, ArpResponse_ARP_Payload_TMac4, ArpResponse_ARP_Payload_TMac5, ArpResponse_ARP_Payload_TMac6,
62  ArpResponse_ARP_Payload_Tip1, ArpResponse_ARP_Payload_Tip2, ArpResponse_ARP_Payload_Tip3, ArpResponse_Type_S1, ArpResponse_Type_S48,
63  ArpResponse_Dest_S22, ArpResponse_Dest_S11, ArpResponse_Dest_S12, ArpResponse_Dest_S13, ArpResponse_Dest_S14, ArpResponse_Dest_S15,
64  ArpResponse_ARP_Payload_HType1, ArpResponse_ARP_Payload_Tip4, ArpResponse_ARP_Payload_HType2, ArpResponse_ARP_Payload_PType1, ArpResponse_Src_S50,
65  ArpResponse_Src_S51, ArpResponse_Src_S52, ArpResponse_Src_S53, ArpResponse_Src_S54, ArpResponse_ARP_Payload_Op1, ArpResponse_Src_S55,
66  ArpResponse_ARP_Payload_Op2, delay1, CheckBusy, ArpResponse_Preamble_S57, ArpResponse_Preamble_S58, ArpResponse_CRC_crc1, ArpResponse_CRC_crc2,
67  ArpResponse_CRC_crc3, ArpResponse_CRC_crc4, ArpResponse_CRC_S59, PreCheckBusy, ArpResponse_ARP_Payload_Op3, ArpResponse_ARP_Payload_Op4,
68  ArpResponse_ARP_Payload_TMac7, ArpResponse_ARP_Payload_TMac8, ArpResponse_ARP_Payload_TMac9, ArpResponse_ARP_Payload_TMac10, ArpResponse_ARP_Payload_TMac11,
69  ArpResponse_ARP_Payload_TMac12, ArpResponse_ARP_Payload_Tip5, ArpResponse_ARP_Payload_Tip6, ArpResponse_ARP_Payload_Tip7, ArpResponse_ARP_Payload_Tip8
70 );
71 -- attribute ENUM_ENCODING of Sreg0_type: type is ... -- enum_encoding attribute is not supported for symbolic encoding
72 
73 signal Sreg0: Sreg0_type;
74 
75 begin
76 
77 -- concurrent signals assignments
78 
79 -- Diagram ACTION
80 -- Note: expect that trigger is a single clock width pulse
81 trigger_sig <= trigger;
82 four_bit_proc : process (clk) -- make trigger sig a single clock width pulse
83 begin
84  if rising_edge(clk) then
85  if (four_bit_mode = '1') then
86  clken <= not clken;
87  else
88  clken <= '1';
89  end if;
90  end if;
91 end process;
92 
93 ----------------------------------------------------------------------
94 -- Machine: Sreg0
95 ----------------------------------------------------------------------
96 Sreg0_machine: process (clk)
97 begin
98  if clk'event and clk = '1' then
99  if reset = '1' then
100  Sreg0 <= idle;
101  -- Set default values for outputs, signals and variables
102  -- ...
103  delay_count <= 20;
104  -- number of ticks after trigger to delay sending of packet
105 -- also used for loops within packet
106  arp_busy <= '0';
107  -- indicates to udp to not take over transmit line
108  dataout <= (others => '0');
109  tx_er <= '0';
110  tx_en <= '0';
111  crc_gen_en <= '0';
112  crc_gen_init <= '0';
113  crc_gen_rd <= '0';
114  announce_sig <= '0';
115  else
116  if clken = '1' then
117  -- Set default values for outputs, signals and variables
118  -- ...
119  case Sreg0 is
120  when idle =>
121  delay_count <= 20;
122  -- number of ticks after trigger to delay sending of packet
123  -- also used for loops within packet
124  arp_busy <= '0';
125  -- indicates to udp to not take over transmit line
126  dataout <= (others => '0');
127  tx_er <= '0';
128  tx_en <= '0';
129  crc_gen_en <= '0';
130  crc_gen_init <= '0';
131  crc_gen_rd <= '0';
132  announce_sig <= '0';
133  if trigger_sig = '1' then
134  Sreg0 <= PreCheckBusy;
135  arp_busy <= '1';
136  if (arp_announce = '1') then
137  announce_sig <= '1';
138  end if;
139  end if;
140  when delay =>
141  delay_count <= delay_count - 1;
142  if delay_count = 1 then
143  Sreg0 <= ArpResponse_Preamble_S57;
144  crc_gen_init <= '0';
145  dataout <= x"55";
146  tx_en <= '1';
147  delay_count <= 7;
148  end if;
149  when delay1 =>
150  delay_count <= delay_count - 1;
151  if delay_count = 1 then
152  Sreg0 <= idle;
153  end if;
154  when CheckBusy =>
155  if udp_busy = '0' then
156  Sreg0 <= delay;
157  crc_gen_init <= '1';
158  end if;
159  when PreCheckBusy =>
160  if udp_busy = '0' then
161  Sreg0 <= CheckBusy;
162  end if;
163  when ArpResponse_Dest_S22 =>
164  Sreg0 <= ArpResponse_Dest_S11;
165  if(announce_sig = '0') then
166  dataout <= tmac(39 downto 32);
167  else
168  dataout <= x"FF";
169  end if;
170  when ArpResponse_Dest_S11 =>
171  Sreg0 <= ArpResponse_Dest_S12;
172  if(announce_sig = '0') then
173  dataout <= tmac(31 downto 24);
174  else
175  dataout <= x"FF";
176  end if;
177  when ArpResponse_Dest_S12 =>
178  Sreg0 <= ArpResponse_Dest_S13;
179  if(announce_sig = '0') then
180  dataout <= tmac(23 downto 16);
181  else
182  dataout <= x"FF";
183  end if;
184  when ArpResponse_Dest_S13 =>
185  Sreg0 <= ArpResponse_Dest_S14;
186  if(announce_sig = '0') then
187  dataout <= tmac(15 downto 8);
188  else
189  dataout <= x"FF";
190  end if;
191  when ArpResponse_Dest_S14 =>
192  Sreg0 <= ArpResponse_Dest_S15;
193  if(announce_sig = '0') then
194  dataout <= tmac(7 downto 0);
195  else
196  dataout <= x"FF";
197  end if;
198  when ArpResponse_Dest_S15 =>
199  Sreg0 <= ArpResponse_Src_S51;
200  dataout <= mac(47 downto 40);
201  --x"00";
202  when ArpResponse_Src_S50 =>
203  Sreg0 <= ArpResponse_Src_S55;
204  dataout <= mac(31 downto 24);
205  --x"55";
206  when ArpResponse_Src_S51 =>
207  Sreg0 <= ArpResponse_Src_S50;
208  dataout <= mac(39 downto 32);
209  --x"80";
210  when ArpResponse_Src_S52 =>
211  Sreg0 <= ArpResponse_Type_S48;
212  dataout <= x"08";
213  when ArpResponse_Src_S53 =>
214  Sreg0 <= ArpResponse_Src_S52;
215  dataout <= mac(7 downto 0);
216  --addrs;
217  when ArpResponse_Src_S54 =>
218  Sreg0 <= ArpResponse_Src_S53;
219  dataout <= mac(15 downto 8);
220  --x"00";
221  when ArpResponse_Src_S55 =>
222  Sreg0 <= ArpResponse_Src_S54;
223  dataout <= mac(23 downto 16);
224  --x"EC";
225  when ArpResponse_Type_S1 =>
226  Sreg0 <= ArpResponse_ARP_Payload_HType1;
227  dataout <= x"00";
228  when ArpResponse_Type_S48 =>
229  Sreg0 <= ArpResponse_Type_S1;
230  dataout <= x"06";
231  when ArpResponse_ARP_Payload_PType2 =>
232  Sreg0 <= ArpResponse_ARP_Payload_HLen;
233  dataout <= x"06";
234  when ArpResponse_ARP_Payload_HLen =>
235  Sreg0 <= ArpResponse_ARP_Payload_PLen;
236  dataout <= x"04";
237  when ArpResponse_ARP_Payload_PLen =>
238  if announce_sig = '1' then
239  Sreg0 <= ArpResponse_ARP_Payload_Op3;
240  dataout <= x"00";
241  -- ARP reply
242  else
243  Sreg0 <= ArpResponse_ARP_Payload_Op1;
244  dataout <= x"00";
245  -- ARP reply
246  end if;
247  when ArpResponse_ARP_Payload_SMac1 =>
248  Sreg0 <= ArpResponse_ARP_Payload_SMac2;
249  dataout <= mac(39 downto 32);
250  --x"80";
251  when ArpResponse_ARP_Payload_SMac2 =>
252  Sreg0 <= ArpResponse_ARP_Payload_SMac3;
253  dataout <= mac(31 downto 24);
254  --x"55";
255  when ArpResponse_ARP_Payload_SMac3 =>
256  Sreg0 <= ArpResponse_ARP_Payload_SMac4;
257  dataout <= mac(23 downto 16);
258  --x"EC";
259  when ArpResponse_ARP_Payload_SMac4 =>
260  Sreg0 <= ArpResponse_ARP_Payload_SMac5;
261  dataout <= mac(15 downto 8);
262  --x"00";
263  when ArpResponse_ARP_Payload_SMac5 =>
264  Sreg0 <= ArpResponse_ARP_Payload_SMac6;
265  dataout <= mac(7 downto 0);
266  --addrs;
267  when ArpResponse_ARP_Payload_SMac6 =>
268  Sreg0 <= ArpResponse_ARP_Payload_Sip1;
269  dataout <= addrs(31 downto 24);
270  --x"C0";
271  when ArpResponse_ARP_Payload_Sip1 =>
272  Sreg0 <= ArpResponse_ARP_Payload_Sip2;
273  dataout <= addrs(23 downto 16);
274  --x"A8";
275  when ArpResponse_ARP_Payload_Sip2 =>
276  Sreg0 <= ArpResponse_ARP_Payload_Sip3;
277  dataout <= addrs(15 downto 8);
278  --x"85";
279  when ArpResponse_ARP_Payload_Sip3 =>
280  Sreg0 <= ArpResponse_ARP_Payload_Sip4;
281  dataout <= addrs(7 downto 0);
282  --addrs;
283  when ArpResponse_ARP_Payload_Sip4 =>
284  if announce_sig = '1' then
285  Sreg0 <= ArpResponse_ARP_Payload_TMac7;
286  dataout <= x"00";
287  else
288  Sreg0 <= ArpResponse_ARP_Payload_TMac1;
289  dataout <= tmac(47 downto 40);
290  end if;
291  when ArpResponse_ARP_Payload_TMac1 =>
292  Sreg0 <= ArpResponse_ARP_Payload_TMac2;
293  dataout <= tmac(39 downto 32);
294  when ArpResponse_ARP_Payload_TMac2 =>
295  Sreg0 <= ArpResponse_ARP_Payload_TMac3;
296  dataout <= tmac(31 downto 24);
297  when ArpResponse_ARP_Payload_TMac3 =>
298  Sreg0 <= ArpResponse_ARP_Payload_TMac4;
299  dataout <= tmac(23 downto 16);
300  when ArpResponse_ARP_Payload_TMac4 =>
301  Sreg0 <= ArpResponse_ARP_Payload_TMac5;
302  dataout <= tmac(15 downto 8);
303  when ArpResponse_ARP_Payload_TMac5 =>
304  Sreg0 <= ArpResponse_ARP_Payload_TMac6;
305  dataout <= tmac(7 downto 0);
306  when ArpResponse_ARP_Payload_TMac6 =>
307  Sreg0 <= ArpResponse_ARP_Payload_Tip1;
308  dataout <= tip(31 downto 24);
309  when ArpResponse_ARP_Payload_Tip1 =>
310  Sreg0 <= ArpResponse_ARP_Payload_Tip2;
311  dataout <= tip(23 downto 16);
312  when ArpResponse_ARP_Payload_Tip2 =>
313  Sreg0 <= ArpResponse_ARP_Payload_Tip3;
314  dataout <= tip(15 downto 8);
315  when ArpResponse_ARP_Payload_Tip3 =>
316  Sreg0 <= ArpResponse_ARP_Payload_Tip4;
317  dataout <= tip(7 downto 0);
318  when ArpResponse_ARP_Payload_HType1 =>
319  Sreg0 <= ArpResponse_ARP_Payload_HType2;
320  dataout <= x"01";
321  --ethernet
322  when ArpResponse_ARP_Payload_Tip4 =>
323  Sreg0 <= ArpResponse_CRC_S59;
324  dataout <= (others => '0');
325  -- crc may need buffered 0 input
326  delay_count <= 18;
327  when ArpResponse_ARP_Payload_HType2 =>
328  Sreg0 <= ArpResponse_ARP_Payload_PType1;
329  dataout <= x"08";
330  --IPv4
331  when ArpResponse_ARP_Payload_PType1 =>
332  Sreg0 <= ArpResponse_ARP_Payload_PType2;
333  dataout <= x"00";
334  when ArpResponse_ARP_Payload_Op1 =>
335  Sreg0 <= ArpResponse_ARP_Payload_Op2;
336  dataout <= x"02";
337  -- ARP reply
338  when ArpResponse_ARP_Payload_Op2 =>
339  Sreg0 <= ArpResponse_ARP_Payload_SMac1;
340  dataout <= mac(47 downto 40);
341  --x"00";
342  when ArpResponse_ARP_Payload_Op3 =>
343  Sreg0 <= ArpResponse_ARP_Payload_Op4;
344  dataout <= x"01";
345  -- ARP request
346  when ArpResponse_ARP_Payload_Op4 =>
347  Sreg0 <= ArpResponse_ARP_Payload_SMac1;
348  dataout <= mac(47 downto 40);
349  --x"00";
350  when ArpResponse_ARP_Payload_TMac7 =>
351  Sreg0 <= ArpResponse_ARP_Payload_TMac8;
352  dataout <= x"00";
353  when ArpResponse_ARP_Payload_TMac8 =>
354  Sreg0 <= ArpResponse_ARP_Payload_TMac9;
355  dataout <= x"00";
356  when ArpResponse_ARP_Payload_TMac9 =>
357  Sreg0 <= ArpResponse_ARP_Payload_TMac10;
358  dataout <= x"00";
359  when ArpResponse_ARP_Payload_TMac10 =>
360  Sreg0 <= ArpResponse_ARP_Payload_TMac11;
361  dataout <= x"00";
362  when ArpResponse_ARP_Payload_TMac11 =>
363  Sreg0 <= ArpResponse_ARP_Payload_TMac12;
364  dataout <= x"00";
365  when ArpResponse_ARP_Payload_TMac12 =>
366  Sreg0 <= ArpResponse_ARP_Payload_Tip5;
367  dataout <= addrs(31 downto 24);
368  --x"C0";
369  when ArpResponse_ARP_Payload_Tip5 =>
370  Sreg0 <= ArpResponse_ARP_Payload_Tip6;
371  dataout <= addrs(23 downto 16);
372  --x"A8";
373  when ArpResponse_ARP_Payload_Tip6 =>
374  Sreg0 <= ArpResponse_ARP_Payload_Tip7;
375  dataout <= addrs(15 downto 8);
376  --x"85";
377  when ArpResponse_ARP_Payload_Tip7 =>
378  Sreg0 <= ArpResponse_ARP_Payload_Tip8;
379  dataout <= addrs(7 downto 0);
380  --addrs;
381  when ArpResponse_ARP_Payload_Tip8 =>
382  Sreg0 <= ArpResponse_CRC_S59;
383  dataout <= (others => '0');
384  -- crc may need buffered 0 input
385  delay_count <= 18;
386  when ArpResponse_Preamble_S57 =>
387  delay_count <= delay_count - 1;
388  if delay_count = 1 then
389  Sreg0 <= ArpResponse_Preamble_S58;
390  dataout <= x"D5";
391  end if;
392  when ArpResponse_Preamble_S58 =>
393  Sreg0 <= ArpResponse_Dest_S22;
394  if(announce_sig = '0') then
395  dataout <= tmac(47 downto 40);
396  else
397  dataout <= x"FF";
398  end if;
399  crc_gen_en <= '1';
400  when ArpResponse_CRC_crc1 =>
401  Sreg0 <= ArpResponse_CRC_crc2;
402  when ArpResponse_CRC_crc2 =>
403  Sreg0 <= ArpResponse_CRC_crc3;
404  when ArpResponse_CRC_crc3 =>
405  Sreg0 <= ArpResponse_CRC_crc4;
406  when ArpResponse_CRC_crc4 =>
407  Sreg0 <= delay1;
408  crc_gen_rd <= '0';
409  tx_en <= '0';
410  delay_count <= 30;
411  -- number of ticks after sending packet to keep line dead from udp
412  when ArpResponse_CRC_S59 =>
413  delay_count <= delay_count - 1;
414  if delay_count = 1 then
415  Sreg0 <= ArpResponse_CRC_crc1;
416  crc_gen_rd <= '1';
417  crc_gen_en <= '0';
418  end if;
419 --vhdl_cover_off
420  when others =>
421  null;
422 --vhdl_cover_on
423  end case;
424  end if;
425  end if;
426  end if;
427 end process;
428 
429 end arp_reply_arch;