OpenCores
URL https://opencores.org/ocsvn/memory_cores/memory_cores/trunk

Subversion Repositories memory_cores

[/] [memory_cores/] [trunk/] [FIFO2/] [FIFO_LIB.VHD] - Blame information for rev 25

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 18 olupas
--============================================================================--
2
--
3
--  S Y N T H E Z I A B L E    FIFO controller C O R E
4
--
5
--  www.OpenCores.Org - May 2001
6
--  This core adheres to the GNU public license
7
--
8
-- Design units   : FIFO-Def (Package declaration and body)
9
--
10
-- File name      : FIFO_Lib.vhd
11
--
12
-- Purpose        : This packages defines all the types used for
13
--                the FIFO design which are not contained
14
--                in the IEEE Std_Logic_1164 package.
15
--
16
-- Errors         : None known
17
--
18
-- Library        : FIFO_Lib
19
--
20
-- Dependencies : None
21
--
22
-- Author         : Ovidiu Lupas
23
--                 http://www.opencores.org/people/olupas
24
--                 olupas@opencores.org
25
--
26
-- Simulator     : ModelSim PE/PLUS version 4.7b on a Windows95 PC
27
--------------------------------------------------------------------------------
28
-- Revision list
29
-- Version   Author       Date          Changes
30
--
31
-- 0.1        OL      15 April 99      New model
32
--------------------------------------------------------------------------------
33
--------------------------------------------------------------------------------
34
-- package FIFO_Def
35
--------------------------------------------------------------------------------
36
library IEEE,STD;
37
use IEEE.Std_Logic_1164.all;
38
use IEEE.Numeric_Std.all;
39
--**--
40
package FIFO_Def is
41
      -----------------------------------------------------------------------------
42
      -- function definition
43
      -----------------------------------------------------------------------------
44
      function "+"(left, right : bit_vector)
45
         return bit_vector;
46
      -----------------------------------------------------------------------------
47
      -- Converts unsigned Std_LOGIC_Vector to Integer, leftmost bit is MSB
48
      -- Error message for unknowns (U, X, W, Z, -), converted to 0
49
      -- Verifies whether vector is too long (> 16 bits)
50
      -----------------------------------------------------------------------------
51
      function  BV2Integer (
52
         Invector : in  Std_Logic_Vector(3 downto 0))
53
       return     Integer;
54
      -----------------------------------------------------------------------------
55
      -- Converts unsigned Std_LOGIC_Vector to Integer, leftmost bit is MSB
56
      -- Error message for unknowns (U, X, W, Z, -), converted to 0
57
      -- Verifies whether vector is too long (> 16 bits)
58
      -----------------------------------------------------------------------------
59
      function  ToInteger (
60
         Invector : in  Unsigned(3 downto 0))
61
       return     Integer;
62
      -------------------------------------------------------------------------
63
      -- internal GRAY counter 16 bits - count up
64
      -------------------------------------------------------------------------
65
      component FIFOcnt
66
         port (
67
            ClkIn  : in  Std_Logic;
68
            Reset  : in  Std_Logic;
69
            Load   : in  Std_Logic;
70
            Data16 : in  Bit_Vector(15 downto 0);
71
            CntOut : out Std_Logic);
72
      end component;
73
      ---------------------------------------------------------------------
74
      -- Status counter for FIFO memory
75
      ---------------------------------------------------------------------
76
      component StatCnt
77
         port (
78
            ClkIn    : in   Std_Logic;
79
            Reset    : in   Std_Logic;
80
            Enable   : in   Std_Logic;
81
            UpDown   : in   Std_Logic;
82
            Full     : out  Std_Logic;
83
            Empty    : out  Std_Logic;
84
            AlmFull  : out  Std_Logic;
85
            AlmEmpty : out  Std_Logic);
86
      end component;
87
end FIFO_Def; --================= End of package header ===================--
88
package body FIFO_Def is
89
  -------------------------------------------------------------------------------------
90
  -------------------------------------------------------------------------------------
91
  function "+"(left, right : bit_vector)
92
     return bit_vector is
93
     -- normalize the indexing
94
     alias left_val  : bit_vector(left'length downto 1) is left;
95
     alias right_val : bit_vector(right'length downto 1) is right;
96
     -- arbitrarily make the result the same size as the left input
97
     variable result : bit_vector(left_val'RANGE);
98
     -- temps
99
     variable carry : bit := '0';
100
     variable right_bit : bit;
101
     variable left_bit : bit;
102
  begin
103
     for i in result'reverse_range loop
104
         left_bit := left_val(i);
105
         if (i <= right_val'high) then
106
             right_bit := right_val(i);
107
         else
108
             -- zero extend the right input
109
             right_bit := '0';
110
         end if;
111
         result(i) := (left_bit xor right_bit) xor carry;
112
         carry := (left_bit  and right_bit)
113
                or (left_bit and carry)
114
                or (right_bit and carry);
115
     end loop;
116
     return result;
117
  end "+";
118
  -------------------------------------------------------------------------------------
119
  -------------------------------------------------------------------------------------
120
  --function "+"(left, right : Std_Logic_Vector)
121
  --   return Std_Logic_Vector is
122
  --   -- normalize the indexing
123
  --   alias left_val  : Std_Logic_Vector(left'length downto 1) is left;
124
  --   alias right_val : Std_Logic_Vector(right'length downto 1) is right;
125
  --   -- arbitrarily make the result the same size as the left input
126
  --   variable result : Std_Logic_Vector(left_val'RANGE);
127
  --   -- temps
128
  --   variable carry     : Std_Logic := '0';
129
  --   variable right_bit : Std_Logic;
130
  --   variable left_bit  : Std_Logic;
131
  --begin
132
  --   for i in result'reverse_range loop
133
  --       left_bit := left_val(i);
134
  --       if (i <= right_val'high) then
135
  --           right_bit := right_val(i);
136
  --       else
137
  --           -- zero extend the right input
138
  --           right_bit := '0';
139
  --       end if;
140
  --       result(i) := (left_bit xor right_bit) xor carry;
141
  --       carry := (left_bit  and right_bit)
142
  --              or (left_bit and carry)
143
  --              or (right_bit and carry);
144
  --   end loop;
145
  --   return result;
146
  --end "+";
147
  -------------------------------------------------------------------------------------
148
  -------------------------------------------------------------------------------------
149
  function  BV2Integer (
150
       InVector : in Std_Logic_Vector(3 downto 0))
151
      return  Integer is
152
    constant HeaderMsg   : String          := "To_Integer:";
153
    constant MsgSeverity : Severity_Level  := Warning;
154
    variable Value       : Integer         := 0;
155
  begin
156
    for i in 0 to 3 loop
157
      if (InVector(i) = '1') then
158
         Value := Value + (2**I);
159
      end if;
160
    end loop;
161
    return Value;
162
  end BV2Integer;
163
  -------------------------------------------------------------------------------------
164
  -------------------------------------------------------------------------------------
165
  function  ToInteger (
166
       InVector : in Unsigned(3 downto 0))
167
      return  Integer is
168
    constant HeaderMsg   : String          := "To_Integer:";
169
    constant MsgSeverity : Severity_Level  := Warning;
170
    variable Value       : Integer         := 0;
171
  begin
172
    for i in 0 to 3 loop
173
      if (InVector(i) = '1') then
174
         Value := Value + (2**I);
175
      end if;
176
    end loop;
177
    return Value;
178
  end ToInteger;
179
end FIFO_Def; --================ End of package body ================--
180
library ieee;
181
use ieee.Std_Logic_1164.all;
182
use ieee.Numeric_STD.all;
183
library work;
184
use work.FIFO_Def.all;
185
---------------------------------------------------------------------
186
-- 16-bit GRAY counter
187
---------------------------------------------------------------------
188
entity FIFOcnt is
189
    port (
190
        ClkIn  : in  Std_Logic;
191
        Reset  : in  Std_Logic;
192
        Enable : in  Std_Logic;
193
        CntOut : out Std_Logic_Vector(3 downto 0));
194
end FIFOcnt;
195
-----------------------------------------------------------------------
196
-- Architecture for 16-bit GRAY counter - generates the internal clock
197
-----------------------------------------------------------------------
198
architecture Behaviour of FIFOcnt is
199
  ---------------------------------------------------------------------
200
  -- Signals
201
  ---------------------------------------------------------------------
202
  type CNT_Array is array(0 to 15) of Std_Logic_Vector(3 downto 0);
203
  constant Cnt_Code : CNT_Array := ("0000","0010","0011","0001",
204
                                    "1000","1010","1011","1001",
205
                                    "1100","1110","1111","1101",
206
                                    "0100","0110","0111","0101");
207
  signal binidx : Unsigned(3 downto 0);
208
begin --======================== Architecture =======================--
209
  process(ClkIn,Reset,Enable)
210
  begin
211
     if Reset = '1' then
212
        binidx <= (others => '0');
213
     elsif ClkIn'Event and ClkIn = '1' then
214
        if Enable = '1' then
215
           binidx <= binidx + "1";
216
        end if;
217
     end if;
218
  end process;
219
  CntOut <= Cnt_Code(ToInteger(binidx));
220
end Behaviour; --================ End of architecture ================--
221
 
222
library ieee;
223
use ieee.Std_Logic_1164.all;
224
use ieee.Numeric_STD.all;
225
library work;
226
use work.FIFO_Def.all;
227
---------------------------------------------------------------------
228
-- Up-Down counter for FIFO status
229
---------------------------------------------------------------------
230
entity StatCnt is
231
    port (
232
        ClkIn    : in   Std_Logic;
233
        Reset    : in   Std_Logic;
234
        Enable   : in   Std_Logic;
235
        UpDown   : in   Std_Logic;
236
        Full     : out  Std_Logic;
237
        Empty    : out  Std_Logic;
238
        AlmFull  : out  Std_Logic;
239
        AlmEmpty : out  Std_Logic);
240
end StatCnt;
241
-----------------------------------------------------------------------
242
-- Architecture for 16-bit GRAY counter - generates the internal clock
243
-----------------------------------------------------------------------
244
architecture Behaviour of StatCnt is
245
  ---------------------------------------------------------------------
246
  -- Signals
247
  ---------------------------------------------------------------------
248
  type CNT_Array is array(0 to 15) of Std_Logic_Vector(3 downto 0);
249
  constant Cnt_Code : CNT_Array := ("0000","0001","0010","0011",
250
                                    "0100","0101","0110","0111",
251
                                    "1000","1001","1010","1011",
252
                                    "1100","1101","1110","1111");
253
  signal binidx : Unsigned(3 downto 0);
254
  signal CntOut : Integer;
255
begin --======================== Architecture =======================--
256
  process(ClkIn,Reset,Enable)
257
  begin
258
     if Reset = '1' then
259
        binidx <= (others => '0');
260
     elsif (Rising_Edge(ClkIn) and Enable = '1') then
261
        if UpDown = '1' then
262
           binidx <= binidx + "1";
263
        else
264
           binidx <= binidx - "1";
265
        end if;
266
     end if;
267
     CntOut <= ToInteger(binidx);
268
     case CntOut is
269
         when 0 =>
270
               Empty <= '1';
271
               AlmEmpty <= '0';
272
               AlmFull <= '0';
273
               Full <= '0';
274
         when 1 =>
275
               Empty <= '0';
276
               AlmEmpty <= '1';
277
               AlmFull <= '0';
278
               Full <= '0';
279
         when 2 =>
280
               Empty <= '0';
281
               AlmEmpty <= '1';
282
               AlmFull <= '0';
283
               Full <= '0';
284
         when 13 =>
285
               Empty <= '0';
286
               AlmEmpty <= '0';
287
               AlmFull <= '1';
288
               Full <= '0';
289
         when 14 =>
290
               Empty <= '0';
291
               AlmEmpty <= '0';
292
               AlmFull <= '1';
293
               Full <= '0';
294
         when 15 =>
295
               Empty <= '0';
296
               AlmEmpty <= '0';
297
               AlmFull <= '0';
298
               Full <= '1';
299
         when others =>
300
               Empty <= '0';
301
               AlmEmpty <= '0';
302
               AlmFull <= '0';
303
               Full <= '0';
304
     end case;
305
  end process;
306
end Behaviour; --================ End of architecture ================--

powered by: WebSVN 2.1.0

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