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

powered by: WebSVN 2.1.0

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