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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.interface/] [udp_ip/] [1.0/] [vhd/] [udp_ip.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : UDP/IP
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : udp_ip.vhd
6
-- Author     : Jussi Nieminen  <niemin95@galapagosinkeiju.cs.tut.fi>
7
-- Last update: 2010-08-18
8
-------------------------------------------------------------------------------
9
-- Description: Receives/transmits data from/to an application, inside a UDP/IP
10
--              packet. Also handles ARP requests.
11
-------------------------------------------------------------------------------
12
-- Revisions  :
13
-- Date        Version  Author  Description
14
-- 2009/09/03  1.0      niemin95        Created
15
-------------------------------------------------------------------------------
16
 
17
 
18
library ieee;
19
use ieee.std_logic_1164.all;
20
use work.udp_ip_pkg.all;
21
 
22
entity udp_ip is
23
 
24
  generic (
25
    disable_rx_g  : integer := 0;
26
    disable_arp_g : integer := 0);
27
 
28
  port (
29
    clk               : in  std_logic;
30
    rst_n             : in  std_logic;
31
    -- to/from application
32
    new_tx_in         : in  std_logic;
33
    tx_len_in         : in  std_logic_vector( tx_len_w_c-1 downto 0 );
34
    target_addr_in    : in  std_logic_vector( ip_addr_w_c-1 downto 0 );
35
    target_port_in    : in  std_logic_vector( port_w_c-1 downto 0 );
36
    source_port_in    : in  std_logic_vector( port_w_c-1 downto 0 );
37
    tx_data_in        : in  std_logic_vector( udp_data_width_c-1 downto 0 );
38
    tx_data_valid_in  : in  std_logic;
39
    tx_re_out         : out std_logic;
40
    new_rx_out        : out std_logic;
41
    rx_data_valid_out : out std_logic;
42
    rx_data_out       : out std_logic_vector( udp_data_width_c-1 downto 0 );
43
    rx_re_in          : in  std_logic;
44
    rx_erroneous_out  : out std_logic;
45
    source_addr_out   : out std_logic_vector( ip_addr_w_c-1 downto 0 );
46
    source_port_out   : out std_logic_vector( port_w_c-1 downto 0 );
47
    dest_port_out     : out std_logic_vector( port_w_c-1 downto 0 );
48
    rx_len_out        : out std_logic_vector( tx_len_w_c-1 downto 0 );
49
 
50
    -- Use this when disable_arp_g = 1
51
    no_arp_target_MAC_in     : in  std_logic_vector( MAC_addr_w_c-1 downto 0 ) := (others => '0');
52
 
53
    -- to/from ethernet controller
54
    tx_data_out       : out std_logic_vector( udp_data_width_c-1 downto 0 );
55
    tx_data_valid_out : out std_logic;
56
    tx_re_in          : in  std_logic;
57
    target_MAC_out    : out std_logic_vector( MAC_addr_w_c-1 downto 0 );
58
    new_tx_out        : out std_logic;
59
    tx_len_out        : out std_logic_vector( tx_len_w_c-1 downto 0 );
60
    tx_frame_type_out : out std_logic_vector( frame_type_w_c-1 downto 0 );
61
    rx_data_in        : in  std_logic_vector( udp_data_width_c-1 downto 0 );
62
    rx_data_valid_in  : in  std_logic;
63
    rx_re_out         : out std_logic;
64
    new_rx_in         : in  std_logic;
65
    rx_len_in         : in  std_logic_vector( tx_len_w_c-1 downto 0 );
66
    rx_frame_type_in  : in  std_logic_vector( frame_type_w_c-1 downto 0 );
67
    rx_erroneous_in   : in  std_logic;
68
    rx_error_out      : out std_logic   -- this means system error, not error
69
                                        -- in data caused by network etc.
70
    );
71
 
72
end udp_ip;
73
 
74
 
75
architecture rtl of udp_ip is
76
 
77
  signal gen_ARP_rep              : std_logic;
78
  signal gen_ARP_IP               : std_logic_vector( ip_addr_w_c-1 downto 0 );
79
  signal IP_arpsnd_arp            : std_logic_vector( ip_addr_w_c-1 downto 0 );
80
  signal MAC_arp_arpsnd           : std_logic_vector( MAC_addr_w_c-1 downto 0 );
81
  signal ARP_entry_valid          : std_logic;
82
  signal MAC_request_UDP_arpsnd   : std_logic;
83
  signal MAC_arpsnd_UDP           : std_logic_vector( MAC_addr_w_c-1 downto 0 );
84
  signal MAC_valid_arpsnd_UDP     : std_logic;
85
  signal IP_UDP_arpsnd            : std_logic_vector( ip_addr_w_c-1 downto 0 );
86
  signal sending_reply_arpsnd_arp : std_logic;
87
  signal rx_arp_done              : std_logic;
88
  signal arpsnd_tx_ready          : std_logic;
89
 
90
  -- to and from arpsnd
91
  signal tx_data_from_arp       : std_logic_vector( udp_data_width_c-1 downto 0 );
92
  signal tx_data_valid_from_arp : std_logic;
93
  signal tx_re_to_arp           : std_logic;
94
  signal tx_target_MAC_from_arp : std_logic_vector( MAC_addr_w_c-1 downto 0 );
95
  signal tx_len_from_arp        : std_logic_vector( tx_len_w_c-1 downto 0 );
96
  signal tx_frame_type_from_arp : std_logic_vector( frame_type_w_c-1 downto 0 );
97
  signal new_tx_from_arp        : std_logic;
98
  signal rx_data_to_arp       : std_logic_vector( udp_data_width_c-1 downto 0 );
99
  signal rx_data_valid_to_arp : std_logic;
100
  signal new_rx_to_arp        : std_logic;
101
  signal rx_re_from_arp       : std_logic;
102
 
103
  -- to and from udp block
104
  signal tx_data_from_udp       : std_logic_vector( udp_data_width_c-1 downto 0 );
105
  signal tx_data_valid_from_udp : std_logic;
106
  signal tx_re_to_udp           : std_logic;
107
  signal tx_target_MAC_from_udp : std_logic_vector( MAC_addr_w_c-1 downto 0 );
108
  signal tx_len_from_udp        : std_logic_vector( tx_len_w_c-1 downto 0 );
109
  signal tx_frame_type_from_udp : std_logic_vector( frame_type_w_c-1 downto 0 );
110
  signal new_tx_from_udp        : std_logic;
111
  signal rx_data_to_udp       : std_logic_vector( udp_data_width_c-1 downto 0 );
112
  signal rx_data_valid_to_udp : std_logic;
113
  signal new_rx_to_udp        : std_logic;
114
  signal rx_re_from_udp       : std_logic;
115
 
116
  -- mux select signals
117
  signal input_select  : std_logic_vector( 1 downto 0 );
118
  signal output_select : std_logic_vector( 1 downto 0 );
119
 
120
  -- mux signals
121
  signal tx_datas       : std_logic_vector( 3*udp_data_width_c-1 downto 0 );
122
  signal tx_data_valids : std_logic_vector( 2 downto 0 );
123
  signal tx_target_MACs : std_logic_vector( 2*MAC_addr_w_c-1 downto 0 );
124
  signal tx_lens        : std_logic_vector( 2*tx_len_w_c-1 downto 0 );
125
  signal tx_frame_types : std_logic_vector( 2*frame_type_w_c-1 downto 0 );
126
  signal new_txs        : std_logic_vector( 1 downto 0 );
127
  signal tx_res         : std_logic_vector( 2 downto 0 );
128
  signal rx_res         : std_logic_vector( 2 downto 0 );
129
  signal rx_datas       : std_logic_vector( 3*udp_data_width_c-1 downto 0 );
130
  signal rx_data_valids : std_logic_vector( 2 downto 0 );
131
  signal new_rxs        : std_logic_vector( 1 downto 0 );
132
 
133
  signal frame_valid : std_logic;
134
 
135
-------------------------------------------------------------------------------
136
begin  -- rtl
137
-------------------------------------------------------------------------------
138
 
139
 
140
  --                    | Eth ctrl |
141
  --                    ------------
142
  --                         ||
143
  --  ---------------------------------------------
144
  --  |UDP/IP                ||                   |
145
  --  |               ---------------             |
146
  --  |              /     MUX       \___         |
147
  --  |             /_________________\  |        |
148
  --  |              ||     ||     ||    |        |
149
  --  |       ----------    ||    -----------     |
150
  --  |       | ARPSND |----------|   UDP   |     |
151
  --  |       ----------    ||    -----------     |
152
  --  |         ||          ||       ||           |
153
  --  |      --------      data    addresses etc. |
154
  --  |      | ARP3 |        \\     //            |
155
  --  |      --------         \\   //             |
156
  --  |                        \\ //              |
157
  --  ---------------------------------------------
158
  --                           || ||
159
  --                      ---------------
160
  --                      | application |
161
 
162
 
163
 
164
  -----------------------------------------------------------------------------
165
  -- *** MUX SIGNALS ***
166
 
167
  -- forming the tx signals for the mux
168
  tx_datas       <= tx_data_in & tx_data_from_arp & tx_data_from_udp;
169
  tx_data_valids <= tx_data_valid_in & tx_data_valid_from_arp & tx_data_valid_from_udp;
170
  tx_target_MACs <= tx_target_MAC_from_arp & tx_target_MAC_from_udp;
171
  tx_lens        <= tx_len_from_arp & tx_len_from_udp;
172
  tx_frame_types <= tx_frame_type_from_arp & tx_frame_type_from_udp;
173
  new_txs        <= new_tx_from_arp & new_tx_from_udp;
174
 
175
  -- tx read enables from the mux
176
  tx_re_to_udp <= tx_res(0);
177
  tx_re_to_arp <= tx_res(1);
178
  tx_re_out    <= tx_res(2);
179
 
180
  -- rx signals
181
 
182
  rx_enabled: if disable_rx_g = 0 generate
183
 
184
    rx_res         <= rx_re_in & rx_re_from_arp & rx_re_from_udp;
185
    rx_data_to_udp <= rx_datas( udp_data_width_c-1 downto 0 );
186
    rx_data_to_arp <= rx_datas( 2*udp_data_width_c-1 downto udp_data_width_c );
187
    rx_data_out    <= rx_datas( 3*udp_data_width_c-1 downto 2*udp_data_width_c );
188
 
189
    rx_data_valid_to_udp <= rx_data_valids(0);
190
    rx_data_valid_to_arp <= rx_data_valids(1);
191
    rx_data_valid_out    <= rx_data_valids(2);
192
 
193
    new_rx_to_udp <= new_rxs(0);
194
    new_rx_to_arp <= new_rxs(1);
195
 
196
  end generate rx_enabled;
197
 
198
  -- *** /MUX SIGNALS ***
199
  -----------------------------------------------------------------------------
200
 
201
  -- Input/output select signals can have values from 0 to 2:
202
  -- 0: UDP
203
  -- 1: ARP
204
  -- 2: application
205
 
206
  data_mux : entity work.udp_arp_data_mux
207
    generic map (
208
      data_width_g       => udp_data_width_c,
209
      tx_len_w_g         => tx_len_w_c
210
      )
211
    port map (
212
      rx_data_valid_in   => rx_data_valid_in,
213
      new_rx_in          => new_rx_in,
214
      rx_data_in         => rx_data_in,
215
      rx_res_in          => rx_res,
216
      rx_re_out          => rx_re_out,
217
      rx_datas_out       => rx_datas,
218
      rx_data_valids_out => rx_data_valids,
219
      new_rxs_out        => new_rxs,
220
      tx_datas_in        => tx_datas,
221
      tx_data_valids_in  => tx_data_valids,
222
      tx_target_MACs_in  => tx_target_MACs,
223
      tx_lens_in         => tx_lens,
224
      tx_frame_types_in  => tx_frame_types,
225
      new_txs_in         => new_txs,
226
      tx_re_in           => tx_re_in,
227
      tx_data_out        => tx_data_out,
228
      tx_data_valid_out  => tx_data_valid_out,
229
      tx_target_MAC_out  => target_MAC_out,
230
      tx_len_out         => tx_len_out,
231
      tx_frame_type_out  => tx_frame_type_out,
232
      new_tx_out         => new_tx_out,
233
      tx_res_out         => tx_res,
234
      input_select_in    => input_select,
235
      output_select_in   => output_select
236
      );
237
 
238
  frame_valid <= not rx_erroneous_in;
239
 
240
  arp_enabled: if disable_arp_g = 0 generate
241
 
242
    arp_block : entity work.ARP
243
      port map (
244
        clk               => clk,
245
        rstn              => rst_n,
246
        new_frame_in      => new_rx_to_arp,
247
        new_word_valid_in => rx_data_valid_to_arp,
248
        frame_re_out      => rx_re_from_arp,
249
        frame_data_in     => rx_data_to_arp,
250
        frame_valid_in    => frame_valid,
251
        frame_len_in      => rx_len_in,
252
        sending_reply_in  => sending_reply_arpsnd_arp,
253
        req_IP_in         => IP_arpsnd_arp,
254
        gen_ARP_rep_out   => gen_ARP_rep,
255
        gen_ARP_IP_out    => gen_ARP_IP,
256
        lookup_MAC_out    => MAC_arp_arpsnd,
257
        valid_entry_out   => ARP_entry_valid,
258
        done_out          => rx_arp_done
259
        );
260
 
261
    arpsend : entity work.ARPSnd
262
      port map (
263
        clk                => clk,
264
        rstn               => rst_n,
265
        request_MAC_in     => MAC_request_UDP_arpsnd,
266
        targer_IP_in       => IP_UDP_arpsnd,
267
        ARP_entry_valid_in => ARP_entry_valid,
268
        gen_ARP_reply_in   => gen_ARP_rep,
269
        gen_ARP_IP_in      => gen_ARP_IP,
270
        lookup_MAC_in      => MAC_arp_arpsnd,
271
        lookup_IP_out      => IP_arpsnd_arp,
272
        sending_reply_out  => sending_reply_arpsnd_arp,
273
        target_MAC_out     => tx_target_MAC_from_arp,
274
        requested_MAC_out  => MAC_arpsnd_UDP,
275
        req_MAC_valid_out  => MAC_valid_arpsnd_UDP,
276
        gen_frame_out      => new_tx_from_arp,
277
        frame_type_out     => tx_frame_type_from_arp,
278
        frame_size_out     => tx_len_from_arp,
279
        tx_ready_out       => arpsnd_tx_ready,
280
        wr_data_valid_out  => tx_data_valid_from_arp,
281
        wr_data_out        => tx_data_from_arp,
282
        wr_re_in           => tx_re_to_arp
283
        );
284
 
285
  end generate arp_enabled;
286
 
287
  arp_disabled: if disable_arp_g = 1 generate
288
    MAC_arpsnd_UDP       <= no_arp_target_MAC_in;
289
    MAC_valid_arpsnd_UDP <= '1';
290
    new_tx_from_arp      <= '0';
291
    arpsnd_tx_ready      <= '1';
292
  end generate arp_disabled;
293
 
294
  udp_block: entity work.udp
295
    generic map (
296
        data_width_g => udp_data_width_c,
297
        tx_len_w_g   => tx_len_w_c
298
        )
299
    port map (
300
        clk                   => clk,
301
        rst_n                 => rst_n,
302
        new_tx_in             => new_tx_in,
303
        tx_len_in             => tx_len_in,
304
        target_IP_in          => target_addr_in,
305
        target_port_in        => target_port_in,
306
        source_port_in        => source_port_in,
307
        new_tx_out            => new_tx_from_udp,
308
        tx_MAC_addr_out       => tx_target_MAC_from_udp,
309
        tx_len_out            => tx_len_from_udp,
310
        tx_frame_type_out     => tx_frame_type_from_udp,
311
        header_data_out       => tx_data_from_udp,
312
        header_data_valid_out => tx_data_valid_from_udp,
313
        ethernet_re_in        => tx_re_in,
314
        new_rx_in             => new_rx_to_udp,
315
        rx_data_in            => rx_data_to_udp,
316
        rx_data_valid_in      => rx_data_valid_to_udp,
317
        rx_len_in             => rx_len_in,
318
        rx_frame_type_in      => rx_frame_type_in,
319
        rx_re_out             => rx_re_from_udp,
320
        rx_erroneous_in       => rx_erroneous_in,
321
        rx_erroneous_out      => rx_erroneous_out,
322
        new_rx_out            => new_rx_out,
323
        rx_len_out            => rx_len_out,
324
        source_IP_out         => source_addr_out,
325
        source_port_out       => source_port_out,
326
        dest_port_out         => dest_port_out,
327
        application_re_in     => rx_re_in,
328
        request_MAC_out       => MAC_request_UDP_arpsnd,
329
        IP_to_arp_out         => IP_UDP_arpsnd,
330
        requested_MAC_in      => MAC_arpsnd_UDP,
331
        req_MAC_valid_in      => MAC_valid_arpsnd_UDP,
332
        rx_arp_ready_in       => rx_arp_done,
333
        snd_req_from_arp_in   => new_tx_from_arp,
334
        tx_arp_ready_in       => arpsnd_tx_ready,
335
        rx_error_out          => rx_error_out,
336
        input_select_out      => input_select,
337
        output_select_out     => output_select
338
        );
339
 
340
 
341
end rtl;

powered by: WebSVN 2.1.0

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