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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- File        : fifo_casev5.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
--
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 is zero when empty.
21
-------------------------------------------------------------------------------
22
 
23
 
24
library IEEE;
25
use IEEE.std_logic_1164.all;
26
use IEEE.std_logic_arith.all;
27
 
28
 
29
entity fifo is
30
 
31
  generic (
32
    width : integer := 0;
33
    depth : integer := 0);
34
 
35
  port (
36
    Clk            : in  std_logic;
37
    Rst_n          : in  std_logic;     -- Active low
38
    Data_In        : in  std_logic_vector (width-1 downto 0);
39
    Write_Enable   : in  std_logic;
40
    One_Place_Left : out std_logic;
41
    Full           : out std_logic;
42
    Data_Out       : out std_logic_vector (width-1 downto 0);
43
    Read_Enable    : in  std_logic;
44
    Empty          : out std_logic;
45
    One_Data_Left  : out std_logic
46
    );
47
 
48
end fifo;
49
 
50
 
51
architecture behavioral of fifo is
52
 
53
  -- range is this so that one can use data_amount directly to indexing
54
  type reg is array (depth downto 2) of std_logic_vector
55
    (width-1 downto 0);
56
  signal input_buffer       : reg;
57
  -- Registers
58
  signal Full_reg           : std_logic;
59
  signal Empty_reg          : std_logic;
60
  signal One_Data_Left_reg  : std_logic;
61
  signal One_Place_Left_reg : std_logic;
62
  signal Data_amount        : integer range 0 to depth;
63
 
64
 
65
  signal WR : std_logic_vector ( 1 downto 0);
66
 
67
begin  -- behavioral
68
 
69
  -- Continuous assignments
70
  -- Assigns register values to outputs
71
  Full           <= Full_reg;
72
  Empty          <= Empty_reg;
73
  One_Data_Left  <= One_Data_Left_reg;
74
  One_Place_Left <= One_Place_Left_reg;
75
  -- Concurrent assignment
76
  WR <= Write_Enable & Read_Enable;
77
 
78
 
79
 
80
  process (Clk, rst_n)
81
  begin  -- process
82
    if rst_n = '0' then                   -- asynchronous reset (active low)
83
      for i in depth downto 2 loop
84
        input_buffer(i) <= (others => '0');
85
      end loop;  -- i
86
      Data_out           <= (others => '0');
87
 
88
      Data_Amount        <= 0;
89
      Empty_reg          <= '1';
90
      One_Data_Left_reg  <= '0';
91
      One_Place_Left_reg <= '0';
92
      Full_reg           <= '0';
93
 
94
    elsif Clk'event and Clk = '1' then    -- rising clock edge
95
 
96
      case WR is
97
        when "01"                        =>
98
          -- Read data
99
          if Data_amount = 0 then
100
            -- empty
101
            Data_amount       <= Data_amount;
102
            Empty_reg         <= '1';
103
            One_Data_Left_reg <= '0';
104
          elsif Data_amount = 1 then
105
            -- 1 data
106
            Data_out          <= (others => '0');
107
            Data_amount       <= Data_amount-1;
108
            Empty_reg         <= '1';
109
            One_Data_Left_reg <= '0';
110
          elsif Data_amount = 2 then
111
            Data_out          <= input_buffer(Data_amount);
112
            Data_amount       <= Data_amount-1;
113
            Empty_reg         <= '0';
114
            One_Data_Left_reg <= '1';
115
          else
116
            Data_out          <= input_buffer(Data_amount);
117
            Data_amount       <= Data_amount-1;
118
            One_Data_Left_reg <= '0';
119
            Empty_reg         <= '0';
120
          end if;
121
 
122
          -- Fifo's getting emptier          
123
          if Data_amount = depth-1 then
124
            One_Place_Left_reg <= '0';
125
            Full_reg           <= '0';
126
          elsif Data_amount = depth then
127
            One_Place_Left_reg <= '1';
128
            Full_reg           <= '0';
129
          else
130
            One_Place_Left_reg <= '0';
131
            Full_reg           <= '0';
132
          end if;
133
 
134
 
135
        when "10" =>
136
          -- Write Data
137
          if Data_amount = 0 then
138
            Data_out            <= Data_In;
139
            Data_amount         <= Data_amount+1;
140
          elsif Data_amount = depth then
141
            input_buffer        <= input_buffer;
142
          else
143
            for i in depth-1 downto 2 loop
144
              input_buffer(i+1) <= input_buffer(i);
145
            end loop;  -- i
146
            input_buffer(2)     <= Data_In;
147
            Data_amount         <= Data_amount+1;
148
          end if;
149
 
150
          -- define the values for output control signals          
151
          if Data_amount = 0 then
152
            Empty_reg          <= '0';
153
            One_Data_Left_reg  <= '1';
154
            Full_reg           <= '0';
155
            One_Place_Left_reg <= '0';
156
          elsif Data_amount = 1 then
157
            Empty_reg          <= '0';
158
            One_Data_Left_reg  <= '0';
159
            Full_reg           <= '0';
160
            One_Place_Left_reg <= '0';
161
          elsif Data_amount = depth-2 then
162
            Empty_reg          <= '0';
163
            One_Data_Left_reg  <= '0';
164
            Full_reg           <= '0';
165
            One_Place_Left_reg <= '1';
166
          elsif Data_amount = depth-1 then
167
            Empty_reg          <= '0';
168
            One_Data_Left_reg  <= '0';
169
            Full_reg           <= '1';
170
            One_Place_Left_reg <= '0';
171
          else
172
            Empty_reg          <= Empty_reg;
173
            One_Data_Left_reg  <= One_Data_Left_reg;
174
            Full_reg           <= Full_reg;
175
            One_Place_Left_reg <= One_Place_Left_reg;
176
          end if;
177
 
178
        when "11" =>
179
          -- Read and Write concurrently
180
 
181
          if Data_amount = 0 then
182
            -- can only write
183
            Data_out           <= Data_in;
184
            Empty_reg          <= '0';
185
            One_Data_Left_reg  <= '1';
186
            Full_reg           <= '0';
187
            One_Place_Left_reg <= '0';
188
            Data_amount <= Data_amount+1;
189
 
190
          elsif Data_amount = 1 then
191
            Data_out           <= Data_In;
192
            Empty_reg          <= '0';
193
            One_Data_Left_reg  <= '1';
194
            Full_reg           <= '0';
195
            One_Place_Left_reg <= '0';
196
 
197
          elsif Data_amount = depth then
198
            -- cannot write if full, just read
199
            Data_out            <= input_buffer (Data_amount);
200
            Data_amount         <= Data_amount-1;
201
            Empty_reg           <= '0';
202
            One_Data_Left_reg   <= '0';
203
            Full_reg            <= '0';
204
            One_Place_Left_reg  <= '1';
205
          else
206
            Data_out            <= input_buffer (Data_amount);
207
            for i in depth-1 downto 2 loop
208
              input_buffer(i+1) <= input_buffer(i);
209
            end loop;  -- i
210
            input_buffer(2)     <= Data_In;
211
            Empty_reg           <= Empty_reg;
212
            One_Data_Left_reg   <= One_Data_Left_reg;
213
            Full_reg            <= Full_reg;
214
            One_Place_Left_reg  <= One_Place_Left_reg;
215
          end if;
216
 
217
        when others =>
218
          -- Do nothing, write and read low
219
          input_buffer       <= input_buffer;
220
          Data_amount        <= Data_amount;
221
          Empty_reg          <= Empty_reg;
222
          One_Data_Left_reg  <= One_Data_Left_reg;
223
          Full_reg           <= Full_reg;
224
          One_Place_Left_reg <= One_Place_Left_reg;
225
 
226
      end case;
227
    end if; --synchronous
228
  end process;
229
 
230
end behavioral;
231
 
232
 
233
 
234
 
235
 
236
 
237
 
238
 
239
 
240
 
241
 
242
 

powered by: WebSVN 2.1.0

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