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/] [UDP_RX.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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