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

Subversion Repositories udp_ipv4_for_10g_ethernet

[/] [udp_ipv4_for_10g_ethernet/] [trunk/] [src/] [hdl/] [frame_rx_if.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 DFC
-------------------------------------------------------------------------------
2
--
3
-- (C) Copyright 2017 DFC Design, s.r.o., Brno, Czech Republic
4
-- Author: Marek Kvas (m.kvas@dfcdesign.cz)
5
--
6
-------------------------------------------------------------------------------
7
-- This file is part of UDP/IPv4 for 10 G Ethernet core.
8
-- 
9
-- UDP/IPv4 for 10 G Ethernet core is free software: you can 
10
-- redistribute it and/or modify it under the terms of 
11
-- the GNU Lesser General Public License as published by the Free 
12
-- Software Foundation, either version 3 of the License, or
13
-- (at your option) any later version.
14
-- 
15
-- UDP/IPv4 for 10 G Ethernet core is distributed in the hope that 
16
-- it will be useful, but WITHOUT ANY WARRANTY; without even 
17
-- the implied warranty of MERCHANTABILITY or FITNESS FOR A 
18
-- PARTICULAR PURPOSE.  See the GNU Lesser General Public License 
19
-- for more details.
20
-- 
21
-- You should have received a copy of the GNU Lesser General Public 
22
-- License along with UDP/IPv4 for 10 G Ethernet core.  If not, 
23
-- see <http://www.gnu.org/licenses/>.
24
-------------------------------------------------------------------------------
25
--
26
-- This module sits on outputs of tag and data fifos and translates them
27
-- to easily understandable interface.
28
--
29
--
30
-------------------------------------------------------------------------------
31
 
32
library ieee;
33
use ieee.std_logic_1164.all;
34
use ieee.numeric_std.all;
35
 
36
library work;
37
use work.frame_pkg.all;
38
 
39
Library UNISIM;
40
use UNISIM.vcomponents.all;
41
 
42
 
43
entity frame_rx_if is
44
   port (
45
      RST            : in  std_logic;
46
      CLK            : in  std_logic;
47
 
48
      FRAME_VALID    : out std_logic;
49
      FRAME_RD_EN    : in  std_logic;
50
      FRAME_LENGTH   : out std_logic_vector(C_FP_TAG_LENGTH_BITLEN - 1 downto 0);
51
      FRAME_LAST     : out std_logic;
52
      FRAME_BE       : out std_logic_vector(7 downto 0);
53
      FRAME_DATA     : out data64_port_type;
54
      SRC_MAC        : out mac_addr_type;
55
      SRC_IP         : out ip_addr_type;
56
      SRC_UDP        : out udp_port_type;
57
      DST_UDP        : out udp_port_type;
58
 
59
 
60
      -- Tag and data fifos
61
      DFIFO_DATA     : in  fp_dfifo_data_type;
62
      DFIFO_RD_EN    : out std_logic;
63
      DFIFO_EMPTY    : in  std_logic;
64
 
65
      TFIFO_DATA     : in  fp_tfifo_data_type;
66
      TFIFO_RD_EN    : out std_logic;
67
      TFIFO_EMPTY    : in  std_logic
68
        );
69
end entity;
70
 
71
 
72
 
73
 
74
architecture synthesis of frame_rx_if is
75
 
76
   constant LC_RI_LENGTH_POS  : integer := 0;
77
   constant LC_RI_DST_UDP_POS : integer :=
78
                                 LC_RI_LENGTH_POS + C_FP_TAG_LENGTH_BITLEN;
79
   constant LC_RI_SRC_UDP_POS : integer :=
80
                                 LC_RI_DST_UDP_POS + udp_port_type'length;
81
   constant LC_RI_SRC_IP_POS  : integer :=
82
                                 LC_RI_SRC_UDP_POS + udp_port_type'length;
83
   constant LC_RI_SRC_MAC_POS : integer :=
84
                                 LC_RI_SRC_IP_POS + ip_addr_type'length;
85
 
86
 
87
 
88
   -- Main FSM 
89
   type main_fsm_type is (M_WTAG, M_DATA, M_DISCARD);
90
   signal main_fsm_cur     : main_fsm_type;
91
   signal main_fsm_next    : main_fsm_type;
92
 
93
   -- FSM control signals
94
   signal load_tag_info       : std_logic;
95
   signal load_ret_info       : std_logic;
96
   signal load_discard_info   : std_logic;
97
   signal dfifo_rd_en_discard : std_logic;
98
   signal last_word           : std_logic;
99
 
100
 
101
   signal frame_length_i      : std_logic_vector(FRAME_LENGTH'range);
102
   signal data_cnt            : unsigned(FRAME_LENGTH'range);
103
 
104
   signal frame_valid_i       : std_logic;
105
 
106
   -- Internal variant of output signal
107
   signal tfifo_rd_en_i    : std_logic;
108
   signal dfifo_rd_en_i    : std_logic;
109
 
110
   -- Decomposed tag fifo
111
   signal tfifo_length     : std_logic_vector(C_FP_TAG_LENGTH_BITLEN - 1
112
                                                                     downto 0);
113
   signal tfifo_flags      : std_logic_vector(C_FP_TAG_FLAGS_BITLEN - 1
114
                                                                     downto 0);
115
   signal tfifo_return_info: std_logic_vector(C_FP_TAG_RET_INFO_LENGTH_BITLEN -1
116
                                                                     downto 0);
117
   signal return_info      : std_logic_vector(
118
                              4*C_FP_TAG_RET_INFO_LENGTH_BITLEN-1 downto 0);
119
 
120
   -- Decompose data fifo
121
   signal dfifo_rdata      : data64_port_type;
122
   signal dfifo_be         : std_logic_vector(7 downto 0);
123
 
124
begin
125
 
126
      -- Decompose fifos
127
   tfifo_length <= TFIFO_DATA(C_FP_TAG_LENGTH_BITLEN - 1 downto 0);
128
   tfifo_return_info <= TFIFO_DATA(C_FP_TAG_RET_INFO_LENGTH_BITLEN - 1
129
                                                 downto 0);
130
   tfifo_flags  <= TFIFO_DATA(TFIFO_DATA'left
131
                        downto C_FP_TAG_RET_INFO_LENGTH_BITLEN);
132
 
133
 
134
   dfifo_rdata <= DFIFO_DATA(dfifo_rdata'range);
135
   dfifo_be <= DFIFO_DATA(DFIFO_DATA'left downto dfifo_rdata'length);
136
 
137
   -- Main FSM
138
   main_fsm_adv_proc : process (RST, CLK)
139
   begin
140
      if RST = '1' then
141
         main_fsm_cur <= M_WTAG;
142
      elsif rising_edge(CLK) then
143
         main_fsm_cur <= main_fsm_next;
144
      end if;
145
   end process;
146
 
147
   main_fsm_trans_out_proc : process (main_fsm_cur, TFIFO_EMPTY, tfifo_flags,
148
                                      last_word, dfifo_rd_en_i)
149
   begin
150
 
151
      load_tag_info <= '0';
152
      load_discard_info <= '0';
153
      dfifo_rd_en_discard <= '0';
154
      tfifo_rd_en_i <= '0';
155
      load_ret_info <= '0';
156
      frame_valid_i <= '0';
157
 
158
      main_fsm_next <= main_fsm_cur;
159
      case main_fsm_cur is
160
         when M_WTAG =>
161
            if TFIFO_EMPTY = '0' then
162
               tfifo_rd_en_i <= '1';
163
               case tfifo_flags is
164
                  when C_FP_TAG_UDP =>
165
                     main_fsm_next <= M_DATA;
166
                     load_tag_info <= '1';
167
                  when C_FP_TAG_RETINF =>
168
                     load_ret_info <= '1';
169
                  when C_FP_TAG_DISCARD =>
170
                     load_discard_info <= '1';
171
                     main_fsm_next <= M_DISCARD;
172
                  when others =>
173
                     load_discard_info <= '1';
174
                     main_fsm_next <= M_DISCARD;
175
               end case;
176
            end if;
177
         when M_DATA =>
178
            frame_valid_i <= '1';
179
            if last_word = '1' and dfifo_rd_en_i = '1' then
180
               main_fsm_next <= M_WTAG;
181
            end if;
182
         when M_DISCARD =>
183
            dfifo_rd_en_discard <= '1';
184
            if last_word = '1' then
185
               main_fsm_next <= M_WTAG;
186
            end if;
187
         when others =>
188
            main_fsm_next <= M_WTAG;
189
      end case;
190
 
191
   end process;
192
 
193
 
194
   -- Count down packet len
195
   data_cnt_proc : process (RST, CLK)
196
      variable len : unsigned(tfifo_length'range);
197
   begin
198
      if RST = '1' then
199
         data_cnt <= (others => '0');
200
         last_word <= '0';
201
      elsif rising_edge(CLK) then
202
         if load_tag_info = '1' or
203
            load_discard_info = '1' then
204
            len := unsigned(tfifo_length);
205
            data_cnt <= len;
206
            if len <= 8 then
207
               last_word <= '1';
208
            else
209
               last_word <= '0';
210
            end if;
211
         elsif dfifo_rd_en_i = '1' then
212
            last_word <= '0';
213
            if data_cnt > 8 then
214
               data_cnt <= data_cnt - 8;
215
               if data_cnt <= 16 then
216
                  last_word <= '1';
217
               end if;
218
            else
219
               data_cnt <= (others => '0');
220
            end if;
221
         end if;
222
      end if;
223
   end process;
224
 
225
   -- Register return info
226
   ret_info_reg_proc : process(CLK)
227
   begin
228
      if rising_edge(CLK) then
229
         if load_ret_info = '1' or load_tag_info = '1' then
230
            for i in return_info'length/C_FP_TAG_RET_INFO_LENGTH_BITLEN
231
                           downto 2 loop
232
               return_info(i * C_FP_TAG_RET_INFO_LENGTH_BITLEN - 1 downto
233
                           (i-1) * C_FP_TAG_RET_INFO_LENGTH_BITLEN ) <=
234
               return_info((i-1) * C_FP_TAG_RET_INFO_LENGTH_BITLEN - 1 downto
235
                           (i-2) * C_FP_TAG_RET_INFO_LENGTH_BITLEN );
236
            end loop;
237
            return_info(C_FP_TAG_RET_INFO_LENGTH_BITLEN - 1 downto 0) <=
238
               tfifo_return_info;
239
         end if;
240
      end if;
241
   end process;
242
 
243
   dfifo_rd_en_i <= '1' when dfifo_rd_en_discard = '1' or
244
                    (frame_valid_i = '1' and FRAME_RD_EN = '1') else '0';
245
 
246
 
247
   -- Outputs assignment
248
   -- DFIFO_EMPTY should never happen if tags are consistent.
249
   -- If it happens there is no way back. Reset is needed to recover.
250
   DFIFO_RD_EN <= dfifo_rd_en_i;
251
   TFIFO_RD_EN <= tfifo_rd_en_i;
252
 
253
   FRAME_VALID <= frame_valid_i;
254
   FRAME_LAST <= last_word;
255
   FRAME_DATA <= dfifo_rdata;
256
   FRAME_BE <= dfifo_be;
257
   FRAME_LENGTH <= return_info(C_FP_TAG_LENGTH_BITLEN - 1 downto 0);
258
   DST_UDP <= return_info(LC_RI_DST_UDP_POS + udp_port_type'left
259
                     downto LC_RI_DST_UDP_POS );
260
   SRC_UDP <= return_info(LC_RI_SRC_UDP_POS + udp_port_type'left
261
                     downto LC_RI_SRC_UDP_POS);
262
   SRC_IP  <= return_info(LC_RI_SRC_IP_POS + ip_addr_type'left
263
                     downto LC_RI_SRC_IP_POS );
264
   SRC_MAC <= return_info(LC_RI_SRC_MAC_POS + mac_addr_type'left
265
                     downto LC_RI_SRC_MAC_POS);
266
 
267
 
268
 
269
 
270
end architecture;
271
 
272
 
273
 

powered by: WebSVN 2.1.0

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