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_casev6.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- File        : fifo_casev6.vhdl
3
-- Description : Fifo buffer for hibi interface
4
-- Author      : Ari Kulmala
5
-- Date        : 10.06.2003
6
-- Modified    : 18.06.2003 - Re-wrote the way output control signals are
7
--                            assigned
8
--                          - output value is not zero when empty
9
--
10
-- Detailed description:
11
-- -Input and Output always from the same register
12
--   -> input-buffer is shifted whenever write occurs
13
--   -> when read, a mux chooses which value to load to the output next
14
--      (the oldest)
15
--
16
-- !NOTE! isn't tested as one-length FIFO. doesn't probably work. (vector
17
-- length (1 downto 2) ...
18
--
19
-- !NOTE!
20
-- * Output stays in the old value when empty.
21
-------------------------------------------------------------------------------
22
 
23
-------------------------------------------------------------------------------
24
-- To do: as in fifo_casev4: fifojen nollaus olisi syyta ehka poistaa myos
25
-- resetin yhteydesta, jos sita ei nollata myoskaan luettaessa viimeinen
26
-- samaten input_bufferin nollaus.
27
-------------------------------------------------------------------------------
28
 
29
library IEEE;
30
use IEEE.std_logic_1164.all;
31
use IEEE.std_logic_arith.all;
32
 
33
 
34
entity fifo is
35
 
36
  generic (
37
    width : integer := 0;
38
    depth : integer := 0);
39
 
40
  port (
41
    Clk            : in  std_logic;
42
    Rst_n          : in  std_logic;     -- Active low
43
    Data_In        : in  std_logic_vector (width-1 downto 0);
44
    Write_Enable   : in  std_logic;
45
    One_Place_Left : out std_logic;
46
    Full           : out std_logic;
47
    Data_Out       : out std_logic_vector (width-1 downto 0);
48
    Read_Enable    : in  std_logic;
49
    Empty          : out std_logic;
50
    One_Data_Left  : out std_logic
51
    );
52
 
53
end fifo;
54
 
55
architecture behavioral of fifo is
56
 
57
  -- range is this so that one can use data_amount directly to indexing
58
  type reg is array (depth downto 2) of std_logic_vector
59
    (width-1 downto 0);
60
  signal input_buffer : reg;
61
  -- Registers
62
  signal Full_reg           : std_logic;
63
  signal Empty_reg          : std_logic;
64
  signal One_Data_Left_reg  : std_logic;
65
  signal One_Place_Left_reg : std_logic;
66
 
67
  signal Data_amount : integer range 0 to depth;
68
 
69
 
70
  signal WR : std_logic_vector ( 1 downto 0);
71
 
72
begin  -- behavioral
73
 
74
    -- Continuous assignments
75
  -- Assigns register values to outputs
76
  Full           <= Full_reg;
77
  Empty          <= Empty_reg;
78
  One_Data_Left  <= One_Data_Left_reg;
79
  One_Place_Left <= One_Place_Left_reg;
80
  -- Concurrent assignment
81
  WR <= Write_Enable & Read_Enable;
82
 
83
 
84
 
85
process (Clk, rst_n)
86
begin  -- process
87
  if rst_n = '0' then                   -- asynchronous reset (active low)
88
    --     for i in depth downto 2 loop
89
    --       input_buffer(i) <= (others => '0');
90
    --     end loop;                    -- i
91
    --    Data_out          <= (others => '0');
92
    Data_Amount        <= 0;
93
    Empty_reg          <= '1';
94
    One_Data_Left_reg  <= '0';
95
    One_Place_Left_reg <= '0';
96
    Full_reg           <= '0';
97
 
98
  elsif Clk'event and Clk = '1' then    -- rising clock edge
99
 
100
    case WR is
101
      when "01"                        =>
102
        -- Read data
103
        if Data_amount = 0 then
104
          -- empty
105
          Data_amount       <= Data_amount;
106
          Empty_reg         <= '1';
107
          One_Data_Left_reg <= '0';
108
        elsif Data_amount = 1 then         -- 1 data
109
          --          Data_out          <= (others => '0');
110
          Data_amount       <= Data_amount-1;
111
          Empty_reg         <= '1';
112
          One_Data_Left_reg <= '0';
113
        elsif Data_amount = 2 then
114
          Data_out          <= input_buffer(Data_amount);
115
          Data_amount       <= Data_amount-1;
116
          Empty_reg         <= '0';
117
          One_Data_Left_reg <= '1';
118
        else
119
          Data_out          <= input_buffer(Data_amount);
120
          Data_amount       <= Data_amount-1;
121
          One_Data_Left_reg <= '0';
122
          Empty_reg         <= '0';
123
        end if;
124
 
125
        if Data_amount = depth-1 then
126
          One_Place_Left_reg <= '0';
127
          Full_reg           <= '0';
128
        elsif Data_amount = depth then
129
          One_Place_Left_reg <= '1';
130
          Full_reg           <= '0';
131
        else
132
          One_Place_Left_reg <= '0';
133
          Full_reg           <= '0';
134
        end if;
135
 
136
 
137
      when "10" =>
138
        -- Write Data
139
        if Data_amount = 0 then
140
          Data_out            <= Data_In;
141
          Data_amount         <= Data_amount+1;
142
        elsif Data_amount = depth then
143
          input_buffer        <= input_buffer;
144
        else
145
          for i in depth-1 downto 2 loop
146
            input_buffer(i+1) <= input_buffer(i);
147
          end loop;  -- i
148
          input_buffer(2)     <= Data_In;
149
          Data_amount         <= Data_amount+1;
150
        end if;
151
 
152
        -- Define the control signals here    
153
 
154
        if Data_amount = 0 then
155
          Empty_reg          <= '0';
156
          One_Data_Left_reg  <= '1';
157
          Full_reg           <= '0';
158
          One_Place_Left_reg <= '0';
159
        elsif Data_amount = 1 then
160
          Empty_reg          <= '0';
161
          One_Data_Left_reg  <= '0';
162
          Full_reg           <= '0';
163
          One_Place_Left_reg <= '0';
164
        elsif Data_amount = depth-2 then
165
          Empty_reg          <= '0';
166
          One_Data_Left_reg  <= '0';
167
          Full_reg           <= '0';
168
          One_Place_Left_reg <= '1';
169
        elsif Data_amount = depth-1 then
170
          Empty_reg          <= '0';
171
          One_Data_Left_reg  <= '0';
172
          Full_reg           <= '1';
173
          One_Place_Left_reg <= '0';
174
        else
175
          Empty_reg          <= Empty_reg;
176
          One_Data_Left_reg  <= One_Data_Left_reg;
177
          Full_reg           <= Full_reg;
178
          One_Place_Left_reg <= One_Place_Left_reg;
179
 
180
        end if;
181
 
182
      when "11" =>
183
        -- Read and Write concurrently
184
 
185
        if Data_amount = 0 then
186
          -- can only write
187
          Data_out           <= Data_in;
188
          Empty_reg          <= '0';
189
          One_Data_Left_reg  <= '1';
190
          Full_reg           <= '0';
191
          One_Place_Left_reg <= '0';
192
          Data_amount <= Data_amount+1;
193
 
194
        elsif Data_amount = 1 then
195
          Data_out           <= Data_In;
196
          Empty_reg          <= '0';
197
          One_Data_Left_reg  <= '1';
198
          Full_reg           <= '0';
199
          One_Place_Left_reg <= '0';
200
 
201
        elsif Data_amount = depth then
202
          -- cannot write if full, just read
203
          Data_out            <= input_buffer (Data_amount);
204
          Data_amount         <= Data_amount-1;
205
          Empty_reg           <= '0';
206
          One_Data_Left_reg   <= '0';
207
          Full_reg            <= '0';
208
          One_Place_Left_reg  <= '1';
209
        else
210
          Data_out            <= input_buffer (Data_amount);
211
          for i in depth-1 downto 2 loop
212
            input_buffer(i+1) <= input_buffer(i);
213
          end loop;  -- i
214
          input_buffer(2)     <= Data_In;
215
          Empty_reg           <= Empty_reg;
216
          One_Data_Left_reg   <= One_Data_Left_reg;
217
          Full_reg            <= Full_reg;
218
          One_Place_Left_reg  <= One_Place_Left_reg;
219
        end if;
220
 
221
      when others =>
222
        -- Do nothing
223
        input_buffer       <= input_buffer;
224
        Data_amount        <= Data_amount;
225
        Empty_reg          <= Empty_reg;
226
        One_Data_Left_reg  <= One_Data_Left_reg;
227
        Full_reg           <= Full_reg;
228
        One_Place_Left_reg <= One_Place_Left_reg;
229
 
230
    end case;
231
 
232
  end if; --synchronous
233
 
234
  end process;
235
 
236
end behavioral;
237
 
238
 
239
 
240
 
241
 
242
 
243
 
244
 
245
 
246
 
247
 
248
 

powered by: WebSVN 2.1.0

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