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.communication/] [packet_codec/] [1.0/] [vhd/] [pkt_dec.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- File        : packet_decoder_ctrl.vhdl
3
-- Description : Control of the packet encoder
4
--
5
-- Author      : Vesa Lahtinen
6
-- Date        : 23.10.2003
7
-- Modified    : 
8
-- 28.04.2005    ES Names changed
9
-- 03.05.2005    ES use at max 32bits for conv_integer parameter
10
-- 25.01.0226    ES Removed unnecessary generics, changed amount from latch to reg
11
-- 07.08.2006    AR Removed decoder_format_g, changed src_id to dst_addr
12
-------------------------------------------------------------------------------
13
 
14
-------------------------------------------------------------------------------
15
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
16
--
17
-- This source file may be used and distributed without
18
-- restriction provided that this copyright statement is not
19
-- removed from the file and that any derivative work contains
20
-- the original copyright notice and the associated disclaimer.
21
--
22
-- This source file is free software; you can redistribute it
23
-- and/or modify it under the terms of the GNU Lesser General
24
-- Public License as published by the Free Software Foundation;
25
-- either version 2.1 of the License, or (at your option) any
26
-- later version.
27
--
28
-- This source is distributed in the hope that it will be
29
-- useful, but WITHOUT ANY WARRANTY; without even the implied
30
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
31
-- PURPOSE.  See the GNU Lesser General Public License for more
32
-- details.
33
--
34
-- You should have received a copy of the GNU Lesser General
35
-- Public License along with this source; if not, download it
36
-- from http://www.opencores.org/lgpl.shtml
37
-------------------------------------------------------------------------------
38
 
39
 
40
library ieee;
41
use ieee.std_logic_1164.all;
42
use ieee.std_logic_arith.all;
43
use ieee.std_logic_unsigned.all;
44
 
45
entity packet_decoder_ctrl is
46
 
47
  generic (
48
    data_width_g    : integer := 36;
49
    addr_width_g    : integer := 32;
50
    --decoder_format_g      : INTEGER := 0;  -- are headers forwarded to fifo
51
    pkt_len_g       : integer := 0;
52
    -- write_counter_max_g   : INTEGER := 0;
53
    -- amount_max_g          : INTEGER := 0;  -- NOT USED !!!
54
    fill_packet_g   : integer := 0;
55
    len_flit_en_g   : integer := 1;     -- 2007/08/03 where to place a pkt_len
56
    oaddr_flit_en_g : integer := 1;     -- 2007/08/03 whether to send the orig address
57
    dbg_en_g        : integer := 0;
58
    dbg_width_g     : integer := 1
59
    );
60
 
61
  port (
62
    clk   : in std_logic;
63
    rst_n : in std_logic;
64
 
65
    net_data_in  : in  std_logic_vector (data_width_g-1 downto 0);
66
    net_empty_in : in  std_logic;
67
    net_re_out   : out std_logic;
68
 
69
    fifo_full_in  : in  std_logic;
70
    fifo_av_out   : out std_logic;
71
    fifo_data_out : out std_logic_vector (data_width_g-1 downto 0);
72
    fifo_we_out   : out std_logic;
73
    dbg_out       : out std_logic_vector(dbg_width_g - 1  downto 0)
74
    );
75
 
76
end packet_decoder_ctrl;
77
 
78
 
79
architecture rtl of packet_decoder_ctrl is
80
 
81
  type   state_type is (start, read_address, read_amount, read_dst_addr, read_data);
82
  signal curr_state_r, next_state : state_type;
83
 
84
  -- SIGNAL write_counter_r   : INTEGER RANGE 0 TO write_counter_max_g;
85
  signal write_counter_r : integer range 0 to pkt_len_g;
86
 
87
  signal amount_r : integer range 0 to pkt_len_g;
88
 
89
  -- 2007/08/06
90
  constant len_width_c : integer := 8;  -- bits needed for pkt_len, will be generic someday?
91
 
92
 
93
begin
94
 
95
-- purpose: Clocked process for changing the state
96
-- type   : sequential
97
-- inputs : clk, rst_n, next_state
98
-- outputs: curr_state_r, write_counter_r
99
 
100
  sync : process (clk, rst_n)
101
 
102
  begin  -- PROCESS sync
103
 
104
    if rst_n = '0' then
105
      curr_state_r    <= start;
106
      write_counter_r <= 0;
107
 
108
    elsif clk = '1' and clk'event then
109
      curr_state_r <= next_state;
110
 
111
      amount_r        <= 0;
112
      write_counter_r <= 0;
113
 
114
      case curr_state_r is
115
 
116
        when read_address =>
117
          -- 2007/08/06
118
          if len_flit_en_g = 0 and net_empty_in = '0' then
119
              amount_r <= conv_integer(net_data_in (data_width_g - 1 downto data_width_g - len_width_c))- oaddr_flit_en_g;  -- 2007/08/03
120
          end if;
121
 
122
 
123
        when read_amount =>
124
 
125
          if len_flit_en_g = 1 and net_empty_in = '0' then -- 25.08.2006 AK 
126
 
127
            if data_width_g < 32 then
128
              -- amount_r <= conv_integer(net_data_in)-1;  -- orig
129
              amount_r <= conv_integer(net_data_in)- oaddr_flit_en_g;  -- 2007/08/03
130
            else
131
              -- Otherwise integer overflow may occur. 03.05.2005 ES
132
              -- amount_r <= conv_integer(net_data_in (32-1 downto 0))-1;  -- orig
133
              amount_r <= conv_integer(net_data_in (32-1 downto 0))- oaddr_flit_en_g;  -- 2007/08/03
134
            end if;
135
 
136
          else
137
            amount_r <= amount_r;
138
          end if;
139
 
140
        when read_dst_addr =>
141
          amount_r <= amount_r;
142
 
143
        when read_data =>
144
          amount_r <= amount_r;
145
 
146
          if (fifo_full_in = '0')          -- then
147
            and (net_empty_in = '0') then  --this condition 23.08.2006
148
            -- IF (write_counter_r = write_counter_max_g) THEN
149
            if (write_counter_r = pkt_len_g) then
150
              write_counter_r <= write_counter_r;
151
            else
152
              write_counter_r <= write_counter_r + 1;
153
            end if;
154
          else
155
            write_counter_r <= write_counter_r;
156
          end if;
157
 
158
        when others => null;
159
      end case;
160
 
161
 
162
    end if;
163
 
164
  end process sync;
165
 
166
  -- purpose: Asynchronous process for generating outputs and the next state
167
  -- type   : combinational
168
  -- inputs : net_data_in, net_empty_in,
169
  --          fifo_full_in, curr_state_r
170
  -- outputs: net_re_out, fifo_data_out, fifo_av_out,
171
  --          fifo_we_out, write_counter_r
172
 
173
  async : process (net_data_in, net_empty_in, fifo_full_in,
174
                   write_counter_r, amount_r, curr_state_r)
175
 
176
  begin  -- PROCESS async
177
 
178
    case curr_state_r is
179
 
180
      when start =>
181
 
182
        net_re_out    <= '0';
183
        fifo_data_out <= (others => '0');
184
        fifo_av_out   <= '0';
185
        fifo_we_out   <= '0';
186
 
187
        if (net_empty_in = '0' and fifo_full_in = '0') then
188
          next_state <= read_address;
189
        else
190
          next_state <= start;
191
        end if;
192
 
193
 
194
      when read_address =>
195
 
196
 
197
        fifo_data_out (data_width_g -1 downto data_width_g - len_width_c) <= (others => '0');
198
        fifo_data_out (data_width_g - len_width_c -1 downto 0)            <= net_data_in (data_width_g - len_width_c -1 downto 0);
199
        -- fifo_data_out <= net_data_in;
200
 
201
        if oaddr_flit_en_g = 0 then
202
          -- One address must be written to fifo
203
          -- It is this if orig_addr is disbaled
204
          fifo_av_out <= '1';
205
          fifo_we_out <= '1';
206
        end if;
207
 
208
        if (fifo_full_in = '0' and net_empty_in = '0') then
209
            next_state    <= read_amount;
210
            net_re_out    <= '1';
211
 
212
        else
213
          next_state  <= read_address;
214
          net_re_out  <= '0';
215
          fifo_we_out <= '0';
216
        end if;
217
 
218
 
219
      when read_amount =>
220
 
221
        fifo_data_out <= net_data_in;
222
        fifo_av_out   <= '0';
223
 
224
 
225
        if (net_empty_in = '0' and fifo_full_in = '0') then
226
 
227
          fifo_we_out <= '0';
228
 
229
          if len_flit_en_g = 1 then
230
            net_re_out  <= '1';
231
          else
232
            net_re_out  <= '0';
233
          end if;
234
 
235
          -- Brach 2007/08/03
236
          if oaddr_flit_en_g = 1 then
237
            next_state  <= read_dst_addr;
238
          else
239
            next_state  <= read_data;
240
          end if;
241
 
242
        else
243
          next_state  <= read_amount;
244
          fifo_we_out <= '0';
245
          net_re_out  <= '0';
246
        end if;
247
 
248
 
249
      when read_dst_addr =>
250
 
251
        fifo_data_out <= net_data_in;
252
        fifo_av_out   <= '1';
253
 
254
        if (fifo_full_in = '0' and net_empty_in = '0') then
255
          next_state  <= read_data;
256
          net_re_out  <= '1';
257
          fifo_we_out <= '1';
258
 
259
        else
260
          next_state  <= read_dst_addr;
261
          net_re_out  <= '0';
262
          fifo_we_out <= '0';
263
        end if;
264
 
265
 
266
 
267
      when read_data =>                 -- read_data
268
 
269
        fifo_data_out <= net_data_in;
270
        fifo_av_out   <= '0';
271
 
272
 
273
 
274
        -- 23.08.2006, es
275
        --  - added check for net_empty=0
276
        --  - moved definition of next_state inside above if-else
277
        --  - changed pkt_len-3 to pkt_len-4
278
        --  Seems to work at least with tb_hemres_lat
279
        if (fifo_full_in = '0')         --  then
280
          and net_empty_in = '0' then   -- this condition 23.08.2006
281
 
282
 
283
          -- 20.10.2006 testailua hermesta varten
284
          if ((write_counter_r = amount_r-1 and fill_packet_g = 0)
285
              or
286
              --(write_counter_r = pkt_len_g-4 and fill_packet_g = 1)
287
              (write_counter_r = pkt_len_g-1-1-len_flit_en_g-oaddr_flit_en_g and fill_packet_g = 1)
288
              ) then
289
            next_state <= start;
290
          else
291
            next_state <= read_data;
292
          end if;
293
 
294
 
295
          if (write_counter_r < amount_r) then
296
            -- Verkosta luetaan vakiomäärä
297
            -- eli vaikka siellä oleva fifo olisikin tyhjä
298
            fifo_we_out <= '1';
299
            net_re_out  <= '1';
300
          else
301
            fifo_we_out <= '0';
302
            net_re_out  <= '1';
303
 
304
          end if;
305
 
306
        else
307
          fifo_we_out <= '0';
308
          net_re_out  <= '0';
309
          next_state  <= read_data;     -- 23.03.2006
310
        end if;
311
 
312
 
313
    end case;
314
 
315
 
316
  end process async;
317
 
318
end rtl;

powered by: WebSVN 2.1.0

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