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

Subversion Repositories srl_fifo

[/] [srl_fifo/] [branches/] [avendor/] [rtl/] [srl_fifo_16.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
 
71
library IEEE;
72
use IEEE.STD_LOGIC_1164.ALL;
73
use ieee.NUMERIC_STD.all;
74
 
75
entity srl_fifo_16 is
76
    generic ( width : integer := 8 ); -- set to how wide fifo is to be
77
    port(
78
        data_in      : in     std_logic_vector (width -1 downto 0);
79
        data_out     : out    std_logic_vector (width -1 downto 0);
80
        reset        : in     std_logic;
81
        write        : in     std_logic;
82
        read         : in     std_logic;
83
        full         : out    std_logic;
84
        half_full    : out    std_logic;
85
        data_present : out    std_logic;
86
        clk          : in     std_logic
87
    );
88
 
89
-- Declarations
90
 
91
end srl_fifo_16 ;
92
--
93
------------------------------------------------------------------------------------
94
--
95
architecture rtl of srl_fifo_16 is
96
--
97
------------------------------------------------------------------------------------
98
--
99
 
100
 
101
 
102
------------------------------------------------------------------------------------
103
--
104
------------------------------------------------------------------------------------
105
--
106
 
107
constant srl_length  : integer := 16;    -- set to srl 'type' 16 or 32 bit length
108
constant pointer_vec : integer := 4;    -- set to number of bits needed to store pointer = log2(srl_length)
109
 
110
type    srl_array       is array ( srl_length - 1  downto 0 ) of STD_LOGIC_VECTOR ( WIDTH - 1 downto 0 );
111
signal  fifo_store              : srl_array;
112
 
113
signal  pointer            : integer range 0 to srl_length - 1;
114
 
115
signal pointer_zero        : std_logic;
116
signal pointer_full        : std_logic;
117
signal valid_write         : std_logic;
118
signal half_full_int       : std_logic_vector( pointer_vec - 1 downto 0);
119
 
120
signal empty               : std_logic := '1';
121
signal valid_count         : std_logic ;
122
 
123
------------------------------------------------------------------------------------
124
--
125
------------------------------------------------------------------------------------
126
--      
127
begin
128
 
129
 
130
-- Valid write, high when valid to write data to the store.
131
valid_write <= '1' when ( read = '1' and write = '1' )
132
                    or  ( write = '1' and pointer_full = '0' ) else '0';
133
 
134
-- data store SRL's
135
data_srl :process( clk )
136
begin
137
    if rising_edge( clk ) then
138
        if valid_write = '1' then
139
            fifo_store <= fifo_store( fifo_store'left - 1 downto 0) & data_in;
140
        end if;
141
    end if;
142
end process;
143
 
144
data_out <= fifo_store( pointer );
145
 
146
 
147
process( clk)
148
begin
149
    if rising_edge( clk ) then
150
        if reset = '1' then
151
            empty <= '1';
152
        elsif empty = '1' and write = '1' then
153
            empty <= '0';
154
        elsif pointer_zero = '1' and read = '1' and write = '0' then
155
            empty <= '1';
156
        end if;
157
    end if;
158
end process;
159
 
160
 
161
 
162
--      W       R       Action
163
--      0        0        pointer <= pointer
164
--      0        1       pointer <= pointer - 1  Read, but no write, so less data in counter
165
--      1       0        pointer <= pointer + 1  Write, but no read, so more data in fifo
166
--      1       1       pointer <= pointer              Read and write, so same number of words in fifo
167
--
168
 
169
valid_count <= '1' when (
170
                             (write = '1' and read = '0' and pointer_full = '0' and empty = '0' )
171
                        or
172
                             (write = '0' and read = '1' and pointer_zero = '0' )
173
                         ) else '0';
174
process( clk )
175
begin
176
    if rising_edge( clk ) then
177
        if valid_count = '1' then
178
            if write = '1' then
179
                pointer <= pointer + 1;
180
            else
181
                pointer <= pointer - 1;
182
            end if;
183
        end if;
184
    end if;
185
end process;
186
 
187
 
188
  -- Detect when pointer is zero and maximum
189
pointer_zero <= '1' when pointer = 0 else '0';
190
pointer_full <= '1' when pointer = srl_length - 1 else '0';
191
 
192
 
193
 
194
 
195
  -- assign internal signals to outputs
196
  full <= pointer_full;
197
   half_full_int <= std_logic_vector(to_unsigned(pointer, pointer_vec));
198
   half_full <= half_full_int(half_full_int'left);
199
  data_present <= not( empty );
200
 
201
end rtl;
202
 
203
------------------------------------------------------------------------------------
204
--
205
------------------------------------------------------------------------------------
206
 
207
 

powered by: WebSVN 2.1.0

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