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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
 
2
-- !NOTE! output control signals ain't working right in all cases!!
3
 
4
-- use v5 or v6.
5
 
6
-------------------------------------------------------------------------------
7
-- File        : fifo_casev3.vhdl
8
-- Description : Fifo buffer for hibi interface
9
-- Author      : Ari Kulmala
10
-- Date        : 10.06.2003
11
-- Modified    : 18.06.2003 - Re-wrote the way output control signals are
12
--                            assigned
13
--
14
--
15
-- Detailed description:
16
-- -Input and Output always from the same register
17
--   -> input-buffer is shifted whenever write occurs
18
--   -> when read, a mux chooses which value to load to the output next
19
--      (the oldest)
20
--
21
-- !NOTE! isn't tested as one-length FIFO. doesn't probably work. (vector
22
-- length (1 downto 2) ...
23
--
24
-- !NOTE!
25
-- * Output is zero when empty.
26
-------------------------------------------------------------------------------
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
  type reg is array (depth downto 2) of std_logic_vector
58
    (width-1 downto 0);
59
  signal input_buffer : reg;
60
 
61
--  signal output : std_logic_vector (width-1 downto 0);
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
  -- Concurrent assignment
70
  WR <= Write_Enable & Read_Enable;
71
 
72
 
73
 
74
process (Clk, rst_n)
75
begin  -- process
76
  if rst_n = '0' then                   -- asynchronous reset (active low)
77
    for i in depth downto 2 loop
78
      input_buffer(i) <= (others => '0');
79
    end loop;  -- i
80
 
81
    Data_out          <= (others => '0');
82
    Data_Amount       <= 0;
83
    Empty             <= '1';
84
    One_Data_Left     <= '0';
85
    One_Place_Left    <= '0';
86
    Full              <= '0';
87
 
88
  elsif Clk'event and Clk = '1' then    -- rising clock edge
89
 
90
case WR is
91
  when "01" =>                          -- Read data
92
    if Data_amount = 0 then
93
      Data_amount <= Data_amount;
94
    elsif Data_amount = 1 then
95
      Data_out <= (others => '0');
96
      Data_amount <=  Data_amount-1;
97
    else
98
      Data_out <= input_buffer(Data_amount);
99
      Data_amount <=  Data_amount-1;
100
    end if;
101
 
102
 
103
  when "10" =>                              -- Write Data
104
 
105
    if Data_amount = 0 then
106
      Data_out <=  Data_In;
107
      Data_amount <=  Data_amount+1;
108
    elsif Data_amount = depth then
109
      input_buffer <=  input_buffer;
110
    else
111
      for i in depth-1 downto 2 loop
112
        input_buffer(i+1) <=  input_buffer(i);
113
      end loop;  -- i
114
      input_buffer(2) <=  Data_In;
115
      Data_amount <=  Data_amount+1;
116
    end if;
117
 
118
  when "11" =>                              -- Read and Write concurrently
119
 
120
    if Data_amount = 0 then
121
      Data_out <= Data_in;
122
    elsif Data_amount = 1 then
123
      Data_out <=  Data_In;
124
    elsif Data_amount = depth then      -- cannot write if full
125
      Data_out <= input_buffer (Data_amount);
126
      Data_amount <=  Data_amount-1;
127
    else
128
      Data_out <= input_buffer (Data_amount);
129
      for i in depth-1 downto 2 loop
130
        input_buffer(i+1) <=  input_buffer(i);
131
      end loop;  -- i
132
     input_buffer(2) <=  Data_In;
133
    end if;
134
 
135
  when others =>                            -- Do nothing
136
    input_buffer <= input_buffer;
137
    Data_amount <= Data_amount;
138
 
139
end case;
140
 
141
    if Data_amount = 0 then
142
      if Write_Enable = '1' then
143
        Empty          <= '0';
144
        One_Data_Left  <= '1';
145
      else
146
        Empty          <= '1';
147
        One_Place_Left <= '0';
148
      end if;
149
 
150
      One_Data_Left <= '0';
151
      Full          <= '0';
152
 
153
    elsif Data_amount = 1 then
154
      if Read_Enable = '1' then
155
        Empty         <= '1';
156
        One_Data_Left <= '0';
157
      else
158
        Empty         <= '0';
159
        One_Data_Left <= '1';
160
      end if;
161
      if Write_Enable = '1' then
162
        One_Data_Left <= '0';
163
      end if;
164
 
165
      One_Place_Left <= '0';
166
      Full           <= '0';
167
 
168
    elsif Data_amount = 2 then
169
      if Read_Enable = '1' then
170
        One_Data_Left <= '1';
171
      else
172
        One_Data_Left <= '0';
173
      end if;
174
      Empty           <= '0';
175
      One_Place_Left  <= '0';
176
      Full            <= '0';
177
 
178
 
179
    elsif Data_amount = (depth-2) then
180
      Empty            <= '0';
181
      if Write_Enable = '1' then
182
        One_Place_Left <= '1';
183
      else
184
        One_Place_Left <= '0';
185
      end if;
186
 
187
      One_Data_Left    <= '0';
188
      Full             <= '0';
189
    elsif Data_amount = (depth-1) then
190
      Empty            <= '0';
191
      if Read_Enable = '1' or Write_Enable = '1' then
192
        One_Place_Left <= '0';
193
      else
194
        One_Place_Left <= '1';
195
      end if;
196
      One_Data_Left    <= '0';
197
      if Write_Enable = '1' then
198
        Full           <= '1';
199
      else
200
        Full           <= '0';
201
      end if;
202
 
203
    elsif Data_Amount = depth then
204
      if Read_Enable = '1' then
205
        full          <= '0';
206
        One_Data_Left <= '1';
207
      else
208
        full          <= '1';
209
        One_Data_Left <= '0';
210
      end if;
211
      Empty           <= '0';
212
      One_Place_Left  <= '0';
213
 
214
    else
215
      Empty          <= '0';
216
      One_Place_Left <= '0';
217
      One_Data_Left  <= '0';
218
      Full           <= '0';
219
    end if;
220
 
221
  end if; --synchronous
222
 
223
  end process;
224
 
225
end behavioral;
226
 
227
 
228
 
229
 
230
 
231
 
232
 
233
 
234
 
235
 
236
 
237
 

powered by: WebSVN 2.1.0

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