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

Subversion Repositories dirac

[/] [dirac/] [tags/] [dirac_0_0_1_0/] [src/] [common/] [FIFO.vhd] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 petebleack
-- ***** BEGIN LICENSE BLOCK *****
2
-- 
3
-- $Id: FIFO.vhd,v 1.1.1.1 2005-03-30 10:09:49 petebleackley Exp $ $Name: not supported by cvs2svn $
4
-- *
5
-- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6
-- *
7
-- * The contents of this file are subject to the Mozilla Public License
8
-- * Version 1.1 (the "License"); you may not use this file except in compliance
9
-- * with the License. You may obtain a copy of the License at
10
-- * http://www.mozilla.org/MPL/
11
-- *
12
-- * Software distributed under the License is distributed on an "AS IS" basis,
13
-- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14
-- * the specific language governing rights and limitations under the License.
15
-- *
16
-- * The Original Code is BBC Research and Development code.
17
-- *
18
-- * The Initial Developer of the Original Code is the British Broadcasting
19
-- * Corporation.
20
-- * Portions created by the Initial Developer are Copyright (C) 2004.
21
-- * All Rights Reserved.
22
-- *
23
-- * Contributor(s): Peter Bleackley (Original author)
24
-- *
25
-- * Alternatively, the contents of this file may be used under the terms of
26
-- * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
27
-- * Public License Version 2.1 (the "LGPL"), in which case the provisions of
28
-- * the GPL or the LGPL are applicable instead of those above. If you wish to
29
-- * allow use of your version of this file only under the terms of the either
30
-- * the GPL or LGPL and not to allow others to use your version of this file
31
-- * under the MPL, indicate your decision by deleting the provisions above
32
-- * and replace them with the notice and other provisions required by the GPL
33
-- * or LGPL. If you do not delete the provisions above, a recipient may use
34
-- * your version of this file under the terms of any one of the MPL, the GPL
35
-- * or the LGPL.
36
-- * ***** END LICENSE BLOCK ***** */
37
 
38
 
39
library IEEE;
40
use IEEE.STD_LOGIC_1164.ALL;
41
use IEEE.STD_LOGIC_ARITH.ALL;
42
use IEEE.STD_LOGIC_UNSIGNED.ALL;
43
 
44
--  Uncomment the following lines to use the declarations that are
45
--  provided for instantiating Xilinx primitive components.
46
--library UNISIM;
47
--use UNISIM.VComponents.all;
48
 
49
entity FIFO is
50
        generic (RANK : integer range 0 to 16 :=8);
51
    Port ( WRITE_ENABLE : in std_logic;
52
           DATA_IN : in std_logic;
53
           READ_ENABLE : in std_logic;
54
           RESET : in std_logic;
55
           CLOCK : in std_logic;
56
           DATA_OUT : out std_logic;
57
                          EMPTY : out std_logic);
58
end FIFO;
59
 
60
architecture RTL of FIFO is
61
         component      ENABLEABLE_D_TYPE
62
         port (DATA_IN : in std_logic;
63
                        ENABLE : in std_logic;
64
                         CLK : in std_logic;
65
                         DATA_OUT:      out std_logic);
66
        end component ENABLEABLE_D_TYPE;
67
        component D_TYPE
68
        port(    D : in std_logic;
69
           CLOCK : in std_logic;
70
           Q : out std_logic);
71
end component D_TYPE;
72
        component COUNT_UNIT
73
        port(           INCREMENT : in std_logic;
74
           DECREMENT : in std_logic;
75
                          RESET :       in std_logic;
76
           CLOCK : in std_logic;
77
           OUTPUT : out std_logic;
78
           INCREMENT_CARRY : out std_logic;
79
           DECREMENT_CARRY : out std_logic);
80
end component COUNT_UNIT;
81
        function TWO_TO_N(N:    integer) return integer is
82
        variable A:     integer;
83
        begin
84
        A := 1;
85
        for Z in 0 to N - 1 loop
86
        A := 2*A;
87
        end loop;
88
        return A;
89
        end function TWO_TO_N;
90
        function ZERO_VALUE(ADDRESS:    std_logic_vector) return std_logic is
91
        begin
92
        for J in 0 to RANK - 1 loop
93
        if ADDRESS(J) = '1' then
94
        return '0';
95
        end if;
96
        end loop;
97
        return '1';
98
        end function ZERO_VALUE;
99
 
100
        signal READ_ADDRESS :   std_logic_vector (RANK - 1 downto 0);
101
        signal INC :    std_logic_vector (RANK - 1 downto 0);
102
        signal DEC :    std_logic_vector (RANK - 1 downto 0);
103
        type MATRIX is
104
        array (RANK downto 0) of std_logic_vector (TWO_TO_N(RANK) -1 downto 0);
105
        signal GET_OUTPUT: MATRIX;
106
        signal NEWVAL : std_logic_vector(TWO_TO_N(RANK) - 1 downto 0);
107
        signal INCREMENT :      std_logic;
108
        signal DECREMENT :      std_logic;
109
        signal TOGGLE : std_logic;
110
        signal IS_EMPTY :       std_logic;
111
        signal ZERO :   std_logic;
112
        signal NEW_EMPTY : std_logic;
113
        signal EMPTY_OUT :      std_logic;
114
        signal NOWRITE :        std_logic;
115
        signal CHANGED_VALUE : std_logic;
116
        signal EMPTY_IF_READ :  std_logic;
117
        signal LOAD_ENABLE : std_logic;
118
begin
119
-- Storage registers
120
 
121
 
122
BUILD: for I in 0 to RANK -1 generate
123
 
124
LSB:    if I = 0 generate
125
COUNTER : COUNT_UNIT
126
        port map( INCREMENT => INCREMENT,
127
                                DECREMENT => DECREMENT,
128
                                RESET => RESET,
129
                                CLOCK => CLOCK,
130
                                OUTPUT => READ_ADDRESS(I),
131
                                INCREMENT_CARRY => INC(I),
132
                                DECREMENT_CARRY => DEC(I));
133
 
134
        end generate;
135
 
136
OTHER_BITS:     if I > 0 generate
137
COUNTER :       COUNT_UNIT
138
        port map( INCREMENT => INC(I-1),
139
                                DECREMENT => DEC(I-1),
140
                                RESET => RESET,
141
                                CLOCK => CLOCK,
142
                                OUTPUT => READ_ADDRESS(I),
143
                                INCREMENT_CARRY => INC(I),
144
                                DECREMENT_CARRY => DEC(I));
145
        end generate;
146
 
147
MULTIPLEX:      for Z in 0 to TWO_TO_N(I) - 1 generate
148
OUTPUT_SELECT: process(READ_ADDRESS(RANK - I - 1),GET_OUTPUT(RANK - I -1))
149
begin
150
        if READ_ADDRESS(RANK - I - 1) = '1' then
151
                GET_OUTPUT(RANK - I)(Z) <= GET_OUTPUT(RANK - I - 1)(2*Z + 1);
152
        else
153
                GET_OUTPUT(RANK - I)(Z) <= GET_OUTPUT(RANK - I - 1)(2*Z);
154
        end if;
155
end process OUTPUT_SELECT;
156
end generate;
157
 
158
STORAGE: if I = RANK - 1 generate
159
BITS:   for X in 0 to TWO_TO_N(RANK) - 1 generate
160
STORE:  ENABLEABLE_D_TYPE
161
                        port map (DATA_IN => NEWVAL(X),
162
                        ENABLE => LOAD_ENABLE,
163
                        CLK => CLOCK,
164
                        DATA_OUT => GET_OUTPUT(0)(X));
165
MOST_RECENT:    if X = 0 generate
166
        NEWVAL(X) <= DATA_IN and not RESET;
167
end generate;
168
 
169
OLDER_DATA: if X > 0 generate
170
        NEWVAL(X) <= GET_OUTPUT(0)(X-1) and not RESET;
171
end generate;
172
end generate;
173
end generate;
174
 
175
 
176
end generate;
177
 
178
LOAD_ENABLE <= WRITE_ENABLE or RESET;
179
INCREMENT <= WRITE_ENABLE and not (READ_ENABLE or EMPTY_OUT);
180
DECREMENT <= READ_ENABLE and not (WRITE_ENABLE or ZERO);
181
 
182
EMPTY_VALUE:    D_TYPE
183
        port map(D => IS_EMPTY,
184
                                CLOCK => CLOCK,
185
                                Q => EMPTY_OUT);
186
 
187
IS_EMPTY <= NEW_EMPTY or RESET;
188
 
189
SWITCH_EMPTY: process(TOGGLE,EMPTY_OUT,CHANGED_VALUE)
190
begin
191
        if(TOGGLE = '1') then
192
                NEW_EMPTY <= CHANGED_VALUE;
193
        else
194
                NEW_EMPTY <= EMPTY_OUT;
195
        end if;
196
end process SWITCH_EMPTY;
197
 
198
TOGGLE <= WRITE_ENABLE xor READ_ENABLE;
199
CHANGED_VALUE <= EMPTY_IF_READ and NOWRITE;
200
NOWRITE <= not WRITE_ENABLE;
201
EMPTY_IF_READ <= ZERO or EMPTY_OUT;
202
 
203
 
204
ZERO <= ZERO_VALUE(READ_ADDRESS);
205
 
206
EMPTY <= EMPTY_OUT;
207
 
208
DATA_OUT <= GET_OUTPUT(RANK)(0);
209
 
210
 
211
 
212
end RTL;

powered by: WebSVN 2.1.0

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