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

Subversion Repositories udp_ip__core

[/] [udp_ip__core/] [trunk/] [UDP_IP_CORE/] [UDP_IP_CORE__Spartan3/] [IPV4_PACKET_TRANSMITTER.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 NikosAl
-----------------------------------------------------------------------------------------
2
-- Copyright (C) 2010 Nikolaos Ch. Alachiotis                                                                                                           --
3
--                                                                                                                                                                                                                                      --                                                      
4
-- Engineer:                            Nikolaos Ch. Alachiotis                                                                                                         --
5
--                                                                                                                                                                                                                                      --
6
-- Contact:                                     alachiot@cs.tum.edu                                                                                                                     --
7
--                                                              n.alachiotis@gmail.com                                                                                                          --
8
--                                                                                                                                                                                                                              --
9
-- Create Date:                 14:45:39 11/27/2009                                                                                                             --
10
-- Module Name:                 IPV4_PACKET_TRANSMITTER                                                                                                         --
11
-- Target Devices:              Virtex 5 FPGAs                                                                                                                          --
12
-- Tool versions:               ISE 10.1                                                                                                                                                        --
13
-- Description:                         This component can be used to send IPv4 Ethernet Packets.               --
14
-- Additional Comments: The look-up table contains the header fields of the IP packet, --
15
--                                                              so please keep in mind that you have to reinitialize this LUT. --
16
--                                                                                                                                                                                                                                      --
17
-----------------------------------------------------------------------------------------
18
library IEEE;
19
use IEEE.STD_LOGIC_1164.ALL;
20
use IEEE.STD_LOGIC_ARITH.ALL;
21
use IEEE.STD_LOGIC_UNSIGNED.ALL;
22
 
23
---- Uncomment the following library declaration if instantiating
24
---- any Xilinx primitives in this code.
25
--library UNISIM;
26
--use UNISIM.VComponents.all;
27
 
28
entity IPV4_PACKET_TRANSMITTER is
29
    Port ( rst : in  STD_LOGIC;
30
           clk_125MHz : in  STD_LOGIC;
31
           transmit_start_enable : in  STD_LOGIC;
32
           transmit_data_length : in  STD_LOGIC_VECTOR (15 downto 0);
33
                          usr_data_trans_phase_on : out STD_LOGIC;
34
           transmit_data_input_bus : in  STD_LOGIC_VECTOR (7 downto 0);
35
           start_of_frame_O : out  STD_LOGIC;
36
                          end_of_frame_O : out  STD_LOGIC;
37
                          source_ready : out STD_LOGIC;
38
                          transmit_data_output_bus : out STD_LOGIC_VECTOR (7 downto 0)
39
                          );
40
end IPV4_PACKET_TRANSMITTER;
41
 
42
architecture Behavioral of IPV4_PACKET_TRANSMITTER is
43
 
44
 
45
-----------------------------------------------------------------------------------------------------------------------------------------
46
-----------------------------------------------------------------------------------------------------------------------------------------
47
-- IPv4 PACKET STRUCTURE :                                                                                                                                                                                                                                                                                                      --
48
--                                                                                      Size            |               Description                                                                                     |               Transmission Order              |  Position             --
49
--                                                                              -----------------------------------------------------------------------------------------------------------
50
--                                                                                      6 bytes |       Destin MAC Address (PC)                                                         |               0 1 2 3 4 5                             |       LUT                             --
51
--                                                                                                              |       X-X-X-X-X-X                                                                                             |                                                                       |                                               --
52
--                                                                                                              |                                                                                                                               |                                                                       |                                               --
53
--                                                                                      6 bytes |       Source MAC Address (FPGA)                                                       |          6 7 8 9 10 11                        |       LUT                             --
54
--                                                                                                              |       11111111-11111111-11111111-11111111-...         |                                                                       |                                               --
55
--                                                                                      2 bytes  |      Ethernet Type *                                                                                 |               12 13                                           |       LUT                             --
56
--                                                                                                              |       (fixed to 00001000-00000000 :=>                                 |                                                                       |                                               --
57
--                                                                                                              |        Internet Protocol, Version 4 (IPv4))                   |                                                                       |                                               --
58
-- -- Start of IPv4 Packet ** - -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       --      |                                               --
59
--                                                                                      1 byte  |       4 MSBs = Version , 4 LSBs = Header Length               |               14                                                      |       LUT                             --
60
--                                                       |  0100                                0101                                                                    |                                                                       |                                               --
61
--                                                                                      1 byte  |       Differentiated Services                                                         |               15                                                      |       LUT                             --
62
--                                                                                                              |       00000000                                                                                                        |                                                                       |                                               --
63
--                                                                                      2 bytes |       Total Length                                                                                    |               16 17                                           |       REG                             --
64
--                                                                                                              |       00000000-00100100 (base: 20 + 8 + datalength)|                                                                  |                                               --
65
--                                                                                      2 bytes |       Identification                                                                                  |               18 19                                           |       LUT                             --
66
--                                                                                                              |       00000000-00000000                                                                               |                                                                       |                                               --
67
--                                                                                      2 bytes |       3 MSBs = Flags , 13 LSBs = Fragment Offset      |               20 21                                           |       LUT                             --
68
--                                                                                                              |       010 - 0000000000000                                                                     |                                                                       |                                               --
69
--                                                                                      1 byte  |       Time to Live                                                                                    |               22                                                      |       LUT                             --
70
--                                                                                                              |       01000000                                                                                                        |                                                                       |                                               --
71
--                                                                                      1 byte  |       Protocol                                                                                                        |               23                                                      |       LUT                             --
72
--                                                                                                              |       00010001                                                                                                        |                                                                       |                                               --
73
--                                                                                      2 bytes |  Header Checksum                                                                              |               24 25                                           |       REG                             --
74
--                                                                                                              |       10110111 01111101 (base value)                                  |                                                                       |                                               --
75
--                                                                                      4 bytes |       Source IP Address                                                                               |               26 27 28 29                             |       LUT                             --
76
--                                                                                                              |       X-X-X-X                                                                          - FPGA |                                                                       |                                               --
77
--                                                                                      4 bytes |       Destin IP Address                                                                               |               30 31 32 33                             |       LUT                             --
78
--                                                                                                              |       X-X-X-X                                                                          - PC           |                                                                       |                                               --
79
--      -- Start of UDP Packet *** -    -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -       -- |                                            --
80
--                                                                                      2 bytes |  Source Port                                                                                          |               34 35                                           |       LUT                             --
81
--                                                                                                              |       X-X                                                                                                             |                                                                       |                                               --
82
--                                                                                      2 bytes |       Destination Port                                                                                |               36 37                                           |       LUT                             --
83
--                                                                                                              |       X-X                                                                                                             |                                                                       |                                               --
84
--                                                                                      2 bytes |       Length                                                                                                  |               38 39                                           |       REG                             --
85
--                                                                                                              |       00000000 - 00010000   (8 + # data bytes)                |                                                                       |                                               --
86
--                                                                                      2 bytes |       Checksum                                                                                                        |               40 41                                           |       LUT                             --
87
--                                                                                                              |       00000000 - 00000000                                                                     |                                                                       |                                               --
88
--                                                                                      X bytes |       Data                                                                                                            |               42 .. X                                 |  from input           --
89
--                                                                                                              |                                                                                                                               |                                                                       |                                               --
90
-----------------------------------------------------------------------------------------------------------------------------------------
91
-----------------------------------------------------------------------------------------------------------------------------------------
92
 
93
--  *  More details about the Ethernet Type value you can find here:
94
--     http://en.wikipedia.org/wiki/Ethertype
95
 
96
-- **  More details about the Internet Protocol, Version 4 (IPv4) you can find here:
97
--     http://en.wikipedia.org/wiki/IPv4
98
 
99
-- *** More details about the Internet Protocol, Version 4 (IPv4) you can find here:
100
--     http://en.wikipedia.org/wiki/User_Datagram_Protocol
101
 
102
-----------------------------------------------------------------------------------------------------------------------------------------
103
-----------------------------------------------------------------------------------------------------------------------------------------
104
 
105
 
106
 
107
--------------------------------------------------------------------------------------
108
-- COMPONENT DECLARATION
109
--------------------------------------------------------------------------------------
110
 
111
component REG_16B_WREN is
112
    Port ( rst : in  STD_LOGIC;
113
                          clk : in  STD_LOGIC;
114
           wren : in  STD_LOGIC;
115
           input : in  STD_LOGIC_VECTOR (15 downto 0);
116
           output : out  STD_LOGIC_VECTOR (15 downto 0));
117
end component;
118
 
119
component IPV4_LUT_INDEXER is
120
    Port ( rst : in  STD_LOGIC;
121
           clk : in  STD_LOGIC;
122
           transmit_enable : in  STD_LOGIC;
123
           LUT_index : out  STD_LOGIC_VECTOR (5 downto 0));
124
end component;
125
 
126
component dist_mem_64x8 is
127
  port (
128
    clk : in STD_LOGIC := 'X';
129
    a : in STD_LOGIC_VECTOR ( 5 downto 0 );
130
    qspo : out STD_LOGIC_VECTOR ( 7 downto 0 )
131
  );
132
end component;
133
 
134
component OVERRIDE_LUT_CONTROL is
135
    Port ( clk : in  STD_LOGIC;
136
                input_addr : in  STD_LOGIC_VECTOR (5 downto 0);
137
           sel_total_length_MSBs : out  STD_LOGIC;
138
                          sel_total_length_LSBs : out  STD_LOGIC;
139
                          sel_header_checksum_MSBs : out  STD_LOGIC;
140
                          sel_header_checksum_LSBs : out  STD_LOGIC;
141
                          sel_length_MSBs : out  STD_LOGIC;
142
                          sel_length_LSBs : out  STD_LOGIC
143
           );
144
end component;
145
 
146
component TARGET_EOF is
147
    Port ( rst : in  STD_LOGIC;
148
           clk : in  STD_LOGIC;
149
           start : in  STD_LOGIC;
150
                          total_length_from_reg : in STD_LOGIC_VECTOR(15 downto 0);
151
           eof_O : out  STD_LOGIC);
152
end component;
153
 
154
component ENABLE_USER_DATA_TRANSMISSION is
155
    Port ( rst : in STD_LOGIC;
156
                          clk : in  STD_LOGIC;
157
           start_usr_data_trans : in  STD_LOGIC;
158
           stop_usr_data_trans : in  STD_LOGIC;
159
           usr_data_sel : out  STD_LOGIC);
160
end component;
161
 
162
component ALLOW_ZERO_UDP_CHECKSUM is
163
    Port ( clk : in  STD_LOGIC;
164
           input : in  STD_LOGIC;
165
                          output_to_readen  : out STD_LOGIC;
166
           output_to_datasel : out  STD_LOGIC);
167
end component;
168
 
169
 
170
--------------------------------------------------------------------------------------
171
-- SIGNAL DECLARATION
172
--------------------------------------------------------------------------------------
173
 
174
signal transmit_start_enable_tmp,
175
                 sel_total_length_MSBs,
176
                 sel_total_length_LSBs,
177
                 sel_header_checksum_MSBs,
178
                 sel_header_checksum_LSBs,
179
                 sel_length_MSBs,
180
                 sel_length_LSBs,
181
                 lut_out_sel,
182
                 source_ready_previous_value,
183
                 end_of_frame_O_tmp,
184
                 transmit_start_enable_reg,
185
                 usr_data_sel_sig,
186
                 start_usr_data_read,
187
                 start_usr_data_trans                                                           :       STD_LOGIC;
188
 
189
signal LUT_addr                                                                                                 :       STD_LOGIC_VECTOR(5 downto 0);
190
 
191
signal transmit_data_input_bus_tmp,
192
                 transmit_data_output_bus_tmp,
193
                 sel_total_length_MSBs_vec,
194
                 sel_total_length_LSBs_vec,
195
                 sel_header_checksum_MSBs_vec,
196
                 sel_header_checksum_LSBs_vec,
197
                 sel_length_MSBs_vec,
198
                 sel_length_LSBs_vec,
199
                 lut_out_sel_vec,
200
                 transmit_data_output_bus_no_usr_data,
201
                 usr_data_not_sel_vec,
202
                 usr_data_sel_vec                                                                               :       STD_LOGIC_VECTOR(7 downto 0);
203
 
204
signal transmit_data_length_tmp,
205
                 data_length_regout,
206
                 tmp_total_length,
207
                 tmp_header_checksum,
208
                 tmp_header_checksum_baseval,
209
                 tmp_length                                                                                             :       STD_LOGIC_VECTOR(15 downto 0);
210
 
211
 
212
begin
213
 
214
transmit_start_enable_tmp<=transmit_start_enable;
215
 
216
transmit_data_length_tmp<=transmit_data_length;
217
 
218
transmit_data_input_bus_tmp<=transmit_data_input_bus;
219
 
220
----------------------------------------------------------------------------------------------------
221
-- start_of_frame_O signal
222
----------------------------------------------------------------------------------------------------
223
-- Description:  start_of_frame_O is active low
224
--                                        We connect it to the delayed for one clock cycle transmit_start_enable input signal
225
--                                        through a NOT gate since transmit_start_enable is active high.
226
 
227
process(clk_125MHz)
228
begin
229
if clk_125MHz'event and clk_125MHz='1' then
230
        transmit_start_enable_reg<=transmit_start_enable_tmp; -- Delay transmit_start_enable one cycle.
231
end if;
232
end process;
233
 
234
start_of_frame_O<=not transmit_start_enable_reg;
235
 
236
----------------------------------------------------------------------------------------------------
237
-- end_of_frame_O signal
238
----------------------------------------------------------------------------------------------------
239
-- Description:  end_of_frame_O is active low
240
--                                        The TARGET_EOF module targets the last byte of the packet that is being transmitted
241
--                                        based on a counter that counts the number of transmitted bytes and a comparator that
242
--                                        detects the last byte which is the <tmp_total_length>th byte.
243
 
244
TARGET_EOF_port_map: TARGET_EOF  port map
245
(
246
        rst =>rst,
247
   clk =>clk_125MHz,
248
   start =>transmit_start_enable_reg,
249
        total_length_from_reg =>tmp_total_length,
250
   eof_O =>end_of_frame_O_tmp
251
);
252
 
253
--* The counter in TARGET_EOF starts from -X, where X is the number of bytes transmitted before the 
254
--       IPv4 packet. (MAC addresses + Ethernet Type)
255
 
256
end_of_frame_O<=end_of_frame_O_tmp;
257
 
258
----------------------------------------------------------------------------------------------------
259
-- source_ready signal
260
----------------------------------------------------------------------------------------------------
261
-- Description:  source_ready is active low
262
--                                        This signal is idle(high). (based on rst and end_of_frame_O_tmp). 
263
--                                        This signal is active(low). (based on transmit_start_enable and end_of_frame_O_tmp).
264
 
265
process(clk_125MHz)
266
begin
267
if rst='1' then
268
        source_ready<='1';
269
        source_ready_previous_value<='1';
270
else
271
        if clk_125MHz'event and clk_125MHz='1' then
272
                if (transmit_start_enable_tmp='1' and source_ready_previous_value='1') then
273
                        source_ready<='0';
274
                        source_ready_previous_value<='0';
275
                else
276
                        if (end_of_frame_O_tmp='0' and source_ready_previous_value='0') then
277
                                source_ready<='1';
278
                           source_ready_previous_value<='1';
279
                        end if;
280
                end if;
281
        end if;
282
end if;
283
end process;
284
 
285
----------------------------------------------------------------------------------------------------
286
-- transmit_data_output_bus 
287
----------------------------------------------------------------------------------------------------
288
----------------------------------------------------------------------------------------------------
289
-- Component Name:      REG_16B_WREN
290
-- Instance Name:       NUMBER_OR_DATA_IN_BYTES_REGISTER
291
-- Description:                 Register that holds the number of bytes of input data 
292
--                                                      that will be transmitted in the packet.
293
----------------------------------------------------------------------------------------------------
294
NUMBER_OR_DATA_IN_BYTES_REGISTER : REG_16B_WREN port map
295
(
296
        rst =>rst,
297
        clk =>clk_125MHz,
298
        wren =>transmit_start_enable_tmp, -- The transmit_start_enable input signal can be used as wren.
299
        input =>transmit_data_length_tmp,
300
        output =>data_length_regout
301
);
302
----------------------------------------------------------------------------------------------------
303
 
304
tmp_total_length<="0000000000011100" + data_length_regout;
305
 
306
tmp_header_checksum_baseval<="1011011101111101";        -- CHANGE VALUE! : You have to change this value!
307
tmp_header_checksum<=tmp_header_checksum_baseval - data_length_regout;
308
 
309
tmp_length<="0000000000001000" + data_length_regout;
310
 
311
----------------------------------------------------------------------------------------------------
312
 
313
----------------------------------------------------------------------------------------------------
314
-- Component Name:      IPV4_LUT_INDEXER
315
-- Instance Name:       IPV4_LUT_INDEXER_port_map
316
-- Description:                 When transmit_enable is high for one cycle IPV4_LUT_INDEXER generates the
317
--                                                      addresses to the LUT that contains the header section of the IP packet.
318
----------------------------------------------------------------------------------------------------
319
IPV4_LUT_INDEXER_port_map : IPV4_LUT_INDEXER port map
320
(
321
        rst =>rst,
322
   clk =>clk_125MHz,
323
   transmit_enable =>transmit_start_enable_tmp,
324
   LUT_index =>LUT_addr
325
);
326
----------------------------------------------------------------------------------------------------
327
 
328
----------------------------------------------------------------------------------------------------
329
-- Component Name:      dist_mem_64x8
330
-- Instance Name:       LUT_MEM
331
-- Description:                 LUT that contains the header section.
332
----------------------------------------------------------------------------------------------------
333
LUT_MEM : dist_mem_64x8 port map
334
(
335
        clk =>clk_125MHz,
336
   a =>LUT_addr,
337
   qspo =>transmit_data_output_bus_tmp
338
);
339
----------------------------------------------------------------------------------------------------
340
 
341
----------------------------------------------------------------------------------------------------
342
-- Component Name:      OVERRIDE_LUT_CONTROL
343
-- Instance Name:       OVERRIDE_LUT_CONTROL_port_map
344
-- Description:                 Decides whether the output byte will come from the LUT or not.
345
----------------------------------------------------------------------------------------------------
346
OVERRIDE_LUT_CONTROL_port_map : OVERRIDE_LUT_CONTROL port map
347
(
348
        clk =>clk_125MHz,
349
        input_addr =>LUT_addr,
350
        sel_total_length_MSBs =>sel_total_length_MSBs,
351
        sel_total_length_LSBs =>sel_total_length_LSBs,
352
        sel_header_checksum_MSBs =>sel_header_checksum_MSBs,
353
        sel_header_checksum_LSBs =>sel_header_checksum_LSBs,
354
        sel_length_MSBs =>sel_length_MSBs,
355
        sel_length_LSBs =>sel_length_LSBs
356
);
357
----------------------------------------------------------------------------------------------------
358
 
359
----------------------------------------------------------------------------------------------------
360
-- MUX 7 to 1
361
sel_total_length_MSBs_vec<=(others=>sel_total_length_MSBs);
362
sel_total_length_LSBs_vec<=(others=>sel_total_length_LSBs);
363
sel_header_checksum_MSBs_vec<=(others=>sel_header_checksum_MSBs);
364
sel_header_checksum_LSBs_vec<=(others=>sel_header_checksum_LSBs);
365
sel_length_MSBs_vec<=(others=>sel_length_MSBs);
366
sel_length_LSBs_vec<=(others=>sel_length_LSBs);
367
lut_out_sel_vec <= (others=>lut_out_sel);
368
 
369
lut_out_sel<=(not sel_total_length_MSBs) and (not sel_total_length_LSBs) and
370
                                 (not sel_header_checksum_MSBs) and (not sel_header_checksum_LSBs) and
371
                                 (not sel_length_MSBs) and (not sel_length_LSBs);
372
 
373
-- MUX output
374
transmit_data_output_bus_no_usr_data<= (transmit_data_output_bus_tmp and lut_out_sel_vec) or
375
                                                                                                  (tmp_total_length(15 downto 8) and sel_total_length_MSBs_vec) or
376
                                                                                                  (tmp_total_length(7 downto 0) and sel_total_length_LSBs_vec) or
377
                                                                                                  (tmp_header_checksum(15 downto 8) and sel_header_checksum_MSBs_vec) or
378
                                                                                                  (tmp_header_checksum(7 downto 0) and sel_header_checksum_LSBs_vec) or
379
                                                                                                  (tmp_length(15 downto 8) and sel_length_MSBs_vec) or
380
                                                                                                  (tmp_length(7 downto 0) and sel_length_LSBs_vec);
381
----------------------------------------------------------------------------------------------------
382
 
383
----------------------------------------------------------------------------------------------------
384
-- Component Name:      ALLOW_ZERO_UDP_CHECKSUM
385
-- Instance Name:       ALLOW_ZERO_UDP_CHECKSUM_port_map
386
-- Description:                 Delays the user data transmition phase in order to transmit two bytes with zero
387
--                                                      first.
388
----------------------------------------------------------------------------------------------------
389
ALLOW_ZERO_UDP_CHECKSUM_port_map: ALLOW_ZERO_UDP_CHECKSUM port map
390
(
391
        clk =>clk_125MHz,
392
        input =>sel_length_LSBs,
393
        output_to_readen =>start_usr_data_read,
394
        output_to_datasel =>start_usr_data_trans
395
);
396
----------------------------------------------------------------------------------------------------
397
 
398
----------------------------------------------------------------------------------------------------
399
-- Component Name:      ENABLE_USER_DATA_TRANSMISSION
400
-- Instance Name:       ENABLE_USER_DATA_READ_port_map
401
-- Description:                 Sets usr_data_trans_phase_on signal one cycle before the transmittion of the 
402
--                                                      first user byte.
403
----------------------------------------------------------------------------------------------------
404
ENABLE_USER_DATA_READ_port_map: ENABLE_USER_DATA_TRANSMISSION port map
405
(       rst =>rst,
406
   clk =>clk_125MHz,
407
   start_usr_data_trans =>start_usr_data_read,
408
   stop_usr_data_trans =>end_of_frame_O_tmp,
409
   usr_data_sel =>usr_data_trans_phase_on
410
);
411
----------------------------------------------------------------------------------------------------
412
 
413
----------------------------------------------------------------------------------------------------
414
-- Component Name:      ENABLE_USER_DATA_TRANSMISSION
415
-- Instance Name:       ENABLE_USER_DATA_TRANSMISSION_port_map
416
-- Description:                 Sets usr_data_sel_sig signal to select user data for transmittion.
417
----------------------------------------------------------------------------------------------------
418
ENABLE_USER_DATA_TRANSMISSION_port_map: ENABLE_USER_DATA_TRANSMISSION port map
419
(       rst =>rst,
420
   clk =>clk_125MHz,
421
   start_usr_data_trans =>start_usr_data_trans,
422
   stop_usr_data_trans =>end_of_frame_O_tmp,
423
   usr_data_sel =>usr_data_sel_sig
424
);
425
----------------------------------------------------------------------------------------------------
426
 
427
----------------------------------------------------------------------------------------------------
428
-- MUX 2 to 1
429
usr_data_not_sel_vec<=(others=>not usr_data_sel_sig);
430
usr_data_sel_vec<=(others=>usr_data_sel_sig);
431
 
432
-- MUX output
433
transmit_data_output_bus<=(transmit_data_output_bus_no_usr_data and usr_data_not_sel_vec) or
434
                                                                 (transmit_data_input_bus and usr_data_sel_vec);
435
----------------------------------------------------------------------------------------------------
436
 
437
end Behavioral;

powered by: WebSVN 2.1.0

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