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

Subversion Repositories srl_fifo

[/] [srl_fifo/] [trunk/] [rtl/] [srl_fifo_32.vhd] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 amulcock
----------------------------------------------------------------------------
2 4 amulcock
----                                                                    ----
3
----                                                                    ----
4
---- This file is part of the srl_fifo project                          ----
5
---- http://www.opencores.org/cores/srl_fifo                            ----
6
----                                                                    ----
7
---- Description                                                        ----
8 2 amulcock
---- Implementation of srl_fifo IP core according to                    ----
9 4 amulcock
---- srl_fifo IP core specification document.                           ----
10
----                                                                    ----
11
---- To Do:                                                             ----
12
----    NA                                                                ----
13
----                                                                    ----
14
---- Author(s):                                                         ----
15
----   Andrew Mulcock, amulcock@opencores.org                           ----
16
----                                                                    ----
17 2 amulcock
----------------------------------------------------------------------------
18 4 amulcock
----                                                                    ----
19
---- Copyright (C) 2008 Authors and OPENCORES.ORG                       ----
20
----                                                                    ----
21
---- This source file may be used and distributed without               ----
22
---- restriction provided that this copyright statement is not          ----
23
---- removed from the file and that any derivative work contains        ----
24
---- the original copyright notice and the associated disclaimer.       ----
25
----                                                                    ----
26
---- This source file is free software; you can redistribute it         ----
27
---- and/or modify it under the terms of the GNU Lesser General         ----
28
---- Public License as published by the Free Software Foundation;       ----
29
---- either version 2.1 of the License, or (at your option) any         ----
30
---- later version.                                                     ----
31
----                                                                    ----
32
---- This source is distributed in the hope that it will be             ----
33
---- useful, but WITHOUT ANY WARRANTY; without even the implied         ----
34
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR            ----
35
---- PURPOSE. See the GNU Lesser General Public License for more        ----
36
---- details.                                                           ----
37
----                                                                    ----
38
---- You should have received a copy of the GNU Lesser General          ----
39
---- Public License along with this source; if not, download it         ----
40
---- from http://www.opencores.org/lgpl.shtml                           ----
41
----                                                                    ----
42 2 amulcock
----------------------------------------------------------------------------
43 4 amulcock
----                                                                    ----
44
-- CVS Revision History                                                 ----
45
----                                                                    ----
46
-- $Log: not supported by cvs2svn $                                                                ----
47
----                                                                    ----
48
----                                                                    ----
49 2 amulcock
-- quick description
50
--
51
--  Based upon the using a shift register as a fifo which has been 
52
--   around for years ( decades ), but really came of use to VHDL 
53
--   when the Xilinx FPGA's started having SRL's. 
54
--
55
--  In my view, the definitive article on shift register logic fifo's 
56
--   comes from Mr Chapman at Xilinx, in the form of his BBFIFO
57
--    tecXeclusive article, which as at early 2008, Xilinx have
58
--     removed.
59
--
60
--
61 4 amulcock
-- using Xilinx ISE 10.1 and later, the tools are getting real clever.
62
--   In previous version of ISE, SRL inferance was not this clever.
63
--     now if one infers a 32 bit srl in a device that has inherantly 16 
64
--      bit srls, then an srl and a series of registers was created.
65
--   In 10,1 and later, if you infer a 32 bit srl for a device with
66
--    16 bit srls in, then you end up with the cascaded srls as expected.
67
--
68
--    Well done Xilinx..
69
--
70 2 amulcock
library IEEE;
71
use IEEE.STD_LOGIC_1164.ALL;
72
use ieee.NUMERIC_STD.all;
73
 
74
entity srl_fifo_32 is
75
    generic ( width : integer := 8 ); -- set to how wide fifo is to be
76
    port(
77
        data_in      : in     std_logic_vector (width -1 downto 0);
78
        data_out     : out    std_logic_vector (width -1 downto 0);
79
        reset        : in     std_logic;
80
        write        : in     std_logic;
81
        read         : in     std_logic;
82
        full         : out    std_logic;
83
        half_full    : out    std_logic;
84
        data_present : out    std_logic;
85
        clk          : in     std_logic
86
    );
87
 
88
-- Declarations
89
 
90
end srl_fifo_32 ;
91
--
92
------------------------------------------------------------------------------------
93
--
94
architecture rtl of srl_fifo_32 is
95
--
96
------------------------------------------------------------------------------------
97
--
98
 
99
 
100
 
101
------------------------------------------------------------------------------------
102
--
103
------------------------------------------------------------------------------------
104
--
105
 
106
constant srl_length  : integer := 32;    -- set to srl 'type' 16 or 32 bit length
107
constant pointer_vec : integer := 5;    -- set to number of bits needed to store pointer = log2(srl_length)
108
 
109
type    srl_array       is array ( srl_length - 1  downto 0 ) of STD_LOGIC_VECTOR ( WIDTH - 1 downto 0 );
110
signal  fifo_store              : srl_array;
111
 
112
signal  pointer            : integer range 0 to srl_length - 1;
113
 
114
signal pointer_zero        : std_logic;
115
signal pointer_full        : std_logic;
116
signal valid_write         : std_logic;
117
signal half_full_int       : std_logic_vector( pointer_vec - 1 downto 0);
118
 
119
signal empty               : std_logic := '1';
120
signal valid_count         : std_logic ;
121
 
122
------------------------------------------------------------------------------------
123
--
124
------------------------------------------------------------------------------------
125
--      
126
begin
127
 
128
 
129
-- Valid write, high when valid to write data to the store.
130
valid_write <= '1' when ( read = '1' and write = '1' )
131
                    or  ( write = '1' and pointer_full = '0' ) else '0';
132
 
133
-- data store SRL's
134
data_srl :process( clk )
135
begin
136
    if rising_edge( clk ) then
137
        if valid_write = '1' then
138
            fifo_store <= fifo_store( fifo_store'left - 1 downto 0) & data_in;
139
        end if;
140
    end if;
141
end process;
142
 
143
data_out <= fifo_store( pointer );
144
 
145
 
146
process( clk)
147
begin
148
    if rising_edge( clk ) then
149
        if reset = '1' then
150
            empty <= '1';
151
        elsif empty = '1' and write = '1' then
152
            empty <= '0';
153
        elsif pointer_zero = '1' and read = '1' and write = '0' then
154
            empty <= '1';
155
        end if;
156
    end if;
157
end process;
158
 
159
 
160
 
161
--      W       R       Action
162
--      0        0        pointer <= pointer
163
--      0        1       pointer <= pointer - 1  Read, but no write, so less data in counter
164
--      1       0        pointer <= pointer + 1  Write, but no read, so more data in fifo
165
--      1       1       pointer <= pointer              Read and write, so same number of words in fifo
166
--
167
 
168
valid_count <= '1' when (
169
                             (write = '1' and read = '0' and pointer_full = '0' and empty = '0' )
170
                        or
171
                             (write = '0' and read = '1' and pointer_zero = '0' )
172
                         ) else '0';
173
process( clk )
174
begin
175
    if rising_edge( clk ) then
176
        if valid_count = '1' then
177
            if write = '1' then
178
                pointer <= pointer + 1;
179
            else
180
                pointer <= pointer - 1;
181
            end if;
182
        end if;
183
    end if;
184
end process;
185
 
186
 
187
  -- Detect when pointer is zero and maximum
188
pointer_zero <= '1' when pointer = 0 else '0';
189
pointer_full <= '1' when pointer = srl_length - 1 else '0';
190
 
191
 
192
 
193
 
194
  -- assign internal signals to outputs
195
  full <= pointer_full;
196
   half_full_int <= std_logic_vector(to_unsigned(pointer, pointer_vec));
197
   half_full <= half_full_int(half_full_int'left);
198
  data_present <= not( empty );
199
 
200
end rtl;
201
 
202
------------------------------------------------------------------------------------
203
--
204
------------------------------------------------------------------------------------
205
 
206
 

powered by: WebSVN 2.1.0

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