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

powered by: WebSVN 2.1.0

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