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

Subversion Repositories loadbalancer

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 atalla
---this file could be used to build ARP RESPONSE 
2
 
3
--------------------------------------------------------
4
 
5
        LIBRARY IEEE;
6
        USE IEEE.STD_LOGIC_1164.ALL;
7
        use ieee.numeric_std.all;
8
        use IEEE.STD_LOGIC_ARITH.ALL;
9
        use IEEE.STD_LOGIC_UNSIGNED.ALL;
10
        USE WORK.CONFIG.ALL;
11
-------------------------------
12
 
13
        ENTITY  arp_response IS
14
        GENERIC(DATA_WIDTH :INTEGER := 64;
15
                        CTRL_WIDTH :INTEGER := 8);
16
        PORT(
17
        SIGNAL out_data : OUT   STD_LOGIC_VECTOR(63 DOWNTO 0);
18
        SIGNAL out_ctrl : OUT  STD_LOGIC_VECTOR(7 DOWNTO 0);
19
    SIGNAL out_wr : OUT STD_LOGIC;
20
        SIGNAL header : IN STD_LOGIC_VECTOR(63 DOWNTO 0);
21
     --- ethr  header
22
    SIGNAL src_mac : IN STD_LOGIC_VECTOR(47 DOWNTO 0); --ethernet source MAC
23
        SIGNAL SHA :IN STD_LOGIC_VECTOR(47 DOWNTO 0);--Sender hardware address (SHA)    Hardware (MAC) address of the sender.
24
        SIGNAL SPA :IN STD_LOGIC_VECTOR(31 DOWNTO 0);--Sender protocol address (SPA)    Upper layer protocol address of the sender.
25
        SIGNAL THA : IN STD_LOGIC_VECTOR(47 DOWNTO 0);--Hardware address of the intended receiver. This field is ignored in requests.
26
        SIGNAL TPA : IN STD_LOGIC_VECTOR(31 DOWNTO 0);-- Upper layer protocol address of the intended receiver. 
27
    --- Misc
28
    SIGNAL rdy :IN STD_LOGIC;
29
    SIGNAL reset :IN STD_LOGIC;
30
    SIGNAL clk   :IN STD_LOGIC
31
        );
32
        END ENTITY;
33
 ------------------------------------------------------
34
        ARCHITECTURE behavior OF arp_response IS
35
 
36
------------ one hot encoding state definition  
37
        TYPE state_type is (IDLE, WRITE_HEADER, WRITE_WORD_1 , WRITE_WORD_2, WRITE_WORD_3,
38
                                                WRITE_WORD_4,WRITE_WORD_5, WRITE_WORD_6,WRITE_DUMP1,WRITE_DUMP2, WAIT_EOP);
39
        ATTRIBUTE enum_encoding: STRING;
40
        ATTRIBUTE enum_encoding OF state_type: TYPE IS "onehot";
41
        SIGNAL state, state_next: state_type;
42
------------end state machine definition
43
 
44
---------------internal signals
45
    SIGNAL              out_data_p                      :   STD_LOGIC_VECTOR(DATA_WIDTH-1 DOWNTO 0);
46
        SIGNAL          out_ctrl_p                      :   STD_LOGIC_VECTOR(CTRL_WIDTH-1 DOWNTO 0);
47
    SIGNAL              out_wr_p                        :       STD_LOGIC;
48
        SIGNAL          source_port                     :       STD_LOGIC_VECTOR(1 DOWNTO 0);--just four ports
49
        SIGNAL          dest_port                       :       STD_LOGIC_VECTOR(15 DOWNTO 0);--just four ports
50
 
51
-------------------------------------------
52
        BEGIN
53
           PROCESS(clk)
54
                BEGIN
55
 
56
                        IF RISING_EDGE( clk )THEN
57
                                        IF( rdy ='1' ) THEN
58
                                                IF header(31 DOWNTO 16)=X"0000" THEN
59
                                                                source_port <= "00";
60
                                                                dest_port <= X"0001";
61
                                                        ELSIF header(31 DOWNTO 16)=X"0002" THEN
62
                                                                source_port <= "01";
63
                                                                dest_port <= X"0004";
64
                                                        ELSIF header(31 DOWNTO 16)=X"0004" THEN
65
                                                                source_port <= "10";
66
                                                                dest_port <= X"0010";
67
                                                        ELSIF header(31 DOWNTO 16)=X"0006" THEN
68
                                                                source_port <= "11";
69
                                                                dest_port <= X"0040";
70
                                                END IF;
71
                                        END IF;
72
                        END IF;
73
                END PROCESS;
74
 
75
                PROCESS(reset,clk)
76
                BEGIN
77
                        IF (reset ='1') THEN
78
                                        state                                                           <=      IDLE;
79
                        ELSIF clk'EVENT AND clk ='1' THEN
80
                                        state                                                           <=      state_next;
81
                        END IF;
82
                END PROCESS;
83
                PROCESS(state, rdy)
84
                BEGIN
85
                                        state_next                                                      <=      state;
86
                        CASE state IS
87
                        WHEN IDLE =>
88
                                IF rdy ='1' THEN
89
                                        state_next                                      <=      WRITE_HEADER;
90
                                END IF;
91
                        WHEN WRITE_HEADER =>
92
                                        state_next                                      <=      WRITE_WORD_1;
93
                        WHEN WRITE_WORD_1 =>
94
                                        state_next                                      <=      WRITE_WORD_2;
95
                        WHEN WRITE_WORD_2 =>
96
                                        state_next                                      <=      WRITE_WORD_3;
97
                        WHEN WRITE_WORD_3 =>
98
                                        state_next                                      <=      WRITE_WORD_4;
99
                        WHEN WRITE_WORD_4 =>
100
                                        state_next                                              <=      WRITE_WORD_5;
101
                        WHEN WRITE_WORD_5 =>
102
                                        state_next                                              <=      WRITE_WORD_6;
103
                        WHEN WRITE_WORD_6 =>
104
                                        state_next                                              <=      WRITE_DUMP1;
105
                        WHEN WRITE_DUMP1 =>
106
                                        state_next                                              <=      WRITE_DUMP2;
107
                        WHEN WRITE_DUMP2 =>
108
                                        state_next                                              <=      WAIT_EOP;
109
                        WHEN WAIT_EOP =>
110
                                        state_next                                                      <=      IDLE;
111
                        WHEN OTHERS =>
112
                                        state_next                                                      <=      IDLE;
113
                        END CASE;
114
                END PROCESS;
115
                -------------------OUTPUT ASSIGNMENT
116
                with state select
117
                 out_data_p <= dest_port & X"0008" & header(31 DOWNTO 16)&X"0040" WHEN WRITE_HEADER,
118
                                           src_mac & mac_array(CONV_INTEGER(source_port))(47 downto 32) when WRITE_WORD_1,
119
                                           mac_array(CONV_INTEGER(source_port))(31 downto 0) & X"0806" & X"0001" when WRITE_WORD_2,
120
                                           X"0800" & X"06" & X"04" & X"0002" & mac_array(CONV_INTEGER(source_port))(47 downto 32) when WRITE_WORD_3,
121
                                           mac_array(CONV_INTEGER(source_port))(31 downto 0) & TPA WHEN WRITE_WORD_4,
122
                                           SHA & SPA(31 DOWNTO 16) WHEN WRITE_WORD_5,
123
                                           SPA(15 DOWNTO 0) & ( X"000000000000") WHEN WRITE_WORD_6,
124
                                           X"0000000000000000" WHEN WRITE_DUMP1,
125
                                           X"0000000000000000" WHEN WRITE_DUMP2,
126
                                           ( OTHERS=>'0') when others;
127
 
128
           with state select
129
                                 out_wr_p <= '1' when WRITE_HEADER|WRITE_WORD_1| WRITE_WORD_2| WRITE_WORD_3|WRITE_WORD_4| WRITE_WORD_5|WRITE_WORD_6| WRITE_DUMP1|WRITE_DUMP2,
130
                                                           '0' when others;
131
                with state select
132
                                 out_ctrl_p <= X"FF" when WRITE_HEADER,
133
                                                           X"00" WHEN WRITE_WORD_1| WRITE_WORD_2| WRITE_WORD_3|WRITE_WORD_4| WRITE_WORD_5|WRITE_WORD_6 | WRITE_DUMP1,
134
                                                           X"01" WHEN WRITE_DUMP2,
135
                                                           X"00" when others;
136
                PROCESS(reset, clk)
137
                BEGIN
138
                IF (reset ='1') THEN
139
                    out_data<=(others=>'0');
140
                        out_ctrl<=(others=>'0');
141
                        out_wr<='0';
142
 
143
                ELSIF clk'EVENT AND clk ='1' THEN
144
                        out_data<=out_data_p;
145
                        out_ctrl<=out_ctrl_p;
146
                        out_wr<=out_wr_p;
147
                END IF;
148
                END PROCESS;
149
 
150
 
151
END behavior;
152
 

powered by: WebSVN 2.1.0

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