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.storage/] [fifos/] [synch_fifos/] [1.0/] [vhd/] [fifo_slotted.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- File        : fifo_shift.vhdl
3
-- Description : Fifo buffer for hibi interface
4
--
5
-- Author      : Erno Salminen
6
-- Date        : 29.10.2004
7
-- Modified    : 
8
-- 20.01.2005   ES Names changed
9
-------------------------------------------------------------------------------
10
library ieee;
11
use ieee.std_logic_1164.all;
12
use ieee.std_logic_arith.all;
13
use ieee.std_logic_unsigned.all;
14
 
15
entity fifo is
16
 
17
  generic (
18
    data_width_g :     integer := 32;
19
    depth_g      :     integer := 5
20
    );
21
  port (
22
    clk          : in  std_logic;
23
    rst_n        : in  std_logic;
24
    data_in      : in  std_logic_vector (data_width_g-1 downto 0);
25
    we_in        : in  std_logic;
26
    one_p_out    : out std_logic;
27
    full_out     : out std_logic;
28
    data_out     : out std_logic_vector (data_width_g-1 downto 0);
29
    re_in        : in  std_logic;
30
    empty_out    : out std_logic;
31
    one_d_out    : out std_logic
32
    );
33
 
34
end fifo;
35
 
36
 
37
 
38
architecture slotted_fifo_reg of fifo is
39
 
40
  component fifo_slot
41
    generic (
42
      width           :    integer := 0);
43
    port (
44
      clk             : in std_logic;
45
      rst_n           : in std_logic;
46
      Right_Valid_In  : in std_logic;
47
      Right_Enable_In : in std_logic;
48
      Right_data_in   : in std_logic_vector ( width-1 downto 0);
49
 
50
      Left_data_in  : in  std_logic_vector ( width-1 downto 0);
51
      Left_Valid_In : in  std_logic;
52
      Left_Enable   : in  std_logic;
53
      Valid_Out      : out std_logic;
54
      data_out       : out std_logic_vector ( width-1 downto 0)
55
      );
56
 
57
  end component; -- fifo_slot;
58
 
59
 
60
 
61
  type Fifo_slot_type is record
62
                           Valid : std_logic;
63
                           Data  : std_logic_vector ( data_width_g-1 downto 0);
64
                         end record;
65
  type slot_signal_array is array (depth_g downto 0) of Fifo_slot_type;
66
  signal intermediate_signal     : slot_signal_array;
67
  signal we                      : std_logic_vector ( depth_g-1 downto 0);
68
  signal re                      : std_logic_vector ( depth_g-1 downto 0);
69
 
70
  signal  tie_high : std_logic;
71
 
72
 
73
begin  -- slotted_fifo_reg
74
 
75
 
76
 
77
  -- Continuous assignments
78
  -- Assigns register values to outputs
79
  tie_high  <= '1';
80
  assert depth_g > 1 report "Fifo depth_g must be more than one!" severity WARNING;
81
  full_out  <= intermediate_signal (depth_g-1).Valid;  -- ylin paikka varattu
82
  empty_out <= not (intermediate_signal (0).Valid );   -- alin paikka tyhja
83
 
84
 
85
 
86
  -- Yksi data=alin taynna, toiseksi alin tyhja
87
  one_d_out <= not (intermediate_signal (1).Valid) and intermediate_signal (0).Valid;
88
 
89
  -- Yksi paikka=ylin tyhja, toiseksi ylin taynna
90
  one_p_out <= not (intermediate_signal (depth_g-1).Valid) and intermediate_signal (depth_g-2).Valid;
91
 
92
  data_out       <= intermediate_signal (0).Data;  --alin data ulostuloon
93
  -- Note! There is some old value in data output when fifo is empty.
94
 
95
 
96
 
97
  map_slots    : for i in 0 to depth_g-1 generate
98
    gen_slot_i : fifo_slot
99
      generic map (
100
        width           => data_width_g
101
        )
102
      port map (
103
        clk             => clk,
104
        rst_n           => rst_n,
105
        Right_data_in   => data_in,
106
        Right_Valid_In  => tie_high,
107
        Right_Enable_In => we (i),
108
        Left_Valid_In   => intermediate_signal (i+1).Valid,
109
        Left_data_in    => intermediate_signal (i+1).Data,
110
        Left_Enable     => re (i),
111
        Valid_Out       => intermediate_signal (i).Valid,
112
        data_out        => intermediate_signal (i).Data
113
        );
114
  end generate map_slots;
115
 
116
  intermediate_signal (depth_g).Data  <= (others => '0'); --'Z');
117
  intermediate_signal (depth_g).Valid <= '0';
118
 
119
  async_first_slot: process (intermediate_signal, we_in, re_in)
120
  begin  -- process async_first_slot
121
    -- Ohjataan ensimmaisen we-signaalia
122
 
123
    if we_in = '1' and re_in = '0' then
124
      -- Kirjoitus pelkästään
125
      re <= (others => '0');
126
 
127
 
128
      if intermediate_signal (depth_g-1).Valid = '1' then
129
        -- Ylin paikka taynna
130
        we <= (others => '0');
131
 
132
 
133
      else
134
        -- Kirjoitetaan uusi data 
135
        we <= (others => '0');
136
 
137
        if intermediate_signal(0).Valid = '0' then
138
          -- tyhjä
139
          we(0) <= '1';
140
        else
141
 
142
 
143
           for i in 1 to depth_g-1 loop
144
             if intermediate_signal(i-1).Valid = '1'
145
               and intermediate_signal(i).Valid = '0'
146
             then
147
               we(i) <= '1';
148
             end if;
149
           end loop;  -- (i        
150
        end if;
151
      end if;
152
 
153
 
154
    elsif we_in = '0' and re_in = '1' then
155
      -- Luku pelkästään
156
      we <= (others => '0');
157
      re <= (others => '1');
158
 
159
 
160
 
161
    elsif we_in = '1' and re_in = '1' then
162
      --Luku ja kirjoitus yhta aikaa
163
 
164
      if intermediate_signal (depth_g-1).Valid = '1' then
165
        -- Ylin paikka taynna
166
        we <= (others => '0');
167
        re <= (others => '1');
168
 
169
      else
170
        -- Kirjoitetaan uusi data ja shiftataaan vanhoja
171
        we <= (others => '0');
172
        re <= (others => '1');
173
 
174
 
175
        if intermediate_signal(0).Valid = '0' then
176
          -- tyhjä, ei shifatata
177
          we(0) <= '1';
178
          re    <= (others => '0');
179
 
180
        else
181
 
182
          for i in 1 to depth_g-1 loop
183
            if intermediate_signal(i-1).Valid = '1'
184
              and intermediate_signal(i).Valid = '0'
185
            then
186
              -- kirjoiteteaan juuri tyhjenevään paikkaan
187
              we (i-1) <= '1';
188
              re (i-1) <= '0';
189
 
190
            end if;
191
          end loop;  -- (i     
192
 
193
        end if;
194
      end if;
195
 
196
 
197
 
198
    else
199
      -- Ei tehda mitaan
200
      we <= (others => '0'); --'Z');
201
      re <= (others => '0'); -- 'Z');
202
 
203
 
204
    end if;
205
 
206
 
207
  end process async_first_slot;
208
 
209
 
210
 
211
  check_we: process (we)
212
    variable one_bits : integer := 0;
213
  begin  -- process check_we
214
    one_bits := 0;
215
 
216
    for i in 0 to depth_g-1 loop
217
      if we(i)= '1' then
218
        one_bits := one_bits +1;
219
      end if;
220
    end loop;  -- i
221
 
222
 
223
    --    assert one_bits < 2 report "Too many write enables" severity WARNING;
224
  end process check_we;
225
 
226
 
227
 
228
 
229
 
230
 
231
end slotted_fifo_reg;                  --architecture

powered by: WebSVN 2.1.0

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