1 |
2 |
pjf |
----------------------------------------------------------------------------------
|
2 |
|
|
-- Company:
|
3 |
|
|
-- Engineer:
|
4 |
|
|
--
|
5 |
|
|
-- Create Date: 12:43:16 06/04/2011
|
6 |
|
|
-- Design Name:
|
7 |
|
|
-- Module Name: IP_complete_nomac - Behavioral
|
8 |
|
|
-- Project Name:
|
9 |
|
|
-- Target Devices:
|
10 |
|
|
-- Tool versions:
|
11 |
|
|
-- Description: Implements complete IP stack with ARP (but no MAC)
|
12 |
|
|
--
|
13 |
|
|
-- Dependencies:
|
14 |
|
|
--
|
15 |
|
|
-- Revision:
|
16 |
|
|
-- Revision 0.01 - File Created
|
17 |
|
|
-- Revision 0.02 - separated RX and TX clocks
|
18 |
|
|
-- Additional Comments:
|
19 |
|
|
--
|
20 |
|
|
----------------------------------------------------------------------------------
|
21 |
|
|
LIBRARY ieee;
|
22 |
|
|
USE ieee.std_logic_1164.ALL;
|
23 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
24 |
|
|
use work.axi.all;
|
25 |
|
|
use work.ipv4_types.all;
|
26 |
|
|
use work.arp_types.all;
|
27 |
|
|
|
28 |
|
|
entity IP_complete_nomac is
|
29 |
|
|
Port (
|
30 |
|
|
-- IP Layer signals
|
31 |
|
|
ip_tx_start : in std_logic;
|
32 |
|
|
ip_tx : in ipv4_tx_type; -- IP tx cxns
|
33 |
|
|
ip_tx_result : out std_logic_vector (1 downto 0); -- tx status (changes during transmission)
|
34 |
|
|
ip_tx_data_out_ready : out std_logic; -- indicates IP TX is ready to take data
|
35 |
|
|
ip_rx_start : out std_logic; -- indicates receipt of ip frame.
|
36 |
|
|
ip_rx : out ipv4_rx_type;
|
37 |
|
|
-- system signals
|
38 |
|
|
rx_clk : in STD_LOGIC;
|
39 |
|
|
tx_clk : in STD_LOGIC;
|
40 |
|
|
reset : in STD_LOGIC;
|
41 |
|
|
our_ip_address : in STD_LOGIC_VECTOR (31 downto 0);
|
42 |
|
|
our_mac_address : in std_logic_vector (47 downto 0);
|
43 |
|
|
-- status signals
|
44 |
|
|
arp_pkt_count : out STD_LOGIC_VECTOR(7 downto 0); -- count of arp pkts received
|
45 |
|
|
ip_pkt_count : out STD_LOGIC_VECTOR(7 downto 0); -- number of IP pkts received for us
|
46 |
|
|
-- MAC Transmitter
|
47 |
|
|
mac_tx_tdata : out std_logic_vector(7 downto 0); -- data byte to tx
|
48 |
|
|
mac_tx_tvalid : out std_logic; -- tdata is valid
|
49 |
|
|
mac_tx_tready : in std_logic; -- mac is ready to accept data
|
50 |
|
|
mac_tx_tlast : out std_logic; -- indicates last byte of frame
|
51 |
|
|
-- MAC Receiver
|
52 |
|
|
mac_rx_tdata : in std_logic_vector(7 downto 0); -- data byte received
|
53 |
|
|
mac_rx_tvalid : in std_logic; -- indicates tdata is valid
|
54 |
|
|
mac_rx_tready : out std_logic; -- tells mac that we are ready to take data
|
55 |
|
|
mac_rx_tlast : in std_logic -- indicates last byte of the trame
|
56 |
|
|
);
|
57 |
|
|
end IP_complete_nomac;
|
58 |
|
|
|
59 |
|
|
architecture structural of IP_complete_nomac is
|
60 |
|
|
|
61 |
|
|
COMPONENT IPv4
|
62 |
|
|
PORT(
|
63 |
|
|
-- IP Layer signals
|
64 |
|
|
ip_tx_start : in std_logic;
|
65 |
|
|
ip_tx : in ipv4_tx_type; -- IP tx cxns
|
66 |
|
|
ip_tx_result : out std_logic_vector (1 downto 0); -- tx status (changes during transmission)
|
67 |
|
|
ip_tx_data_out_ready : out std_logic; -- indicates IP TX is ready to take data
|
68 |
|
|
ip_rx_start : out std_logic; -- indicates receipt of ip frame.
|
69 |
|
|
ip_rx : out ipv4_rx_type;
|
70 |
|
|
-- system control signals
|
71 |
|
|
rx_clk : in STD_LOGIC;
|
72 |
|
|
tx_clk : in STD_LOGIC;
|
73 |
|
|
reset : in STD_LOGIC;
|
74 |
|
|
our_ip_address : in STD_LOGIC_VECTOR (31 downto 0);
|
75 |
|
|
our_mac_address : in std_logic_vector (47 downto 0);
|
76 |
|
|
-- system status signals
|
77 |
|
|
rx_pkt_count : out STD_LOGIC_VECTOR(7 downto 0); -- number of IP pkts received for us
|
78 |
|
|
-- ARP lookup signals
|
79 |
|
|
arp_req_req : out arp_req_req_type;
|
80 |
|
|
arp_req_rslt : in arp_req_rslt_type;
|
81 |
|
|
-- MAC layer RX signals
|
82 |
|
|
mac_data_in : in STD_LOGIC_VECTOR (7 downto 0); -- ethernet frame (from dst mac addr through to last byte of frame)
|
83 |
|
|
mac_data_in_valid : in STD_LOGIC; -- indicates data_in valid on clock
|
84 |
|
|
mac_data_in_last : in STD_LOGIC; -- indicates last data in frame
|
85 |
|
|
-- MAC layer TX signals
|
86 |
|
|
mac_tx_req : out std_logic; -- indicates that ip wants access to channel (stays up for as long as tx)
|
87 |
|
|
mac_tx_granted : in std_logic; -- indicates that access to channel has been granted
|
88 |
|
|
mac_data_out_ready : in std_logic; -- indicates system ready to consume data
|
89 |
|
|
mac_data_out_valid : out std_logic; -- indicates data out is valid
|
90 |
|
|
mac_data_out_last : out std_logic; -- with data out valid indicates the last byte of a frame
|
91 |
|
|
mac_data_out : out std_logic_vector (7 downto 0) -- ethernet frame (from dst mac addr through to last byte of frame)
|
92 |
|
|
);
|
93 |
|
|
END COMPONENT;
|
94 |
|
|
|
95 |
|
|
COMPONENT arp
|
96 |
|
|
PORT(
|
97 |
|
|
-- lookup request signals
|
98 |
|
|
arp_req_req : in arp_req_req_type;
|
99 |
|
|
arp_req_rslt : out arp_req_rslt_type;
|
100 |
|
|
-- MAC layer RX signals
|
101 |
|
|
data_in_clk : in STD_LOGIC;
|
102 |
|
|
reset : in STD_LOGIC;
|
103 |
|
|
data_in : in STD_LOGIC_VECTOR (7 downto 0); -- ethernet frame (from dst mac addr through to last byte of frame)
|
104 |
|
|
data_in_valid : in STD_LOGIC; -- indicates data_in valid on clock
|
105 |
|
|
data_in_last : in STD_LOGIC; -- indicates last data in frame
|
106 |
|
|
-- MAC layer TX signals
|
107 |
|
|
mac_tx_req : out std_logic; -- indicates that ip wants access to channel (stays up for as long as tx)
|
108 |
|
|
mac_tx_granted : in std_logic; -- indicates that access to channel has been granted
|
109 |
|
|
data_out_clk : in std_logic;
|
110 |
|
|
data_out_ready : in std_logic; -- indicates system ready to consume data
|
111 |
|
|
data_out_valid : out std_logic; -- indicates data out is valid
|
112 |
|
|
data_out_last : out std_logic; -- with data out valid indicates the last byte of a frame
|
113 |
|
|
data_out : out std_logic_vector (7 downto 0); -- ethernet frame (from dst mac addr through to last byte of frame)
|
114 |
|
|
-- system signals
|
115 |
|
|
our_mac_address : in STD_LOGIC_VECTOR (47 downto 0);
|
116 |
|
|
our_ip_address : in STD_LOGIC_VECTOR (31 downto 0);
|
117 |
|
|
req_count : out STD_LOGIC_VECTOR(7 downto 0) -- count of arp pkts received
|
118 |
|
|
);
|
119 |
|
|
END COMPONENT;
|
120 |
|
|
|
121 |
|
|
COMPONENT tx_arbitrator
|
122 |
|
|
PORT(
|
123 |
|
|
clk : in std_logic;
|
124 |
|
|
reset : in std_logic;
|
125 |
|
|
|
126 |
|
|
req_1 : in std_logic;
|
127 |
|
|
grant_1 : out std_logic;
|
128 |
|
|
data_1 : in std_logic_vector(7 downto 0); -- data byte to tx
|
129 |
|
|
valid_1 : in std_logic; -- tdata is valid
|
130 |
|
|
last_1 : in std_logic; -- indicates last byte of frame
|
131 |
|
|
|
132 |
|
|
req_2 : in std_logic;
|
133 |
|
|
grant_2 : out std_logic;
|
134 |
|
|
data_2 : in std_logic_vector(7 downto 0); -- data byte to tx
|
135 |
|
|
valid_2 : in std_logic; -- tdata is valid
|
136 |
|
|
last_2 : in std_logic; -- indicates last byte of frame
|
137 |
|
|
|
138 |
|
|
data : out std_logic_vector(7 downto 0); -- data byte to tx
|
139 |
|
|
valid : out std_logic; -- tdata is valid
|
140 |
|
|
last : out std_logic -- indicates last byte of frame
|
141 |
|
|
);
|
142 |
|
|
END COMPONENT;
|
143 |
|
|
|
144 |
|
|
---------------------------
|
145 |
|
|
-- Signals
|
146 |
|
|
---------------------------
|
147 |
|
|
|
148 |
|
|
-- ARP REQUEST
|
149 |
|
|
signal arp_req_req_int : arp_req_req_type;
|
150 |
|
|
signal arp_req_rslt_int : arp_req_rslt_type;
|
151 |
|
|
-- MAC arbitration busses
|
152 |
|
|
signal ip_mac_req : std_logic;
|
153 |
|
|
signal ip_mac_grant : std_logic;
|
154 |
|
|
signal ip_mac_data_out : std_logic_vector (7 downto 0);
|
155 |
|
|
signal ip_mac_valid : std_logic;
|
156 |
|
|
signal ip_mac_last : std_logic;
|
157 |
|
|
signal arp_mac_req : std_logic;
|
158 |
|
|
signal arp_mac_grant : std_logic;
|
159 |
|
|
signal arp_mac_data_out : std_logic_vector (7 downto 0);
|
160 |
|
|
signal arp_mac_valid : std_logic;
|
161 |
|
|
signal arp_mac_last : std_logic;
|
162 |
|
|
-- MAC RX bus
|
163 |
|
|
signal mac_rx_tready_int : std_logic;
|
164 |
|
|
-- MAC TX bus
|
165 |
|
|
signal mac_tx_tdata_int : std_logic_vector (7 downto 0);
|
166 |
|
|
signal mac_tx_tvalid_int : std_logic;
|
167 |
|
|
signal mac_tx_tlast_int : std_logic;
|
168 |
|
|
-- control signals
|
169 |
|
|
signal mac_tx_granted_int : std_logic;
|
170 |
|
|
|
171 |
|
|
begin
|
172 |
|
|
|
173 |
|
|
mac_rx_tready_int <= '1'; -- enable the mac receiver
|
174 |
|
|
|
175 |
|
|
-- set followers
|
176 |
|
|
mac_tx_tdata <= mac_tx_tdata_int;
|
177 |
|
|
mac_tx_tvalid <= mac_tx_tvalid_int;
|
178 |
|
|
mac_tx_tlast <= mac_tx_tlast_int;
|
179 |
|
|
|
180 |
|
|
mac_rx_tready <= mac_rx_tready_int;
|
181 |
|
|
|
182 |
|
|
------------------------------------------------------------------------------
|
183 |
|
|
-- Instantiate the IP layer
|
184 |
|
|
------------------------------------------------------------------------------
|
185 |
|
|
|
186 |
|
|
IP_layer : IPv4 PORT MAP
|
187 |
|
|
(
|
188 |
|
|
ip_tx_start => ip_tx_start,
|
189 |
|
|
ip_tx => ip_tx,
|
190 |
|
|
ip_tx_result => ip_tx_result,
|
191 |
|
|
ip_tx_data_out_ready=> ip_tx_data_out_ready,
|
192 |
|
|
ip_rx_start => ip_rx_start,
|
193 |
|
|
ip_rx => ip_rx,
|
194 |
|
|
rx_clk => rx_clk,
|
195 |
|
|
tx_clk => tx_clk,
|
196 |
|
|
reset => reset,
|
197 |
|
|
our_ip_address => our_ip_address,
|
198 |
|
|
our_mac_address => our_mac_address,
|
199 |
|
|
rx_pkt_count => ip_pkt_count,
|
200 |
|
|
arp_req_req => arp_req_req_int,
|
201 |
|
|
arp_req_rslt => arp_req_rslt_int,
|
202 |
|
|
mac_tx_req => ip_mac_req,
|
203 |
|
|
mac_tx_granted => ip_mac_grant,
|
204 |
|
|
mac_data_out_ready => mac_tx_tready,
|
205 |
|
|
mac_data_out_valid => ip_mac_valid,
|
206 |
|
|
mac_data_out_last => ip_mac_last,
|
207 |
|
|
mac_data_out => ip_mac_data_out,
|
208 |
|
|
mac_data_in => mac_rx_tdata,
|
209 |
|
|
mac_data_in_valid => mac_rx_tvalid,
|
210 |
|
|
mac_data_in_last => mac_rx_tlast
|
211 |
|
|
);
|
212 |
|
|
|
213 |
|
|
------------------------------------------------------------------------------
|
214 |
|
|
-- Instantiate the ARP layer
|
215 |
|
|
------------------------------------------------------------------------------
|
216 |
|
|
arp_layer : arp
|
217 |
|
|
Port map(
|
218 |
|
|
-- request signals
|
219 |
|
|
arp_req_req => arp_req_req_int,
|
220 |
|
|
arp_req_rslt => arp_req_rslt_int,
|
221 |
|
|
-- rx signals
|
222 |
|
|
data_in_clk => rx_clk,
|
223 |
|
|
reset => reset,
|
224 |
|
|
data_in => mac_rx_tdata,
|
225 |
|
|
data_in_valid => mac_rx_tvalid,
|
226 |
|
|
data_in_last => mac_rx_tlast,
|
227 |
|
|
-- tx signals
|
228 |
|
|
mac_tx_req => arp_mac_req,
|
229 |
|
|
mac_tx_granted => arp_mac_grant,
|
230 |
|
|
data_out_clk => tx_clk,
|
231 |
|
|
data_out_ready => mac_tx_tready,
|
232 |
|
|
data_out_valid => arp_mac_valid,
|
233 |
|
|
data_out_last => arp_mac_last,
|
234 |
|
|
data_out => arp_mac_data_out,
|
235 |
|
|
-- system signals
|
236 |
|
|
our_mac_address => our_mac_address,
|
237 |
|
|
our_ip_address => our_ip_address,
|
238 |
|
|
req_count => arp_pkt_count
|
239 |
|
|
);
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
------------------------------------------------------------------------------
|
243 |
|
|
-- Instantiate the TX Arbitrator
|
244 |
|
|
------------------------------------------------------------------------------
|
245 |
|
|
mac_tx_arb : tx_arbitrator
|
246 |
|
|
Port map(
|
247 |
|
|
clk => tx_clk,
|
248 |
|
|
reset => reset,
|
249 |
|
|
|
250 |
|
|
req_1 => ip_mac_req,
|
251 |
|
|
grant_1 => ip_mac_grant,
|
252 |
|
|
data_1 => ip_mac_data_out,
|
253 |
|
|
valid_1 => ip_mac_valid,
|
254 |
|
|
last_1 => ip_mac_last,
|
255 |
|
|
|
256 |
|
|
req_2 => arp_mac_req,
|
257 |
|
|
grant_2 => arp_mac_grant,
|
258 |
|
|
data_2 => arp_mac_data_out,
|
259 |
|
|
valid_2 => arp_mac_valid,
|
260 |
|
|
last_2 => arp_mac_last,
|
261 |
|
|
|
262 |
|
|
data => mac_tx_tdata_int,
|
263 |
|
|
valid => mac_tx_tvalid_int,
|
264 |
|
|
last => mac_tx_tlast_int
|
265 |
|
|
);
|
266 |
|
|
|
267 |
|
|
end structural;
|
268 |
|
|
|