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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-- Fifo with case version 4:
2
-- different from v3:
3
-- - using variable data_amount in order to update it right away,
4
--   rather than wait util the process ends.
5
--
6
-- Designer : Ari Kulmala
7
--
8
-- Variable Data_amount will infer register synthesis! Scary stuff, es 07.11.2003
9
 
10
 
11
 
12
library IEEE;
13
use IEEE.std_logic_1164.all;
14
use IEEE.std_logic_arith.all;
15
 
16
 
17
entity fifo is
18
 
19
  generic (
20
    width : integer := 0;
21
    depth : integer := 0
22
    );
23
  port (
24
    Clk            : in  std_logic;
25
    Rst_n          : in  std_logic;     -- Active low
26
    Data_In        : in  std_logic_vector (width-1 downto 0);
27
    Write_Enable   : in  std_logic;
28
    One_Place_Left : out std_logic;
29
    Full           : out std_logic;
30
    Data_Out       : out std_logic_vector (width-1 downto 0);
31
    Read_Enable    : in  std_logic;
32
    Empty          : out std_logic;
33
    One_Data_Left  : out std_logic
34
    );
35
 
36
end fifo;
37
 
38
architecture behavioral of fifo is
39
 
40
  type reg is array (depth downto 2) of std_logic_vector
41
    (width-1 downto 0);
42
  signal input_buffer : reg;
43
 
44
  signal WR : std_logic_vector ( 1 downto 0);
45
 
46
begin  -- behavioral
47
 
48
  -- Concurrent assignment
49
  WR <= Write_Enable & Read_Enable;
50
 
51
 
52
 
53
  process (Clk, rst_n)
54
    variable Data_amount : integer range 0 to depth;
55
  begin  -- process
56
    if rst_n = '0' then                   -- asynchronous reset (active low)
57
      --     for i in depth downto 2 loop
58
      --       input_buffer(i) <= (others => '0');
59
      --     end loop;  -- i
60
      --     Data_out          <= (others => '0');
61
 
62
      Data_Amount       := 0;
63
      Empty             <= '1';
64
      One_Data_Left     <= '0';
65
      One_Place_Left    <= '0';
66
      Full              <= '0';
67
 
68
    elsif Clk'event and Clk = '1' then    -- rising clock edge
69
 
70
      case WR is
71
        when "01" =>
72
          -- Read data
73
          if Data_amount = 0 then
74
            Data_amount := Data_amount;
75
          elsif Data_amount = 1 then
76
            -- Data_out <= (others => '0');
77
            Data_amount := Data_amount-1;
78
          else
79
            Data_out <= input_buffer(Data_amount);
80
            Data_amount := Data_amount-1;
81
          end if;
82
 
83
 
84
        when "10" =>
85
          -- Write Data
86
          if Data_amount = 0 then
87
            Data_out            <= Data_In;
88
            Data_amount := Data_amount+1;
89
          elsif Data_amount = depth then
90
            input_buffer        <= input_buffer;
91
          else
92
            for i in depth-1 downto 2 loop
93
              input_buffer(i+1) <= input_buffer(i);
94
            end loop;  -- i
95
            input_buffer(2)     <= Data_In;
96
            Data_amount := Data_amount+1;
97
          end if;
98
 
99
        when "11" =>
100
          -- Read and Write concurrently
101
          if Data_amount = 0 then
102
            -- cannot read if empty
103
            Data_out            <= Data_in;
104
            Data_Amount := Data_Amount +1;
105
          elsif Data_amount = 1 then
106
            Data_out            <= Data_In;
107
          elsif Data_amount = depth then
108
            -- cannot write if full
109
            Data_out            <= input_buffer (Data_amount);
110
            Data_amount := Data_amount-1;
111
          else
112
            Data_out            <= input_buffer (Data_amount);
113
            for i in depth-1 downto 2 loop
114
              input_buffer(i+1) <= input_buffer(i);
115
            end loop;  -- i
116
            input_buffer(2)      <= Data_In;
117
          end if;
118
 
119
        when others =>                            -- Do nothing
120
          input_buffer <= input_buffer;
121
          Data_amount := Data_amount;
122
 
123
      end case;
124
 
125
      if Data_amount = 0 then
126
        Empty          <= '1';
127
        One_Place_Left <= '0';
128
        One_Data_Left  <= '0';
129
        Full           <= '0';
130
 
131
      elsif Data_amount = 1 then
132
 
133
        Empty          <= '0';
134
        One_Data_Left  <= '1';
135
        One_Place_Left <= '0';
136
        Full           <= '0';
137
      elsif Data_amount = depth-1 then    --one place left
138
        Empty          <= '0';
139
 
140
        One_Place_Left <= '1';
141
        One_Data_Left  <= '0';
142
        Full           <= '0';
143
      elsif Data_amount = depth then      --full
144
        Empty          <= '0';
145
        One_Place_Left <= '0';
146
        One_Data_Left  <= '0';
147
        Full           <= '1';
148
 
149
 
150
      else
151
        Empty          <= '0';
152
        One_Place_Left <= '0';
153
        One_Data_Left  <= '0';
154
        Full           <= '0';
155
      end if;
156
 
157
    end if; --synchronous
158
 
159
  end process;
160
 
161
end behavioral;
162
 
163
 
164
 
165
 
166
 
167
 
168
 
169
 
170
 
171
 
172
 
173
 

powered by: WebSVN 2.1.0

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