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

Subversion Repositories udp_ip_stack

[/] [udp_ip_stack/] [trunk/] [rtl/] [vhdl/] [arp.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 pjf
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer:            Peter Fall
4
-- 
5
-- Create Date:    12:00:04 05/31/2011 
6
-- Design Name: 
7
-- Module Name:    arp - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description:
12
--              handle simple IP lookup in cache
13
--              request cache fill through ARP protocol if required
14
--              cache is simple 1 deep
15
--              Handle ARP protocol
16
--              Respond to ARP requests and replies
17
--              Ignore pkts that are not ARP
18
--              Ignore pkts that are not addressed to us
19
--
20
-- Dependencies: 
21
--
22
-- Revision: 
23
-- Revision 0.01 - File Created
24
-- Revision 0.02 - Added req for mac tx and wait for grant
25
-- Additional Comments: 
26
--
27
----------------------------------------------------------------------------------
28
library IEEE;
29
use IEEE.STD_LOGIC_1164.ALL;
30
use IEEE.NUMERIC_STD.ALL;
31
use work.arp_types.all;
32
 
33
entity arp is
34
    Port (
35
                        -- lookup request signals
36
                        arp_req_req                     : in arp_req_req_type;
37
                        arp_req_rslt            : out arp_req_rslt_type;
38
                        -- MAC layer RX signals
39
                        data_in_clk             : in  STD_LOGIC;
40
                        reset                           : in  STD_LOGIC;
41
                        data_in                                 : in  STD_LOGIC_VECTOR (7 downto 0);             -- ethernet frame (from dst mac addr through to last byte of frame)
42
                        data_in_valid           : in  STD_LOGIC;                                                                        -- indicates data_in valid on clock
43
                        data_in_last            : in  STD_LOGIC;                                                                        -- indicates last data in frame
44
                        -- MAC layer TX signals
45
                        mac_tx_req                      : out std_logic;                                                                        -- indicates that ip wants access to channel (stays up for as long as tx)
46
                        mac_tx_granted          : in std_logic;                                                                 -- indicates that access to channel has been granted            
47
                        data_out_clk            : in std_logic;
48
                        data_out_ready          : in std_logic;                                                                 -- indicates system ready to consume data
49
                        data_out_valid          : out std_logic;                                                                        -- indicates data out is valid
50
                        data_out_last           : out std_logic;                                                                        -- with data out valid indicates the last byte of a frame
51
                        data_out                                : out std_logic_vector (7 downto 0);             -- ethernet frame (from dst mac addr through to last byte of frame)
52
                        -- system signals
53
                        our_mac_address         : in STD_LOGIC_VECTOR (47 downto 0);
54
                        our_ip_address  : in STD_LOGIC_VECTOR (31 downto 0);
55
                        req_count                       : out STD_LOGIC_VECTOR(7 downto 0)                       -- count of arp pkts received
56
                        );
57
end arp;
58
 
59
architecture Behavioral of arp is
60
 
61
        type req_state_type is (IDLE,LOOKUP,REQUEST,WAIT_REPLY);
62
        type rx_state_type is (IDLE,PARSE,PROCESS_ARP,WAIT_END);
63
        type rx_event_type is (NO_EVENT,DATA);
64
        type count_mode_type is (RST,INCR,HOLD);
65
        type arp_oper_type is (NOP,REQUEST,REPLY);
66
        type set_clr_type is (SET, CLR, HOLD);
67
 
68
        type tx_state_type is (IDLE,WAIT_MAC,SEND);
69
 
70
 
71
        type arp_entry_type is record
72
                ip                              : std_logic_vector (31 downto 0);
73
                mac                             : std_logic_vector (47 downto 0);
74
                is_valid                        : std_logic;
75
                reply_required  : std_logic;
76
        end record;
77
 
78
        -- state variables
79
        signal req_state                        : req_state_type;
80
        signal req_ip_addr              : std_logic_vector (31 downto 0);                -- IP address to lookup
81
        signal mac_addr_found   : STD_LOGIC_VECTOR (47 downto 0);                -- mac address found
82
        signal mac_addr_valid_reg: std_logic;
83
        signal send_request_needed              : std_logic;
84
        signal tx_mac_chn_reqd  : std_logic;
85
 
86
        signal rx_state                         : rx_state_type;
87
        signal rx_count                         : unsigned (7 downto 0);
88
        signal arp_operation            : arp_oper_type;
89
        signal arp_req_count            : unsigned (7 downto 0);
90
        signal arp_entry                        : arp_entry_type;                               -- arp entry store
91
        signal new_arp_entry            : arp_entry_type;
92
        signal tx_state                 : tx_state_type;
93
        signal tx_count                         : unsigned (7 downto 0);
94
 
95
-- FIXME        - remove these debug state signals
96
        signal arp_err_data             : std_logic_vector (7 downto 0);
97
        signal set_err_data             : std_logic;
98
 
99
  attribute keep : string;
100
  attribute keep of arp_err_data             : signal is "true";
101
 
102
        -- requester control signals
103
        signal next_req_state   : req_state_type;
104
        signal set_req_state            : std_logic;
105
        signal set_req_ip                       : std_logic;
106
        signal set_mac_addr             : std_logic;
107
        signal set_mac_addr_invalid : std_logic;
108
        signal set_send_req             : std_logic;
109
        signal clear_send_req   : std_logic;
110
 
111
 
112
        -- rx control signals
113
        signal next_rx_state    : rx_state_type;
114
        signal set_rx_state             : std_logic;
115
        signal rx_event                         : rx_event_type;
116
        signal rx_count_mode    : count_mode_type;
117
        signal set_arp_oper             : std_logic;
118
        signal arp_oper_set_val : arp_oper_type;
119
        signal dataval                  : std_logic_vector (7 downto 0);
120
        signal set_arp_entry_request            : std_logic;
121
 
122
        signal set_mac5                         : std_logic;
123
        signal set_mac4                         : std_logic;
124
        signal set_mac3                         : std_logic;
125
        signal set_mac2                         : std_logic;
126
        signal set_mac1                         : std_logic;
127
        signal set_mac0                         : std_logic;
128
 
129
        signal set_ip3                  : std_logic;
130
        signal set_ip2                  : std_logic;
131
        signal set_ip1                  : std_logic;
132
        signal set_ip0                  : std_logic;
133
 
134
        -- tx control signals
135
        signal next_tx_state    : tx_state_type;
136
        signal set_tx_state             : std_logic;
137
        signal tx_count_mode            : count_mode_type;
138
        signal clear_reply_req  : std_logic;
139
        signal set_chn_reqd             : set_clr_type;
140
        signal kill_data_out_valid      : std_logic;
141
 
142
 
143
        -- function to determine whether the rx pkt is an arp pkt and whether we want to process it
144
        -- Returns 1 if we should discard
145
        -- The following will make us ignore the frame (all values hexadecimal):
146
        -- PDU type /= 0806
147
        -- Protocol Type /= 0800
148
        -- Hardware Type /= 1
149
        -- Hardware Length /= 6
150
        -- Protocol Length /= 4
151
        -- Operation /= 1 or 2
152
        -- Target IP /= our IP (i.er. message is not meant for us)
153
        --
154
        function not_our_arp(data : STD_LOGIC_VECTOR; count : unsigned; our_ip : std_logic_vector) return std_logic is
155
        begin
156
                if
157
                        (count = 12 and data /= x"08") or                                               -- PDU type 0806 : ARP
158
                        (count = 13 and data /= x"06") or
159
                        (count = 14 and data /= x"00") or                                               -- HW type 1 : eth
160
                        (count = 15 and data /= x"01") or
161
                        (count = 16 and data /= x"08") or                                               -- Protocol 0800 : IP
162
                        (count = 17 and data /= x"00") or
163
                        (count = 18 and data /= x"06") or                                               -- HW Length 6
164
                        (count = 19 and data /= x"04") or                                               -- protocol length 4
165
                        (count = 20 and data /= x"00") or                                               -- operation 1 or 2 (req or reply)
166
                        (count = 21 and data /= x"01" and data /= x"02") or
167
                        (count = 38 and data /= our_ip(31 downto 24)) or        -- target IP is ours
168
                        (count = 39 and data /= our_ip(23 downto 16)) or
169
                        (count = 40 and data /= our_ip(15 downto 8)) or
170
                        (count = 41 and data /= our_ip(7 downto 0))
171
                then
172
                        return '1';
173
                else
174
                        return '0';
175
                end if;
176
        end function not_our_arp;
177
 
178
begin
179
        req_combinatorial : process (
180
                -- input signals
181
                arp_req_req,
182
                -- state variables
183
                req_state, req_ip_addr, mac_addr_found, mac_addr_valid_reg, send_request_needed, arp_entry,
184
                -- control signals
185
                next_req_state, set_req_state, set_req_ip, set_mac_addr,set_mac_addr_invalid,set_send_req, clear_send_req)
186
        begin
187
                -- set output followers
188
                arp_req_rslt.got_err <= '0';     -- errors not returned in this version
189
                -- zero time response to lookup request if already in cache
190
                if arp_req_req.lookup_req = '1' and arp_req_req.ip = arp_entry.ip and arp_entry.is_valid = '1' then
191
                        arp_req_rslt.got_mac <= '1';
192
                        arp_req_rslt.mac <= arp_entry.mac;
193
                else
194
                        arp_req_rslt.got_mac <= mac_addr_valid_reg;
195
                        arp_req_rslt.mac <= mac_addr_found;
196
                end if;
197
 
198
                -- set signal defaults
199
                next_req_state <= IDLE;
200
                set_req_state <= '0';
201
                set_req_ip <= '0';
202
                set_mac_addr <= '0';
203
                set_mac_addr_invalid <= '0';
204
                set_send_req <= '0';
205
                clear_send_req <= '0';
206
 
207
                -- REQ FSM
208
                case req_state is
209
                        when IDLE =>
210
                                if arp_req_req.lookup_req = '1' then
211
                                        -- check if we already have the info in cache
212
                                        if arp_req_req.ip = arp_entry.ip and arp_entry.is_valid = '1' then
213
                                                -- already have this IP
214
                                                set_mac_addr <= '1';
215
                                        else
216
                                                next_req_state <= LOOKUP;
217
                                                set_req_state <= '1';
218
                                                set_req_ip <= '1';
219
                                                set_mac_addr_invalid <= '1';
220
                                        end if;
221
                                end if;
222
 
223
                        when LOOKUP =>
224
                                if arp_entry.ip = req_ip_addr and arp_entry.is_valid = '1' then
225
                                        -- already have this IP
226
                                        next_req_state <= IDLE;
227
                                        set_req_state <= '1';
228
                                        set_mac_addr <= '1';
229
                                else
230
                                        -- need to request mac for this IP
231
                                        next_req_state <= REQUEST;
232
                                        set_req_state <= '1';
233
                                        set_send_req <= '1';
234
                                end if;
235
 
236
                        when REQUEST =>
237
                                        clear_send_req <= '1';
238
                                        next_req_state <= WAIT_REPLY;
239
                                        set_req_state <= '1';
240
 
241
                        when WAIT_REPLY =>
242
                                if arp_entry.is_valid = '1' then
243
                                        -- have reply, go back to LOOKUP state to see if it is the right one
244
                                        next_req_state <= LOOKUP;
245
                                        set_req_state <= '1';
246
                                end if;
247
                                -- TODO: add timeout here                               
248
 
249
                end case;
250
        end process;
251
 
252
        req_sequential : process (data_in_clk,reset)
253
        begin
254
                if rising_edge(data_in_clk) then
255
                        if reset = '1' then
256
                                -- reset state variables
257
                                req_state <= IDLE;
258
                                req_ip_addr <= (others => '0');
259
                                mac_addr_found <= (others => '0');
260
                                mac_addr_valid_reg <= '0';
261
                                send_request_needed <= '0';
262
                        else
263
                                -- Next req_state processing
264
                                if set_req_state = '1' then
265
                                        req_state <= next_req_state;
266
                                else
267
                                        req_state <= req_state;
268
                                end if;
269
 
270
                                -- Latch the requested IP address
271
                                if set_req_ip = '1' then
272
                                        req_ip_addr <= arp_req_req.ip;
273
                                else
274
                                        req_ip_addr <= req_ip_addr;
275
                                end if;
276
 
277
                                -- send request to TX&RX FSMs to send an ARP request
278
                                if set_send_req = '1' then
279
                                        send_request_needed <= '1';
280
                                elsif clear_send_req = '1' then
281
                                        send_request_needed <= '0';
282
                                else
283
                                        send_request_needed <= send_request_needed;
284
                                end if;
285
 
286
                                -- Set the found mac address
287
                                if set_mac_addr = '1' then
288
                                        mac_addr_found <= arp_entry.mac;
289
                                        mac_addr_valid_reg <= '1';
290
                                elsif set_mac_addr_invalid = '1' then
291
                                        mac_addr_found <= (others => '0');
292
                                        mac_addr_valid_reg <= '0';
293
                                else
294
                                        mac_addr_found <= mac_addr_found;
295
                                        mac_addr_valid_reg <= mac_addr_valid_reg;
296
                                end if;
297
 
298
                        end if;
299
                end if;
300
        end process;
301
 
302
 
303
        rx_combinatorial : process (
304
                -- input signals
305
                data_in, data_in_valid, data_in_last, our_ip_address,
306
                -- state variables
307
                rx_state, rx_count, arp_operation, arp_req_count, arp_err_data,
308
                -- control signals
309
                next_rx_state, set_rx_state, rx_event, rx_count_mode, set_arp_oper, arp_oper_set_val,
310
                dataval,set_mac5,set_mac4,set_mac3,set_mac2,set_mac1,set_mac0,set_ip3,set_ip2,set_ip1,set_ip0, set_err_data,
311
                set_arp_entry_request)
312
        begin
313
                -- set output followers
314
                req_count <= STD_LOGIC_VECTOR(arp_req_count);
315
 
316
                -- set signal defaults
317
                next_rx_state <= IDLE;
318
                set_rx_state <= '0';
319
                rx_event <= NO_EVENT;
320
                rx_count_mode <= HOLD;
321
                set_arp_oper <= '0';
322
                arp_oper_set_val <= NOP;
323
                dataval <= (others => '0');
324
                set_mac5 <= '0';
325
                set_mac4 <= '0';
326
                set_mac3 <= '0';
327
                set_mac2 <= '0';
328
                set_mac1 <= '0';
329
                set_mac0 <= '0';
330
                set_ip3 <= '0';
331
                set_ip2 <= '0';
332
                set_ip1 <= '0';
333
                set_ip0 <= '0';
334
                set_arp_entry_request <= '0';
335
                set_err_data <= '0';
336
 
337
                -- determine event (if any)
338
                if data_in_valid = '1' then
339
                        rx_event <= DATA;
340
                end if;
341
 
342
                -- RX FSM
343
                case rx_state is
344
                        when IDLE =>
345
                                rx_count_mode <= RST;
346
                                case rx_event is
347
                                        when NO_EVENT => -- (nothing to do)
348
                                        when DATA =>
349
                                                next_rx_state <= PARSE;
350
                                                set_rx_state <= '1';
351
                                                rx_count_mode <= INCR;
352
                                end case;
353
 
354
                        when PARSE =>
355
                                case rx_event is
356
                                        when NO_EVENT => -- (nothing to do)
357
                                        when DATA =>
358
                                                rx_count_mode <= INCR;
359
                                                -- handle early frame termination
360
                                                if data_in_last = '1' then
361
                                                        next_rx_state <= IDLE;
362
                                                        set_rx_state <= '1';
363
                                                else
364
                                                        -- check for end of frame. Also, detect and discard if not our frame
365
                                                        if rx_count = 42 then
366
                                                                next_rx_state <= PROCESS_ARP;
367
                                                                set_rx_state <= '1';
368
                                                        elsif not_our_arp(data_in,rx_count,our_ip_address) = '1' then
369
                                                                dataval <= data_in;
370
                                                                set_err_data <= '1';
371
                                                                next_rx_state <= WAIT_END;
372
                                                                set_rx_state <= '1';
373
                                                        elsif rx_count = 21 then
374
                                                                -- capture ARP operation
375
                                                                case data_in is
376
                                                                        when x"01" =>
377
                                                                                arp_oper_set_val <= REQUEST;
378
                                                                                set_arp_oper <= '1';
379
                                                                        when x"02" =>
380
                                                                                arp_oper_set_val <= REPLY;
381
                                                                                set_arp_oper <= '1';
382
                                                                        when others =>  -- ignore other values
383
                                                                end case;
384
                                                        -- capture source mac addr
385
                                                        elsif rx_count = 22 then
386
                                                                set_mac5 <= '1';
387
                                                                dataval <= data_in;
388
                                                        elsif rx_count = 23 then
389
                                                                set_mac4 <= '1';
390
                                                                dataval <= data_in;
391
                                                        elsif rx_count = 24 then
392
                                                                set_mac3 <= '1';
393
                                                                dataval <= data_in;
394
                                                        elsif rx_count = 25 then
395
                                                                set_mac2 <= '1';
396
                                                                dataval <= data_in;
397
                                                        elsif rx_count = 26 then
398
                                                                set_mac1 <= '1';
399
                                                                dataval <= data_in;
400
                                                        elsif rx_count = 27 then
401
                                                                set_mac0 <= '1';
402
                                                                dataval <= data_in;
403
                                                        -- capture source ip addr
404
                                                        elsif rx_count = 28 then
405
                                                                set_ip3 <= '1';
406
                                                                dataval <= data_in;
407
                                                        elsif rx_count = 29 then
408
                                                                set_ip2 <= '1';
409
                                                                dataval <= data_in;
410
                                                        elsif rx_count = 30 then
411
                                                                set_ip1 <= '1';
412
                                                                dataval <= data_in;
413
                                                        elsif rx_count = 31 then
414
                                                                set_ip0 <= '1';
415
                                                                dataval <= data_in;
416
                                                        end if;
417
                                                end if;
418
                                end case;
419
 
420
                        when PROCESS_ARP =>
421
                                next_rx_state <= WAIT_END;
422
                                set_rx_state <= '1';
423
                                case arp_operation is
424
                                        when NOP => -- (nothing to do)
425
                                        when REQUEST =>
426
                                                        set_arp_entry_request <= '1';
427
                                                        arp_oper_set_val <= NOP;
428
                                                        set_arp_oper <= '1';
429
                                        when REPLY =>
430
                                                        set_arp_entry_request <= '1';
431
                                                        arp_oper_set_val <= NOP;
432
                                                        set_arp_oper <= '1';
433
                                end case;
434
 
435
                        when WAIT_END =>
436
                                case rx_event is
437
                                        when NO_EVENT => -- (nothing to do)
438
                                        when DATA =>
439
                                                if data_in_last = '1' then
440
                                                        next_rx_state <= IDLE;
441
                                                        set_rx_state <= '1';
442
                                                end if;
443
                                end case;
444
 
445
                end case;
446
 
447
        end process;
448
 
449
        rx_sequential : process (data_in_clk)
450
        begin
451
                if rising_edge(data_in_clk) then
452
                        if reset = '1' then
453
                                -- reset state variables
454
                                rx_state <= IDLE;
455
                                rx_count <= x"00";
456
                                arp_operation <= NOP;
457
                                arp_req_count <= x"00";
458
                                -- reset arp entry store
459
                                arp_entry.ip <= x"00000000";
460
                                arp_entry.mac <= x"000000000000";
461
                                arp_entry.is_valid <= '0';
462
                                arp_entry.reply_required <= '0';
463
                                arp_err_data <= (others => '0');
464
                        else
465
                                -- Next rx_state processing
466
                                if set_rx_state = '1' then
467
                                        rx_state <= next_rx_state;
468
                                else
469
                                        rx_state <= rx_state;
470
                                end if;
471
 
472
                                -- rx_count processing
473
                                case rx_count_mode is
474
                                        when RST =>
475
                                                rx_count <= x"00";
476
                                        when INCR =>
477
                                                rx_count <= rx_count + 1;
478
                                        when HOLD =>
479
                                                rx_count <= rx_count;
480
                                end case;
481
 
482
                                -- err data
483
                                if set_err_data = '1' then
484
                                        arp_err_data <= data_in;
485
                                else
486
                                        arp_err_data <= arp_err_data;
487
                                end if;
488
 
489
                                -- arp operation processing
490
                                if set_arp_oper = '1' then
491
                                        arp_operation <= arp_oper_set_val;
492
                                else
493
                                        arp_operation <= arp_operation;
494
                                end if;
495
 
496
                                -- source mac capture
497
                                if (set_mac5 = '1') then new_arp_entry.mac(47 downto 40) <= dataval; end if;
498
                                if (set_mac4 = '1') then new_arp_entry.mac(39 downto 32) <= dataval; end if;
499
                                if (set_mac3 = '1') then new_arp_entry.mac(31 downto 24) <= dataval; end if;
500
                                if (set_mac2 = '1') then new_arp_entry.mac(23 downto 16) <= dataval; end if;
501
                                if (set_mac1 = '1') then new_arp_entry.mac(15 downto 8) <= dataval; end if;
502
                                if (set_mac0 = '1') then new_arp_entry.mac(7 downto 0) <= dataval; end if;
503
 
504
                                -- source ip capture
505
                                if (set_ip3 = '1') then new_arp_entry.ip(31 downto 24) <= dataval; end if;
506
                                if (set_ip2 = '1') then new_arp_entry.ip(23 downto 16) <= dataval; end if;
507
                                if (set_ip1 = '1') then new_arp_entry.ip(15 downto 8) <= dataval; end if;
508
                                if (set_ip0 = '1') then new_arp_entry.ip(7 downto 0) <= dataval; end if;
509
 
510
                                -- set arp entry request
511
                                if set_arp_entry_request = '1' then
512
                                        -- copy info from new entry to arp_entry and set reply required
513
                                        arp_entry.mac <= new_arp_entry.mac;
514
                                        arp_entry.ip <= new_arp_entry.ip;
515
                                        arp_entry.is_valid <= '1';
516
                                        if arp_operation = REQUEST then
517
                                                arp_entry.reply_required <= '1';
518
                                        else
519
                                                arp_entry.reply_required <= '0';
520
                                        end if;
521
                                        -- count another ARP pkt received
522
                                        arp_req_count <= arp_req_count + 1;
523
                                elsif clear_reply_req = '1' then
524
                                        -- note: clear_reply_req is set by tx logic, but handled in the clk domain of the rx
525
                                        -- maintain arp entry state, but reset the reply required flag
526
                                        arp_entry.mac <= arp_entry.mac;
527
                                        arp_entry.ip <= arp_entry.ip;
528
                                        arp_entry.is_valid <= arp_entry.is_valid;
529
                                        arp_entry.reply_required <= '0';
530
                                        arp_req_count <= arp_req_count;
531
                                elsif send_request_needed = '1' then
532
                                        -- set up the arp entry to take the request to be transmitted out by the TX FSM
533
                                        arp_entry.ip <= req_ip_addr;
534
                                        arp_entry.mac <= (others => '0');
535
                                        arp_entry.is_valid <= '0';
536
                                        arp_entry.reply_required <= '0';
537
                                else
538
                                        arp_entry <= arp_entry;
539
                                        arp_req_count <= arp_req_count;
540
                                end if;
541
 
542
                        end if;
543
                end if;
544
        end process;
545
 
546
        tx_combinatorial : process (
547
                -- input signals
548
                data_out_ready, send_request_needed, mac_tx_granted, our_mac_address, our_ip_address,
549
                -- state variables
550
                tx_state, tx_count, tx_mac_chn_reqd, arp_entry,
551
                -- control signals
552
                next_rx_state, set_rx_state, tx_count_mode, kill_data_out_valid,
553
                set_chn_reqd, clear_reply_req)
554
        begin
555
                -- set output followers
556
                mac_tx_req <= tx_mac_chn_reqd;
557
 
558
                case tx_state is
559
                        when SEND   =>
560
                                if data_out_ready = '1' and kill_data_out_valid = '0' then
561
                                        data_out_valid <= '1';
562
                                else
563
                                        data_out_valid <= '0';
564
                                end if;
565
                        when OTHERS =>  data_out_valid <= '0';
566
                end case;
567
 
568
                -- set signal defaults
569
                next_tx_state <= IDLE;
570
                set_tx_state <= '0';
571
                tx_count_mode <= HOLD;
572
                data_out <= x"00";
573
                data_out_last <= '0';
574
                clear_reply_req <= '0';
575
                set_chn_reqd <= HOLD;
576
                kill_data_out_valid <= '0';
577
 
578
                -- TX FSM
579
                case tx_state is
580
                        when IDLE =>
581
                                tx_count_mode <= RST;
582
                                if arp_entry.reply_required = '1' then
583
                                        set_chn_reqd <= SET;
584
                                        next_tx_state <= WAIT_MAC;
585
                                        set_tx_state <= '1';
586
                                elsif send_request_needed = '1' then
587
                                        set_chn_reqd <= SET;
588
                                        next_tx_state <= WAIT_MAC;
589
                                        set_tx_state <= '1';
590
                                else
591
                                        set_chn_reqd <= CLR;
592
                                end if;
593
 
594
                        when WAIT_MAC =>
595
                                tx_count_mode <= RST;
596
                                if mac_tx_granted = '1' then
597
                                        next_tx_state <= SEND;
598
                                        set_tx_state <= '1';
599
                                end if;
600
                                -- TODO - should handle timeout here
601
 
602
                        when SEND =>
603
                                if data_out_ready = '1' then
604
                                                tx_count_mode <= INCR;
605
                                end if;
606
                                case tx_count is
607
                                        when x"00"  => data_out <= x"ff";                                                               -- dst = broadcast
608
                                        when x"01"  => data_out <= x"ff";
609
                                        when x"02"  => data_out <= x"ff";
610
                                        when x"03"  => data_out <= x"ff";
611
                                        when x"04"  => data_out <= x"ff";
612
                                        when x"05"  => data_out <= x"ff";
613
                                        when x"06"  => data_out <= our_mac_address (47 downto 40);      -- src = our mac
614
                                        when x"07"  => data_out <= our_mac_address (39 downto 32);
615
                                        when x"08"  => data_out <= our_mac_address (31 downto 24);
616
                                        when x"09"  => data_out <= our_mac_address (23 downto 16);
617
                                        when x"0a"  => data_out <= our_mac_address (15 downto 8);
618
                                        when x"0b"  => data_out <= our_mac_address (7 downto 0);
619
                                        when x"0c"  => data_out <= x"08";                                                                       -- pkt type = 0806 : ARP
620
                                        when x"0d"  => data_out <= x"06";
621
                                        when x"0e"  => data_out <= x"00";                                                                       -- HW type = 0001 : eth
622
                                        when x"0f"  => data_out <= x"01";
623
                                        when x"10"  => data_out <= x"08";                                                                       -- protocol = 0800 : ip
624
                                        when x"11"  => data_out <= x"00";
625
                                        when x"12"  => data_out <= x"06";                                                                       -- HW size = 06
626
                                        when x"13"  => data_out <= x"04";                                                                       -- prot size = 04
627
 
628
                                        when x"14"  =>  data_out <= x"00";                                                                      -- opcode =             
629
                                        when x"15"  =>
630
                                                if arp_entry.is_valid = '1' then
631
                                                        data_out <= x"02";                                                                                                                                                      -- 02 : REPLY if arp_entry valid
632
                                                else
633
                                                        data_out <= x"01";                                                                                                                                                      -- 01 : REQ if arp_entry invalid
634
                                                end if;
635
 
636
                                        when x"16" => data_out <= our_mac_address (47 downto 40);       -- sender mac
637
                                        when x"17" => data_out <= our_mac_address (39 downto 32);
638
                                        when x"18" => data_out <= our_mac_address (31 downto 24);
639
                                        when x"19" => data_out <= our_mac_address (23 downto 16);
640
                                        when x"1a" => data_out <= our_mac_address (15 downto 8);
641
                                        when x"1b" => data_out <= our_mac_address (7 downto 0);
642
                                        when x"1c" => data_out <= our_ip_address (31 downto 24);        -- sender ip
643
                                        when x"1d" => data_out <= our_ip_address (23 downto 16);
644
                                        when x"1e" => data_out <= our_ip_address (15 downto 8);
645
                                        when x"1f" => data_out <= our_ip_address (7 downto 0);
646
                                        when x"20" => data_out <= arp_entry.mac (47 downto 40);         -- target mac
647
                                        when x"21" => data_out <= arp_entry.mac (39 downto 32);
648
                                        when x"22" => data_out <= arp_entry.mac (31 downto 24);
649
                                        when x"23" => data_out <= arp_entry.mac (23 downto 16);
650
                                        when x"24" => data_out <= arp_entry.mac (15 downto 8);
651
                                        when x"25" => data_out <= arp_entry.mac (7 downto 0);
652
                                        when x"26" => data_out <= arp_entry.ip  (31 downto 24);         -- target ip
653
                                        when x"27" => data_out <= arp_entry.ip   (23 downto 16);
654
                                        when x"28" => data_out <= arp_entry.ip   (15 downto 8);
655
 
656
                                        when x"29" =>
657
                                                data_out <= arp_entry.ip(7 downto 0);
658
                                                data_out_last <= '1';
659
 
660
                                        when x"2a" =>
661
                                                clear_reply_req <= '1';                 -- reset the reply request (done in the rx clk process domain)
662
                                                kill_data_out_valid <= '1';     -- data is no longer valid
663
                                                next_tx_state <= IDLE;
664
                                                set_tx_state <= '1';
665
 
666
                                        when others =>
667
                                                next_tx_state <= IDLE;
668
                                                set_tx_state <= '1';
669
                                end case;
670
                end case;
671
        end process;
672
 
673
        tx_sequential : process (data_out_clk,reset)
674
        begin
675
                if rising_edge(data_out_clk) then
676
                        if reset = '1' then
677
                                -- reset state variables
678
                                tx_state <= IDLE;
679
                                tx_mac_chn_reqd <= '0';
680
                        else
681
                                -- Next rx_state processing
682
                                if set_tx_state = '1' then
683
                                        tx_state <= next_tx_state;
684
                                else
685
                                        tx_state <= tx_state;
686
                                end if;
687
 
688
                                -- tx_count processing
689
                                case tx_count_mode is
690
                                        when RST =>
691
                                                tx_count <= x"00";
692
                                        when INCR =>
693
                                                tx_count <= tx_count + 1;
694
                                        when HOLD =>
695
                                                tx_count <= tx_count;
696
                                end case;
697
 
698
                                -- control access request to mac tx chn
699
                                case set_chn_reqd is
700
                                        when SET => tx_mac_chn_reqd <= '1';
701
                                        when CLR => tx_mac_chn_reqd <= '0';
702
                                        when HOLD => tx_mac_chn_reqd <= tx_mac_chn_reqd;
703
                                end case;
704
 
705
                        end if;
706
                end if;
707
        end process;
708
 
709
 
710
end Behavioral;
711
 

powered by: WebSVN 2.1.0

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