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

Subversion Repositories loadbalancer

[/] [loadbalancer/] [trunk/] [ARP/] [arp_parser.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 atalla
--------------------------------------------------------
2
 
3
        LIBRARY IEEE;
4
        USE IEEE.STD_LOGIC_1164.ALL;
5
-------------------------------
6
 
7
        ENTITY  arp_parser IS
8
        GENERIC(DATA_WIDTH :INTEGER := 64;
9
                        CTRL_WIDTH :INTEGER := 8);
10
        PORT(
11
        SIGNAL in_data :IN   STD_LOGIC_VECTOR(63 DOWNTO 0);
12
        SIGNAL in_ctrl : IN   STD_LOGIC_VECTOR(7 DOWNTO 0);
13
    SIGNAL in_wr :IN STD_LOGIC;
14
 
15
        SIGNAL header : OUT STD_LOGIC_VECTOR(63 DOWNTO 0);
16
     --- ethr  header
17
    SIGNAL src_mac : OUT STD_LOGIC_VECTOR(47 DOWNTO 0); --ethernet source MAC
18
    -------ARP------------
19
        SIGNAL SHA :OUT STD_LOGIC_VECTOR(47 DOWNTO 0);--Sender hardware address (SHA)    Hardware (MAC) address of the sender.
20
        SIGNAL SPA :OUT STD_LOGIC_VECTOR(31 DOWNTO 0);--Sender protocol address (SPA)    Upper layer protocol address of the sender.
21
        SIGNAL THA : OUT STD_LOGIC_VECTOR(47 DOWNTO 0);--Hardware address of the intended receiver. This field is ignored in requests.
22
        SIGNAL TPA : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);-- Upper layer protocol address of the intended receiver. 
23
    --- Misc
24
    SIGNAL done :OUT STD_LOGIC;
25
    SIGNAL reset :IN STD_LOGIC;
26
    SIGNAL clk   :IN STD_LOGIC
27
        );
28
        END ENTITY;
29
 ------------------------------------------------------
30
        ARCHITECTURE behavior OF arp_parser IS
31
 
32
------------ one hot encoding state definition
33
 
34
        TYPE state_type is (READ_HEADER, READ_WORD_1, READ_WORD_2, READ_WORD_3, READ_WORD_4,READ_WORD_5, READ_WORD_6, WAIT_EOP);
35
        ATTRIBUTE enum_encoding: STRING;
36
        attribute enum_encoding of state_type : type is "onehot";
37
        SIGNAL state, state_NEXT : state_type;
38
------------end state machine definition
39
 
40
---------------internal signals
41
   --- ethr  header
42
        SIGNAL header_rdy :STD_LOGIC;
43
    SIGNAL src_mac_rdy_p1, src_mac_rdy_p2 :STD_LOGIC;
44
    -------ARP------------
45
        SIGNAL SHA_rdy_p1, SHA_rdy_p2 : STD_LOGIC;
46
        SIGNAL SPA_rdy : STD_LOGIC;
47
        SIGNAL THA_rdy :  STD_LOGIC;
48
        SIGNAL TPA_rdy_p1, TPA_rdy_p2 :  STD_LOGIC;
49
 
50
-------------------------------------------
51
        BEGIN
52
 
53
                PROCESS(reset,clk)
54
                BEGIN
55
                        IF (reset ='1') THEN
56
                                state <=READ_HEADER;
57
 
58
                        ELSIF clk'EVENT AND clk ='1' THEN
59
                                state<=state_next;
60
                        END IF;
61
                END PROCESS;
62
 
63
                PROCESS(state, in_wr, in_ctrl, in_data)
64
                BEGIN
65
                                         src_mac_rdy_p1                         <= '0';
66
                                         src_mac_rdy_p2                         <= '0';
67
                                         SHA_rdy_p1                                     <= '0';
68
                                         SHA_rdy_p2                                     <= '0';
69
                                         SPA_rdy                                        <= '0';
70
                                         THA_rdy                                        <= '0';
71
                                         TPA_rdy_p1                                     <= '0';
72
                                         TPA_rdy_p2                                     <= '0';
73
                                         header_rdy                                     <= '0';
74
 
75
                    state_next<=state;
76
                        CASE state IS
77
 
78
                        WHEN READ_HEADER =>
79
                                IF(in_wr = '1'  AND in_ctrl=X"FF" ) THEN -- check if ARP request
80
                                        header_rdy                                      <= '1';
81
                                        state_next                       <= READ_WORD_1;
82
                                END IF;
83
 
84
                        WHEN READ_WORD_1 =>
85
                                IF(in_wr='1') THEN
86
                                        src_mac_rdy_p1                           <= '1';
87
                                        state_next                       <= READ_WORD_2;
88
                                END IF;
89
 
90
                        WHEN READ_WORD_2 =>
91
 
92
                                IF(in_wr='1') THEN
93
                                        src_mac_rdy_p2                          <= '1';
94
                                                state_next                <= READ_WORD_3;
95
                                END IF;
96
 
97
                        WHEN READ_WORD_3 =>
98
 
99
                                IF(in_wr='1') THEN
100
                                         SHA_rdy_p1                                     <= '1';
101
                                        state_next                <= READ_WORD_4;
102
                                END IF;
103
 
104
                        WHEN READ_WORD_4 =>
105
 
106
                                IF(in_wr='1') THEN
107
                                        SHA_rdy_p2                                      <= '1';
108
                                        SPA_rdy                                         <= '1';
109
                                        state_next                        <= READ_WORD_5;
110
                                END IF;
111
 
112
                        WHEN READ_WORD_5 =>
113
 
114
                                IF(in_wr='1') THEN
115
                                        THA_rdy                                         <= '1';
116
                                        TPA_rdy_p1                                      <= '1';
117
                                        state_next                       <= READ_WORD_6;
118
                                END IF;
119
 
120
                        WHEN READ_WORD_6 =>
121
 
122
                                IF(in_wr='1') THEN
123
                                        TPA_rdy_p2                                      <= '1';
124
                                        state_next                       <= WAIT_EOP;
125
                                END IF;
126
 
127
                        WHEN WAIT_EOP =>
128
                                IF (in_wr ='1'  AND in_ctrl /= X"00") THEN
129
                                                state_next              <= READ_HEADER;
130
                                        END IF;
131
 
132
                        WHEN OTHERS =>
133
                        END CASE;
134
                END PROCESS;
135
----------------------------------
136
 
137
----------------------------------
138
                PROCESS(reset, clk)
139
                BEGIN
140
                IF (reset ='1') THEN
141
 
142
                        src_mac<=(others=>'0');
143
                        -------ARP------------
144
                        SHA<=(others=>'0');
145
                        SPA<=(others=>'0');
146
                        THA<=(others=>'0');
147
                        TPA<=(others=>'0');
148
                        done <='0';
149
                ELSIF clk'EVENT AND clk ='1' THEN
150
                        IF header_rdy ='1' THEN
151
                                header<=in_data(63 DOWNTO 0);
152
                        END IF;
153
 
154
                        IF src_mac_rdy_p1 ='1' THEN
155
                           src_mac(47 DOWNTO 32)   <= in_data(15 DOWNTO 0);
156
                        END IF;
157
                        IF src_mac_rdy_p2 ='1' THEN
158
                           src_mac (31 DOWNTO 0)   <= in_data(63 DOWNTO 32);
159
                        END IF;
160
 
161
                        -------ARP------------
162
 
163
                        IF SHA_rdy_p1 = '1' THEN
164
                                SHA(47 DOWNTO 32)                 <= in_data(15 DOWNTO 0);
165
                        END IF;
166
                        IF SHA_rdy_p2  ='1' THEN
167
                                SHA(31 DOWNTO 0)           <= in_data(63 DOWNTO 32);
168
                        END IF;
169
                        IF SPA_rdy  ='1' THEN
170
                                SPA               <= in_data(31 DOWNTO 0);
171
                        END IF;
172
                        IF THA_rdy = '1' THEN
173
                                        THA                              <= in_data(63 DOWNTO 16);
174
                        END IF;
175
                        IF TPA_rdy_p1 = '1' THEN
176
                        TPA(31 DOWNTO 16)                <= in_data(15 DOWNTO 0);
177
                        END IF;
178
                        IF TPA_rdy_p2 = '1' THEN
179
                        TPA(15 DOWNTO 0)          <= in_data(63 DOWNTO 48);
180
 
181
                        END IF;
182
                        done <=TPA_rdy_p2;
183
                END IF;
184
                END PROCESS;
185
 
186
 
187
END behavior;
188
 

powered by: WebSVN 2.1.0

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