OpenCores
URL https://opencores.org/ocsvn/gigabit_udp_mac/gigabit_udp_mac/trunk

Subversion Repositories gigabit_udp_mac

[/] [gigabit_udp_mac/] [trunk/] [LAN/] [UDP_KED/] [ARP_RX.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 boa_a_m
--****************************************************************************************
2
library IEEE;
3
use IEEE.STD_LOGIC_1164.all;
4
use IEEE.NUMERIC_STD.all;
5
use IEEE.std_logic_unsigned.all;
6
 
7
library work;
8
use work.signal_Package.all;
9
 
10
entity ARP_RX is
11
generic (
12
                        g_TIME_OUT_LOOKUP_TABLE_ARP                     : std_logic_vector(31 downto 0):= x"9502F900" --20S                                                                                              
13
                        );
14
  port (
15
 
16
    -- system signals
17
    i_rx_clk             : in  std_logic;
18
    i_tx_clk             : in  std_logic;
19
    i_reset              : in  std_logic;
20
    i_our_ip_addr        : in  std_logic_vector (31 downto 0);
21
 
22
        -- MAC layer RX inputs
23
    i_mac_data_in        : in  std_logic_vector (7 downto 0);
24
    i_mac_data_in_valid  : in  std_logic;
25
    i_mac_data_in_last   : in  std_logic;
26
 
27
        -- Outputs to ARP 
28
        o_ip_addr0            : out std_logic_vector(31 downto 0);
29
        o_mac_addr0           : out std_logic_vector(47 downto 0);
30
        o_addr_valid0         : out std_logic;
31
        o_pc_reply            : out std_logic;
32
        o_pc_req              : out std_logic;
33
 
34
        -- Error Out
35
        o_arp_rx_err_out      : out std_logic_vector (3 downto 0)
36
    );
37
end ARP_RX;
38
 
39
architecture Behavioral of ARP_RX is
40
 
41
--=========================== ARP Lookup Table =========================================
42
component ARP_Lookup_table is
43
generic (
44
                        g_TIME_OUT_LOOKUP_TABLE_ARP                     : std_logic_vector(31 downto 0):= x"9502F900" --20S                                                                                              
45
                        );
46
port (
47
 
48
    -- system signals
49
    i_rx_clk              : in  std_logic;
50
    i_tx_clk              : in  std_logic;
51
    i_reset               : in  std_logic;
52
 
53
         -- Data in
54
         i_mac_addr_in         : in  std_logic_vector(47 downto 0);
55
         i_ip_addr_in          : in  std_logic_vector(31 downto 0);
56
         i_addr_valid_in       : in  std_logic;
57
 
58
         i_request_in          : in  std_logic;
59
         i_reqly_in            : in  std_logic;
60
         i_trans_data_in       : in  std_logic;
61
 
62
         -- Data out
63
         o_mac_addr_out        : out  std_logic_vector(47 downto 0);
64
         o_ip_addr_out         : out  std_logic_vector(31 downto 0);
65
         o_addr_valid_out      : out  std_logic;
66
 
67
         o_request_out         : out  std_logic;
68
         o_reply_out           : out  std_logic
69
 
70
         );
71
end component;
72
--======================================================================================
73
--================================= Constant ===========================================================
74
--Generate Block Conditional Constants
75
constant c_GENERATE_PING_MODULE             : boolean  := true;                                  --if Ping Block is not Used,Value is False
76
constant c_GENERATE_ARP_MODULE              : boolean  := true;                                  --if ARP  Block is not Used,Value is False
77
constant c_DEFAULT_DST_MAC_ADDR             : std_logic_vector (47 downto 0) := x"F46D04962225"; --if ARP Block is not Used,Copy PC MAC Address to This Value    
78
 
79
 
80
--Application Layer Data Length
81
constant c_PACKET_LENGTH                    : std_logic_vector (15 downto 0):= x"05c0";          --1472 (Maximum Application Layer Packet Length)
82
constant c_udp_tx_src_ip                    : std_logic_vector (31 downto 0):= x"C0A86403";      --192.168.100.3(FPGA IP Adress)
83
constant c_udp_tx_dst_ip                    : std_logic_vector (31 downto 0):= x"C0A86402";      --192.168.100.2(PC IP Address)
84
constant c_udp_tx_protocol                  : std_logic_vector (7 downto 0) := x"11";            --UDP Protocol
85
constant c_udp_tx_src_mac                   : std_logic_vector (47 downto 0):= x"112233445566";  --FPGA MAC Address
86
constant c_udp_tx_checksum                  : std_logic_vector (15 downto 0):= x"0000";          --UDP Checksum(Value For This Constant is not Importanat)
87
constant c_udp_tx_src_port                  : std_logic_vector (15 downto 0):= x"0401";          --UDP Src Port(Value For This Constant is not Importanat)
88
constant c_udp_tx_dst_port                  : std_logic_vector (15 downto 0):= x"0FF5";          --UDP Dst Port(Value For This Constant is not Importanat)
89
 
90
 
91
--ARP Constants
92
constant c_TIME_OUT_LOOKUP_TABLE_ARP        : std_logic_vector (31 downto 0) := x"9502F900";     --20S(Value/125MHz = 20 )       
93
constant c_TIME_OUT_WAIT_FOR_ARP_REPLY      : std_logic_vector (31 downto 0) := x"07735940";     --1S    (Value/125MHz = 1 )     
94
constant c_RE_SEND_ARP_REQUEST              : std_logic_vector (3 downto 0)  := x"A";            --10    
95
 
96
 
97
--IP Constants
98
constant c_IP_TTL                           : std_logic_vector (7 downto 0)  := x"80";           -- IP Packet Time to live
99
constant c_IP_BC_ADDR                       : std_logic_vector (31 downto 0) := x"ffffffff";     -- Broadcast IP  Address
100
constant c_MAC_BC_ADDR                      : std_logic_vector (47 downto 0) := x"ffffffffffff"; -- Broadcast MAC Address
101
--======================================================================================================
102
 
103
 
104
 
105
 
106
--============================= Top Signals ============================================================
107
 
108
--signal   s_udp_tx_data_len      : std_logic_vector (15 downto 0):= c_PACKET_LENGTH;  --1472 (Maximum Application Layer Packet Length)
109
--signal        s_udp_tx_start         : std_logic:='0';
110
--signal        s_udp_tx_ready         : std_logic;
111
--signal   s_udp_tx_din          : std_logic_vector (7 downto 0);
112
--
113
--signal        s_udp_rx_dout          : std_logic_vector(7 downto 0);
114
--signal        s_udp_rx_dout_rdy      : std_logic;
115
--signal        s_udp_rx_dout_last     : std_logic;
116
--      
117
--signal        s_udp_rx_src_ip        : std_logic_vector(31 downto 0);
118
--signal   s_udp_rx_src_port      : std_logic_vector(15 downto 0);
119
--signal   s_udp_rx_dst_port      : std_logic_vector(15 downto 0);
120
--signal   s_udp_rx_data_len      : std_logic_vector(15 downto 0);      
121
--signal        s_udp_rx_err_out_top          : std_logic_vector(3 downto 0);
122
--signal        s_udp_tx_err_out_top       : std_logic_vector(3 downto 0);
123
--signal        s_arp_rx_err_out_top   : std_logic_vector(3 downto 0);
124
--signal   s_ip_rx_dst_ip_top         : std_logic_vector(31 downto 0);
125
--signal   s_ip_rx_err_out_top        : std_logic_vector (3 downto 0);
126
--signal   s_ip_tx_err_out_top        : std_logic_vector (3 downto 0);
127
--
128
--
129
--signal   s_rx_clk_out           : std_logic;
130
--signal   s_buff_rx_clk_out      : std_logic;
131
--signal   s_tx_clk_out           : std_logic;
132
--signal   s_buff_tx_clk_out      : std_logic;
133
--signal   s_clk_125              : std_logic;
134
--signal   s_clk_100              : std_logic;
135
--signal   s_clk_m                : std_logic;
136
--
137
----chip scope
138
--signal   s_control              : std_logic_vector (35 downto 0);
139
--signal   s_data_log             : std_logic_vector (15 downto 0);
140
--
141
--
142
----for transmit data
143
--signal   s_data_test_val        : std_logic:='0';
144
--signal   s_data_test_last       : std_logic:='0';
145
--signal   s_data_test            : std_logic_vector (7 downto 0):=(others=>'0');
146
--signal   s_cnt2                 : std_logic_vector (15 downto 0):=(others=>'0');
147
--signal   s_global_reset         : std_logic:='1';
148
--
149
--
150
--
151
--signal   s_gmii_txd           : std_logic_vector(7 downto 0);
152
--signal   s_gmii_tx_en         : std_logic;
153
--signal   s_gmii_tx_er         : std_logic;
154
--======================================================================================================
155
 
156
 
157
 
158
 
159
 
160
 
161
--===================== Reset_gen Signals ==============================================================
162
signal   s_cnt_rst     : std_logic_vector(15 downto 0):=(others=>'0');
163
--======================================================================================================
164
 
165
 
166
 
167
 
168
 
169
 
170
--================================ Ethernet 1g Signals =================================================
171
signal   s_gtx_clk                :  std_logic;
172
signal   s_tx_clk                 :  std_logic;
173
signal   s_rx_clk                 :  std_logic;
174
signal   s_rstn                   :  std_logic;
175
signal   s_rx_reset             :  std_logic;
176
signal   s_tx_reset             :  std_logic;
177
 
178
 
179
--mac to gmii_if signals
180
signal   s_mac_gmii_rxd           :  std_logic_vector(7 downto 0);
181
signal   s_mac_gmii_rx_dv         :  std_logic;
182
signal   s_mac_gmii_rx_er         :  std_logic;
183
 
184
signal   s_mac_gmii_txd           :  std_logic_vector(7 downto 0);
185
signal   s_mac_gmii_tx_en         :  std_logic;
186
signal   s_mac_gmii_tx_er         :  std_logic;
187
 
188
 
189
 
190
--ip to mac signals
191
signal   s_mac_tx_tready        :  std_logic;
192
signal  s_mac_tx_tdata         :  std_logic_vector(7 downto 0);
193
signal   s_mac_tx_tvalid        :  std_logic;
194
signal   s_mac_tx_tlast         :  std_logic;
195
 
196
signal   s_mac_rx_tdata         :  std_logic_vector(7 downto 0);
197
signal   s_mac_rx_tvalid        :  std_logic;
198
signal   s_mac_rx_tlast         :  std_logic;
199
--======================================================================================================
200
 
201
 
202
 
203
 
204
 
205
 
206
 
207
 
208
 
209
 
210
--================================ UDP Signals =========================================================
211
    -------- for transfer Rx data from IP to UDP layer----------------
212
        signal s_ip_rx_dout           :  std_logic_vector(7 downto 0);
213
        signal s_ip_rx_dout_rdy       :  std_logic;
214
        signal s_ip_rx_dout_last      :  std_logic;
215
 
216
        -------- for transfer Rx status data from IP to UDP layer---------
217
        signal s_ip_rx_src_ip         :  std_logic_vector(31 downto 0);
218
    signal s_ip_rx_dst_ip         :  std_logic_vector(31 downto 0);
219
    signal s_ip_rx_data_len       :  std_logic_vector(15 downto 0);
220
    signal s_ip_rx_protocol       :  std_logic_vector(7 downto 0);
221
    signal s_ip_rx_broadcast      :  std_logic;
222
    signal s_ip_rx_err_out_udp        :  std_logic_vector (3 downto 0);
223
    signal s_ip_tx_err_out_udp        :  std_logic_vector (3 downto 0);
224
    signal s_arp_rx_err_out_udp       :  std_logic_vector (3 downto 0);
225
 
226
        -------- for transfer Tx data from UDP to IP layer---------------
227
        signal s_ip_tx_start          :  std_logic;
228
        signal s_ip_tx_rdy            :  std_logic;
229
        signal s_ip_tx_din                :  std_logic_vector(7 downto 0);
230
 
231
        -------- for transfer Tx header data from UDP to IP layer--------
232
        signal s_ip_tx_src_ip         :  std_logic_vector(31 downto 0);
233
        signal s_ip_tx_dst_ip         :  std_logic_vector(31 downto 0);
234
        signal s_ip_tx_src_mac        :  std_logic_vector(47 downto 0);
235
        signal s_ip_tx_data_len       :  std_logic_vector(15 downto 0);
236
        signal s_ip_tx_protocol       :  std_logic_vector(7 downto 0);
237
        -----------------------------------------------------------------
238
--======================================================================================================
239
 
240
 
241
 
242
 
243
 
244
 
245
 
246
 
247
 
248
 
249
--============================= IP Signals =============================================================
250
  signal s_ip_mac_tx_tvalid    : std_logic;
251
  signal s_ip_mac_tx_tlast     : std_logic;
252
  signal s_ip_mac_tx_tdata     : std_logic_vector(7 downto 0);
253
  signal s_ip_mac_tx_req       : std_logic;
254
  signal s_ip_mac_tx_granted   : std_logic;
255
 
256
  signal s_arp_mac_tx_tvalid   : std_logic;
257
  signal s_arp_mac_tx_tlast    : std_logic;
258
  signal s_arp_mac_tx_tdata    : std_logic_vector(7 downto 0);
259
  signal s_arp_mac_tx_req      : std_logic;
260
  signal s_arp_mac_tx_granted  : std_logic;
261
 
262
  signal s_ping_mac_tx_tvalid   : std_logic;
263
  signal s_ping_mac_tx_tlast    : std_logic;
264
  signal s_ping_mac_tx_tdata    : std_logic_vector(7 downto 0);
265
  signal s_ping_mac_tx_req      : std_logic;
266
  signal s_ping_mac_tx_granted  : std_logic;
267
 
268
  signal s_lookup_req          : std_logic;
269
  signal s_lookup_ip           : std_logic_vector(31 downto 0);
270
  signal s_lookup_mac_addr     : std_logic_vector(47 downto 0);
271
  signal s_lookup_mac_got      : std_logic;
272
  signal s_lookup_mac_err      : std_logic;
273
 
274
 
275
 
276
  signal s_no_ping_packet      : std_logic;
277
  signal s_ip_rx_err_out            : std_logic_vector(3 downto 0);
278
  --======================================================================================================
279
 
280
 
281
 
282
 
283
 
284
 
285
 
286
 
287
 
288
 
289
 
290
 
291
  --============================= IP4_TX Signals ==========================================================
292
  type t_tx_ip_state_type   is (IDLE,WAIT_MAC_ADDR,WAIT_CHN,SEND_DATA);
293
  type t_crc_state_type  is (IDLE, TOT_LEN, ID, FLAGS, TTL, CKS, SAH, SAL, DAH, DAL, ADDOVF, FINAL, WAIT_END);
294
  signal st_crc_state     : t_crc_state_type:=IDLE;
295
  signal s_tx_hdr_cks    : std_logic_vector (23 downto 0):=(others=>'0');
296
  signal s_cal_cheksum   : std_logic:='0';
297
 
298
 
299
  signal st_tx_ip_state      : t_tx_ip_state_type:=IDLE;
300
  signal s_cnt_ip_tx      : std_logic_vector (15 downto 0):=(others=>'0');
301
  signal s_dst_mac_addr  : std_logic_vector (47 downto 0); -- arp block updats this signal
302
  signal s_total_length  : std_logic_vector (15 downto 0); -- s_total_length is i_data_length+20(ip header) 
303
 
304
  signal s_ip_header     : std_logic_vector (7 downto 0):=(others=>'0');
305
  --========================================================================================================
306
 
307
 
308
 
309
 
310
 
311
 
312
 
313
 
314
 
315
 
316
  --============================ IP4_RX  Signals============================================================
317
  type t_rx_ip_state_type is (IDLE,ETH_H,IP_H,USER_DATA,WAIT_END);
318
  signal st_RX_IP_STATE         : t_rx_ip_state_type:=IDLE;
319
  signal s_cnt_ip_rx         : std_logic_vector (15 downto 0):=x"0001";
320
 
321
  signal s_src_ip_ip_rx         : std_logic_vector (31 downto 0):=(others=>'0');
322
  signal s_dst_ip_ip_rx         : std_logic_vector (31 downto 0):=(others=>'0');
323
  signal s_data_len_ip_rx       : std_logic_vector (15 downto 0):=(others=>'0');
324
  signal s_protocol_ip_rx       : std_logic_vector (7 downto 0) :=(others=>'0');
325
  signal s_broadcast_ip_rx      : std_logic;
326
  --========================================================================================================
327
 
328
 
329
 
330
 
331
 
332
 
333
 
334
 
335
 
336
 
337
 
338
--==================================== ARP Signals ==========================================================
339
type         t_arp_state_type is     (IDLE,LOOK_UP,WAIT_PC_REPLY);
340
signal       st_ARP_STATE             : t_arp_state_type:=IDLE;
341
signal       s_timeout_wait_reply_cnt           : std_logic_vector(31 downto 0):=(others=>'0');
342
signal       s_error_cnt             : std_logic_vector(3 downto 0):=(others=>'0');
343
 
344
--ARP_TX Signals
345
signal       s_dst_ip_addr_pc      : std_logic_vector(31 downto 0):=(others=>'0');
346
signal       s_dst_mac_addr_pc     : std_logic_vector(47 downto 0):=(others=>'0');
347
signal       s_dst_ip_addr_lookup  : std_logic_vector(31 downto 0):=(others=>'0');
348
signal       s_fpga_req_tx         : std_logic:='0';
349
signal       s_pc_req_tx           : std_logic:='0';
350
 
351
 
352
--ARP_RX Signals
353
signal       s_ip_addr0            : std_logic_vector(31 downto 0);
354
signal       s_mac_addr0           : std_logic_vector(47 downto 0);
355
signal       s_addr_valid0         : std_logic;
356
signal       s_pc_reply_rx         : std_logic;
357
signal       s_pc_req_rx           : std_logic;
358
--===========================================================================================================
359
 
360
 
361
 
362
 
363
 
364
 
365
 
366
 
367
 
368
 
369
 
370
--=============================== ARP RX Signals ============================================================
371
type t_rx_arp_state_type is       (IDLE,ETH_H,ARP_DATA,WAIT_END);
372
signal st_RX_ARP_STATE             : t_rx_arp_state_type:=IDLE;
373
signal s_cnt_arp_rx             : std_logic_vector (15 downto 0):=x"0001";
374
 
375
 
376
signal s_dst_ip            : std_logic_vector (31 downto 0):=(others=>'0');
377
signal s_operation         : std_logic_vector (15 downto 0):=(others=>'0');
378
signal s_addr_valid        : std_logic:='0';
379
signal s_pc_req            : std_logic:='0';
380
signal s_pc_reply          : std_logic:='0';
381
 
382
 
383
signal s_src_mac_arp_rx            : std_logic_vector (47 downto 0):=(others=>'0');
384
signal s_src_ip_arp_rx             : std_logic_vector (31 downto 0):=(others=>'0');
385
signal s_addr_valid_pulse   : std_logic:='0';
386
signal s_pc_req_pulse       : std_logic:='0';
387
signal s_pc_reply_pulse     : std_logic:='0';
388
signal s_trans_data_pulse   : std_logic:='0';
389
--===========================================================================================================
390
 
391
 
392
 
393
 
394
 
395
 
396
 
397
 
398
 
399
 
400
 
401
 
402
--=================================== ARP LOOKUP_TABLE Signals ==============================================
403
signal   s_timeout_lookup_table_cnt        : std_logic_vector(31 downto 0):=(others=>'0');
404
 
405
signal   s_din              : std_logic_vector(82 downto 0):=(others=>'0');
406
signal   s_wr_en            : std_logic;
407
signal   s_dout             : std_logic_vector(82 downto 0):=(others=>'0');
408
signal   s_valid            : std_logic;
409
signal   s_empty              : std_logic;
410
signal   s_notempty           : std_logic;
411
 
412
 
413
signal   s_mac_addr_out     : std_logic_vector(47 downto 0):=(others=>'0');
414
signal   s_ip_addr_out      : std_logic_vector(31 downto 0):=(others=>'0');
415
signal   s_addr_valid_out   : std_logic:='0';
416
signal   s_request_out      : std_logic:='0';
417
signal   s_reply_out        : std_logic:='0';
418
--============================================================================================================
419
 
420
 
421
 
422
 
423
 
424
 
425
 
426
 
427
 
428
 
429
 
430
--============================ ARP TX Signals ================================================================
431
type t_arp_tx_state_type   is (IDLE,WAIT_CHN,SEND_DATA);
432
signal st_tx_arp_state          : t_arp_tx_state_type:=IDLE;
433
signal s_cnt_arp_tx          : std_logic_vector (7 downto 0):=(others=>'0');
434
signal s_arp_type          : std_logic_vector (15 downto 0):=(others=>'0');
435
signal s_dst_ip_addr     : std_logic_vector (31 downto 0):=(others=>'0');
436
signal s_dst_mac_addr1   : std_logic_vector (47 downto 0):=(others=>'0');
437
signal s_dst_mac_addr2   : std_logic_vector (47 downto 0):=(others=>'0');
438
--============================================================================================================
439
 
440
 
441
 
442
 
443
 
444
 
445
 
446
 
447
 
448
 
449
 
450
 
451
--============================== PING Signals =================================================================
452
--for Delayed Inputs
453
signal   s_mac_data_in_r        : std_logic_vector (7 downto 0);
454
signal   s_mac_data_in_valid_r  : std_logic;
455
signal   s_mac_data_in_last_r   : std_logic;
456
 
457
 
458
--Sync_fifo_ping Signals
459
signal   s_ip_rx_in          : std_logic_vector(14 downto 0);
460
signal   s_ip_rx_out         : std_logic_vector(14 downto 0):=(others=>'0');
461
signal   s_mac_data_in          : std_logic_vector(7 downto 0);
462
signal   s_mac_data_in_valid  : std_logic;
463
signal   s_mac_data_in_last   : std_logic;
464
signal   s_mac_data_in_last_d : std_logic;
465
signal   s_ip_rx_err_in       : std_logic_vector(3 downto 0);
466
signal   s_no_ping_data     : std_logic;
467
signal   s_empty_sync_fifo    : std_logic:='0';
468
signal   s_not_empty_sync_fifo: std_logic;
469
 
470
 
471
--Data_fifo_ping Signals
472
signal   s_rst_fifo_ping     : std_logic:='1';
473
signal   s_wr_en_fifo_ping   : std_logic:='0';
474
signal   s_din_fifo_ping     : std_logic_vector(7 downto 0):=(others=>'0');
475
signal   s_rd_en_fifo_ping   : std_logic;
476
signal   s_dout_fifo_ping    : std_logic_vector(7 downto 0);
477
 
478
 
479
--Checksum Signals
480
signal   s_checksum_data_out   : std_logic_vector(15 downto 0);
481
signal   s_checksum_data_in    : std_logic_vector(7 downto 0);
482
signal   s_checksum_start_calc : std_logic:='0';
483
signal   s_checksum_stop_calc  : std_logic:='0';
484
 
485
 
486
--st_PING_STATE Machine Process Signals 
487
type     t_ping_state            is (IDLE,ACQUIRE_DATA,WAIT_END,WAIT_CHN,SEND_DATA);
488
signal   st_PING_STATE               : t_ping_state:=IDLE;
489
signal   s_wr_cnt              : std_logic_vector(7 downto 0):=(others=>'0');
490
signal   s_rd_cnt              : std_logic_vector(7 downto 0):=(others=>'0');
491
signal   s_start_send          : std_logic;
492
 
493
 
494
signal   s_src_mac_ping           : std_logic_vector(47 downto 0):=(others=>'0');
495
signal   s_dst_mac_ping           : std_logic_vector(47 downto 0):=(others=>'0');
496
signal   s_src_ip_ping            : std_logic_vector(31 downto 0):=(others=>'0');
497
signal   s_dst_ip_ping            : std_logic_vector(31 downto 0):=(others=>'0');
498
--=================================================================================================================
499
 
500
 
501
 
502
 
503
 
504
 
505
 
506
 
507
 
508
 
509
 
510
 
511
--================================= Ping Checksum Calc Signals ====================================================
512
type        t_checksum_state   is   (IDLE,CALC);
513
signal      st_checksum_state      : t_checksum_state:=IDLE;
514
 
515
signal      s_flag       : std_logic:='0';
516
signal      s_din_r      : std_logic_vector(7 downto 0);
517
signal      s_sum        : std_logic_vector(31 downto 0):=(others=>'0');
518
--=================================================================================================================
519
 
520
 
521
 
522
 
523
 
524
 
525
 
526
 
527
 
528
 
529
 
530
--============================ TX_Arbitior Signals =====================================================================
531
type   t_state_type is       (IDLE,DATA_REQ,ARP_REQ,PING_REQ);
532
signal st_STATE               : t_state_type:=IDLE;
533
--======================================================================================================================
534
 
535
 
536
 
537
 
538
 
539
 
540
 
541
 
542
 
543
 
544
 
545
 
546
--============================ UDP RX Signals ===========================================================================
547
  type t_rx_udp_state_type is  (IDLE, UDP_HDR, USER_DATA, WAIT_END);
548
  signal st_RX_UDP_STATE         : t_rx_udp_state_type:=IDLE;
549
  signal s_cnt_udp_rx         : std_logic_vector (15 downto 0):=x"0001";
550
 
551
  signal s_src_ip_udp_rx  : std_logic_vector (31 downto 0):=(others=>'0');
552
  signal s_src_port       : std_logic_vector (15 downto 0):=(others=>'0');
553
  signal s_dst_port       : std_logic_vector (15 downto 0):=(others=>'0');
554
  signal s_data_len_udp_rx       : std_logic_vector (15 downto 0):=(others=>'0');
555
  signal s_err_out        : std_logic_vector (3 downto 0) :=(others=>'0');
556
 --======================================================================================================================= 
557
 
558
 
559
 
560
 
561
 
562
 
563
 
564
 
565
 
566
 
567
 
568
 --============================ UDP TX Signals =============================================================================
569
  type t_tx_udp_state_type     is (IDLE,SEND_DATA);
570
  signal st_tx_udp_state        : t_tx_udp_state_type:=IDLE;
571
 
572
  signal s_cnt_udp_tx        : std_logic_vector (15 downto 0):=(others=>'0');
573
  signal s_ip_data_len   : std_logic_vector (15 downto 0);
574
  signal s_udp_header      : std_logic_vector (7 downto 0):=(others=>'0');
575
--==========================================================================================================================
576
 
577
 
578
 
579
 
580
 
581
 
582
 
583
 
584
 
585
 
586
 
587
--============================ PHY_Interface Signals =======================================================================
588
signal s_gmii_col_reg         : std_logic;
589
signal s_gmii_col_reg_reg     : std_logic;
590
signal s_gmii_rx_clk          : std_logic;
591
--==========================================================================================================================
592
 
593
 
594
 
595
 
596
 
597
 
598
 
599
 
600
 
601
 
602
 
603
--=========================== Ping_Pong Fifo Signals =======================================================================
604
signal s_empty1              : std_logic;
605
signal s_empty2              : std_logic;
606
signal s_notempty1           : std_logic;
607
signal s_notempty2           : std_logic;
608
 
609
 
610
signal s_data_m              : std_logic_vector(7 downto 0);
611
signal s_valid_m             : std_logic;
612
signal s_last_m              : std_logic;
613
 
614
 
615
signal s_wr_en_a             : std_logic:='0';
616
signal s_din_a               : std_logic_vector(7 downto 0):=(others=>'0');
617
signal s_rd_en_a             : std_logic;
618
signal s_dout_a              : std_logic_vector(7 downto 0);
619
signal s_valid_a             : std_logic;
620
signal s_empty_a             : std_logic;
621
 
622
signal s_wr_en_b             : std_logic:='0';
623
signal s_din_b               : std_logic_vector(7 downto 0):=(others=>'0');
624
signal s_rd_en_b             : std_logic;
625
signal s_dout_b              : std_logic_vector(7 downto 0);
626
signal s_valid_b             : std_logic;
627
signal s_empty_b             : std_logic;
628
 
629
 
630
signal s_cnt_a               : std_logic_vector(15 downto 0):=(others=>'0');
631
signal s_cnt_b               : std_logic_vector(15 downto 0):=(others=>'0');
632
signal s_rd_cnt_a            : std_logic_vector(15 downto 0):=(others=>'0');
633
signal s_rd_cnt_b            : std_logic_vector(15 downto 0):=(others=>'0');
634
 
635
signal s_busy_a              : std_logic:='0';
636
signal s_busy_b              : std_logic:='0';
637
 
638
signal s_last_a              : std_logic:='0';
639
signal s_last_b              : std_logic:='0';
640
 
641
signal s_dout_len          : std_logic_vector(15 downto 0);
642
 
643
type        t_pingpong_state     is (wait_data,rd_fifo_a,rd_fifo_b);
644
signal      st_ping_pong_state          : t_pingpong_state:=wait_data;
645
--========================================================================================================================= 
646
 
647
begin
648
 
649
--================================= Recieve ARP Data from Mac Layer ===================
650
p_recieve_arp_data:process(i_rx_clk)
651
begin
652
if(rising_edge(i_rx_clk)) then
653
if (i_reset='1') then
654
    st_RX_ARP_STATE           <= IDLE;
655
         s_cnt_arp_rx                   <= x"0001";
656
 
657
    -- to Lookup
658
         s_src_mac_arp_rx          <= (others => '0');
659
    s_src_ip_arp_rx           <= (others => '0');
660
         s_addr_valid_pulse                     <= '0';
661
         s_pc_req_pulse                         <= '0';
662
         s_pc_reply_pulse                       <= '0';
663
         s_trans_data_pulse                     <= '0';
664
 
665
         -- Internal Signals
666
         s_addr_valid                           <= '0';
667
         s_pc_req                               <= '0';
668
         s_pc_reply                             <= '0';
669
         s_dst_ip                               <= (others => '0');
670
         s_operation                            <= (others => '0');
671
 
672
        --error status
673
         o_arp_rx_err_out               <= (others => '0');
674
 
675
else
676
 
677
         s_addr_valid_pulse             <= '0';
678
         s_pc_req_pulse                 <= '0';
679
         s_pc_reply_pulse               <= '0';
680
         s_trans_data_pulse             <= '0';
681
 
682
        CASE st_RX_ARP_STATE IS
683
      --************************************************************************************************************************************
684
          WHEN IDLE =>
685
 
686
               s_cnt_arp_rx           <= x"0001";
687
                   --error status
688
                   o_arp_rx_err_out             <= (others => '0');
689
                   if ( i_mac_data_in_valid = '1') then
690
                            s_cnt_arp_rx                <= s_cnt_arp_rx+1;
691
                                 st_RX_ARP_STATE        <= ETH_H;
692
                   end if;
693
 
694
       --************************************************************************************************************************************
695
    WHEN ETH_H =>
696
               if ( i_mac_data_in_valid = '1') then
697
                        s_cnt_arp_rx            <= s_cnt_arp_rx+1;
698
                            ---------- Checking Frame Type ------------------------------
699
             if(s_cnt_arp_rx= 13) then
700
                if i_mac_data_in /= x"08" then
701
                   o_arp_rx_err_out     <= x"1";
702
                                       st_RX_ARP_STATE     <= WAIT_END;
703
                end if;
704
                            end if;
705
            if(s_cnt_arp_rx= 14) then
706
               st_RX_ARP_STATE                  <= ARP_DATA;
707
                                   if i_mac_data_in /= x"06" then
708
                                      o_arp_rx_err_out          <= x"1";
709
                                      st_RX_ARP_STATE      <= WAIT_END;
710
               end if;
711
                           end if;
712
                                ------------------------------------------------------
713
            if ( i_mac_data_in_last = '1') then
714
                 s_cnt_arp_rx           <= x"0001";
715
                                          --error status
716
                                          o_arp_rx_err_out              <= x"2";
717
                                     st_RX_ARP_STATE       <= IDLE;
718
            end if;
719
                            ------------------------------------------------------
720
         end if;
721
 
722
       --************************************************************************************************************************************
723
       WHEN ARP_DATA =>
724
 
725
                    if (i_mac_data_in_valid = '1') then
726
                       s_cnt_arp_rx                             <= s_cnt_arp_rx+1;
727
                                 ------------- Checking Hardware Type -----------------------------------------------------------------
728
                                 if(s_cnt_arp_rx= 15) then
729
                               if i_mac_data_in /= x"00" then
730
                   o_arp_rx_err_out     <= x"3";
731
                                            st_RX_ARP_STATE     <= WAIT_END;
732
                end if;
733
                            end if;
734
                                 if(s_cnt_arp_rx= 16) then
735
                               if i_mac_data_in /= x"01" then
736
                   o_arp_rx_err_out     <= x"3";
737
                                            st_RX_ARP_STATE     <= WAIT_END;
738
                end if;
739
                            end if;
740
 
741
                                ------------- Checking Protocol Type -----------------------------------------------------------------
742
                                 if(s_cnt_arp_rx= 17) then
743
                               if i_mac_data_in /= x"08" then
744
                   o_arp_rx_err_out     <= x"4";
745
                                            st_RX_ARP_STATE     <= WAIT_END;
746
                end if;
747
                            end if;
748
                                 if(s_cnt_arp_rx= 18) then
749
                               if i_mac_data_in /= x"00" then
750
                   o_arp_rx_err_out     <= x"4";
751
                                            st_RX_ARP_STATE     <= WAIT_END;
752
                end if;
753
                            end if;
754
                                ------------- Checking Address Length -----------------------------------------------------------------
755
                                if(s_cnt_arp_rx= 19) then
756
                               if i_mac_data_in /= x"06" then
757
                   o_arp_rx_err_out     <= x"5";
758
                                            st_RX_ARP_STATE     <= WAIT_END;
759
                end if;
760
                           end if;
761
                                if(s_cnt_arp_rx= 20) then
762
                               if i_mac_data_in /= x"04" then
763
                   o_arp_rx_err_out     <= x"5";
764
                                            st_RX_ARP_STATE     <= WAIT_END;
765
                end if;
766
                           end if;
767
 
768
                            ------------- Checking & Loading Operation ----------------------------------------------------------
769
           if(s_cnt_arp_rx=21) then
770
                                   s_operation (15 downto 8)    <= i_mac_data_in;
771
                          end if;
772
                          if(s_cnt_arp_rx=22) then
773
               s_operation (7 downto 0)  <= i_mac_data_in;
774
                                   s_pc_req                                             <= '0';
775
                                   s_pc_reply                                           <= '0';
776
 
777
                                        if ((s_operation (15 downto 8) & i_mac_data_in) = x"0001") then
778
                                            s_pc_req                            <= '1';
779
               elsif ((s_operation (15 downto 8) & i_mac_data_in) = x"0002") then
780
                                            s_pc_reply                          <= '1';
781
                                        else
782
                                       o_arp_rx_err_out <= x"6";
783
                                                 st_RX_ARP_STATE        <= WAIT_END;
784
                                   end if;
785
                          end if;
786
                           ------------- Loading Source MAC Address ----------------------------------------------------------------------
787
            if(s_cnt_arp_rx=23) then
788
                                   s_src_mac_arp_rx(47 downto 40)       <= i_mac_data_in;
789
                                end if;
790
            if(s_cnt_arp_rx=24) then
791
                                   s_src_mac_arp_rx(39 downto 32)       <= i_mac_data_in;
792
                                end if;
793
            if(s_cnt_arp_rx=25) then
794
                                   s_src_mac_arp_rx(31 downto 24)       <= i_mac_data_in;
795
                                end if;
796
            if(s_cnt_arp_rx=26) then
797
                                   s_src_mac_arp_rx(23 downto 16)       <= i_mac_data_in;
798
                                end if;
799
                                if(s_cnt_arp_rx=27) then
800
                                   s_src_mac_arp_rx(15 downto 8)        <= i_mac_data_in;
801
                                end if;
802
            if(s_cnt_arp_rx=28) then
803
                                   s_src_mac_arp_rx(7 downto 0)          <= i_mac_data_in;
804
                                end if;
805
            ------------- Loading Source IP Address ----------------------------------------------------------------------
806
            if(s_cnt_arp_rx=29) then
807
                                   s_src_ip_arp_rx(31 downto 24)        <= i_mac_data_in;
808
                                end if;
809
            if(s_cnt_arp_rx=30) then
810
                                   s_src_ip_arp_rx(23 downto 16)        <= i_mac_data_in;
811
                                end if;
812
            if(s_cnt_arp_rx=31) then
813
                                   s_src_ip_arp_rx(15 downto 8)         <= i_mac_data_in;
814
                                end if;
815
            if(s_cnt_arp_rx=32) then
816
                                   s_src_ip_arp_rx(7 downto 0)           <= i_mac_data_in;
817
                                   s_addr_valid                                         <= '1';
818
                                   if ((s_src_ip_arp_rx(31 downto 8) & i_mac_data_in) = c_IP_BC_ADDR) then
819
                                             s_addr_valid                               <= '0';
820
                                             o_arp_rx_err_out                           <= x"7";
821
                                             st_RX_ARP_STATE            <= WAIT_END;
822
                                        end if;
823
                                end if;
824
                                ------------- Loading Dst IP Address ----------------------------------------------------------------------
825
            if(s_cnt_arp_rx=39) then
826
                                   s_dst_ip(31 downto 24)                               <= i_mac_data_in;
827
                                end if;
828
            if(s_cnt_arp_rx=40) then
829
                                   s_dst_ip(23 downto 16)                               <= i_mac_data_in;
830
                                end if;
831
            if(s_cnt_arp_rx=41) then
832
                                   s_dst_ip(15 downto 8)                                <= i_mac_data_in;
833
                                end if;
834
            if(s_cnt_arp_rx=42) then -- End of ARP Packet
835
                                   s_dst_ip(7 downto 0)                                  <= i_mac_data_in;
836
                                        st_RX_ARP_STATE                 <= WAIT_END;
837
                                        -- transmit to Lookup
838
                                        s_trans_data_pulse                              <= '1';
839
                                   s_addr_valid_pulse                                   <= s_addr_valid;
840
                                        if ((s_dst_ip(31 downto 8) & i_mac_data_in) = i_our_ip_addr) then
841
                                             s_pc_req_pulse                             <= s_pc_req;
842
                                             s_pc_reply_pulse                           <= s_pc_reply;
843
                                   end if;
844
 
845
                           end if;
846
 
847
                                ------------------------------------------------
848
                                if (i_mac_data_in_last = '1') then
849
                  s_cnt_arp_rx                                          <= x"0001";
850
                                                st_RX_ARP_STATE                                 <= IDLE;
851
                                                if (s_cnt_arp_rx < 42) then
852
                                               o_arp_rx_err_out                 <= x"2";
853
                  end if;
854
            end if;
855
                                ------------------------------------------------
856
 
857
                        end if;
858
 
859
          --=============================================                       
860
                WHEN WAIT_END =>
861
           if ( i_mac_data_in_valid = '1') then
862
              if ( i_mac_data_in_last = '1') then
863
                   s_cnt_arp_rx                                 <= x"0001";
864
                                       --error status
865
                                       o_arp_rx_err_out                         <= x"0";
866
                                  st_RX_ARP_STATE                       <= IDLE;
867
              end if;
868
                   end if;
869
 
870
                  END CASE;
871
          --=============================================
872
end if;
873
end if;
874
end process p_recieve_arp_data;
875
--================================================================================================
876
 
877
--===================== ARP_Lookup_table ==========================================================
878
inst_arp_lookup_table : ARP_Lookup_table
879
generic map(
880
                        g_TIME_OUT_LOOKUP_TABLE_ARP     =>      g_TIME_OUT_LOOKUP_TABLE_ARP
881
                        )
882
port map (
883
   -- system signals
884
    i_rx_clk              => i_rx_clk,
885
    i_tx_clk              => i_tx_clk,
886
    i_reset               => i_reset,
887
 
888
         -- Data in
889
         i_mac_addr_in         => s_src_mac_arp_rx,
890
         i_ip_addr_in          => s_src_ip_arp_rx,
891
         i_addr_valid_in       => s_addr_valid_pulse,
892
         i_request_in          => s_pc_req_pulse,
893
         i_reqly_in            => s_pc_reply_pulse,
894
         i_trans_data_in       => s_trans_data_pulse,
895
 
896
         -- Data out
897
         o_mac_addr_out        => o_mac_addr0,
898
         o_ip_addr_out         => o_ip_addr0,
899
         o_addr_valid_out      => o_addr_valid0,
900
 
901
         o_request_out         => o_pc_req,
902
         o_reply_out           => o_pc_reply
903
);
904
--================================================================================================
905
 
906
  end Behavioral;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.