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

Subversion Repositories generic_fifos

[/] [generic_fifos/] [trunk/] [rtl/] [verilog/] [generic_fifo_sc_b.v] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rudi
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  Universal FIFO Single Clock                                ////
4
////                                                             ////
5
////                                                             ////
6
////  Author: Rudolf Usselmann                                   ////
7
////          rudi@asics.ws                                      ////
8
////                                                             ////
9
////                                                             ////
10
////  D/L from: http://www.opencores.org/cores/generic_fifos/    ////
11
////                                                             ////
12
/////////////////////////////////////////////////////////////////////
13
////                                                             ////
14
//// Copyright (C) 2000-2002 Rudolf Usselmann                    ////
15
////                         www.asics.ws                        ////
16
////                         rudi@asics.ws                       ////
17
////                                                             ////
18
//// This source file may be used and distributed without        ////
19
//// restriction provided that this copyright statement is not   ////
20
//// removed from the file and that any derivative work contains ////
21
//// the original copyright notice and the associated disclaimer.////
22
////                                                             ////
23
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
24
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
25
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
26
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
27
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
28
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
29
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
30
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
31
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
32
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
33
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
34
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
35
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
36
////                                                             ////
37
/////////////////////////////////////////////////////////////////////
38
 
39
//  CVS Log
40
//
41
//  $Id: generic_fifo_sc_b.v,v 1.1.1.1 2002-09-25 05:42:04 rudi Exp $
42
//
43
//  $Date: 2002-09-25 05:42:04 $
44
//  $Revision: 1.1.1.1 $
45
//  $Author: rudi $
46
//  $Locker:  $
47
//  $State: Exp $
48
//
49
// Change History:
50
//               $Log: not supported by cvs2svn $
51
//
52
//
53
//
54
//
55
//
56
//
57
//
58
//
59
//
60
//
61
 
62
`include "timescale.v"
63
 
64
/*
65
 
66
Description
67
===========
68
 
69
I/Os
70
----
71
rst     low active, either sync. or async. master reset (see below how to select)
72
clr     synchronous clear (just like reset but always synchronous), high active
73
re      read enable, synchronous, high active
74
we      read enable, synchronous, high active
75
din     Data Input
76
dout    Data Output
77
 
78
full    Indicates the FIFO is full (combinatorial output)
79
full_r  same as above, but registered output (see note below)
80
empty   Indicates the FIFO is empty
81
empty_r same as above, but registered output (see note below)
82
 
83
full_n          Indicates if the FIFO has space for N entries (combinatorial output)
84
full_n_r        same as above, but registered output (see note below)
85
empty_n         Indicates the FIFO has at least N entries (combinatorial output)
86
empty_n_r       same as above, but registered output (see note below)
87
 
88
level           indicates the FIFO level:
89
                2'b00   0-25%    full
90
                2'b01   25-50%   full
91
                2'b10   50-75%   full
92
                2'b11   %75-100% full
93
 
94
combinatorial vs. registered status outputs
95
-------------------------------------------
96
Both the combinatorial and registered status outputs have the same
97
basic functionality. The registered outputs are de-asserted with a
98
1 cycle delay for full_r and empty_r, and a 2 cycle delay for full_n_r
99
and empty_n_r.
100
The combinatorial outputs however, pass through several levels of
101
logic before they are output. The registered status outputs are
102
direct outputs of a flip-flop. The reason both are provided, is
103
that the registered outputs require additional logic inside the
104
FIFO. If you can meet timing of your device with the combinatorial
105
outputs, use them ! The FIFO will be smaller. If the status signals
106
are in the critical pass, use the registered outputs, they have a
107
much smaller output delay (actually only Tcq).
108
 
109
Parameters
110
----------
111
The FIFO takes 3 parameters:
112
dw      Data bus width
113
aw      Address bus width (Determines the FIFO size by evaluating 2^aw)
114
n       N is a second status threshold constant for full_n and empty_n
115
        If you have no need for the second status threshold, do not
116
        connect the outputs and the logic should be removed by your
117
        synthesis tool.
118
 
119
Synthesis Results
120
-----------------
121
In a Spartan 2e a 8 bit wide, 8 entries deep FIFO, takes 85 LUTs and runs
122
at about 116 MHz (IO insertion disabled). The registered status outputs
123
are valid after 2.1NS, the combinatorial once take out to 6.5 NS to be
124
available.
125
 
126
 
127
Misc
128
----
129
This design assumes you will do appropriate status checking externally.
130
 
131
IMPORTANT ! writing while the FIFO is full or reading while the FIFO is
132
empty will place the FIFO in an undefined state.
133
 
134
*/
135
 
136
 
137
// Selecting Sync. or Async Reset
138
// ------------------------------
139
// Uncomment one of the two lines below. The first line for
140
// synchronous reset, the second for asynchronous reset
141
 
142
`define SC_FIFO_ASYNC_RESET                             // Uncomment for Syncr. reset
143
//`define SC_FIFO_ASYNC_RESET   or negedge rst          // Uncomment for Async. reset
144
 
145
 
146
module generic_fifo_sc_b(clk, rst, clr, din, we, dout, re,
147
                        full, empty, full_r, empty_r,
148
                        full_n, empty_n, full_n_r, empty_n_r,
149
                        level);
150
 
151
parameter dw=8;
152
parameter aw=8;
153
parameter n=32;
154
parameter max_size = 1<<aw;
155
 
156
input                   clk, rst, clr;
157
input   [dw-1:0] din;
158
input                   we;
159
output  [dw-1:0] dout;
160
input                   re;
161
output                  full, full_r;
162
output                  empty, empty_r;
163
output                  full_n, full_n_r;
164
output                  empty_n, empty_n_r;
165
output  [1:0]            level;
166
 
167
////////////////////////////////////////////////////////////////////
168
//
169
// Local Wires
170
//
171
 
172
reg     [aw:0]   wp;
173
wire    [aw:0]   wp_pl1;
174
reg     [aw:0]   rp;
175
wire    [aw:0]   rp_pl1;
176
reg             full_r;
177
reg             empty_r;
178
wire    [aw:0]   diff;
179
reg     [aw:0]   diff_r;
180
reg             re_r, we_r;
181
wire            full_n, empty_n;
182
reg             full_n_r, empty_n_r;
183
reg     [1:0]    level;
184
 
185
////////////////////////////////////////////////////////////////////
186
//
187
// Memory Block
188
//
189
 
190
generic_dpram  #(aw,dw) u0(
191
        .rclk(          clk             ),
192
        .rrst(          !rst            ),
193
        .rce(           1'b1            ),
194
        .oe(            1'b1            ),
195
        .raddr(         rp[aw-1:0]       ),
196
        .do(            dout            ),
197
        .wclk(          clk             ),
198
        .wrst(          !rst            ),
199
        .wce(           1'b1            ),
200
        .we(            we              ),
201
        .waddr(         wp[aw-1:0]       ),
202
        .di(            din             )
203
        );
204
 
205
////////////////////////////////////////////////////////////////////
206
//
207
// Misc Logic
208
//
209
 
210
always @(posedge clk `SC_FIFO_ASYNC_RESET)
211
        if(!rst)        wp <= #1 {aw+1{1'b0}};
212
        else
213
        if(clr)         wp <= #1 {aw+1{1'b0}};
214
        else
215
        if(we)          wp <= #1 wp_pl1;
216
 
217
assign wp_pl1 = wp + { {aw{1'b0}}, 1'b1};
218
 
219
always @(posedge clk `SC_FIFO_ASYNC_RESET)
220
        if(!rst)        rp <= #1 {aw+1{1'b0}};
221
        else
222
        if(clr)         rp <= #1 {aw+1{1'b0}};
223
        else
224
        if(re)          rp <= #1 rp_pl1;
225
 
226
assign rp_pl1 = rp + { {aw{1'b0}}, 1'b1};
227
 
228
////////////////////////////////////////////////////////////////////
229
//
230
// Combinatorial Full & Empty Flags
231
//
232
 
233
assign empty = (wp == rp);
234
assign full  = (wp[aw-1:0] == rp[aw-1:0]) & (wp[aw] != rp[aw]);
235
 
236
////////////////////////////////////////////////////////////////////
237
//
238
// Registered Full & Empty Flags
239
//
240
 
241
always @(posedge clk)
242
        empty_r <= #1 (wp == rp) | (re & (wp == rp_pl1));
243
 
244
always @(posedge clk)
245
        full_r <= #1 ((wp[aw-1:0] == rp[aw-1:0]) & (wp[aw] != rp[aw])) |
246
        (we & (wp_pl1[aw-1:0] == rp[aw-1:0]) & (wp_pl1[aw] != rp[aw]));
247
 
248
////////////////////////////////////////////////////////////////////
249
//
250
// Combinatorial Full_n & Empty_n Flags
251
//
252
 
253
assign diff = wp-rp;
254
assign empty_n = diff < n;
255
assign full_n  = !(diff < (max_size-n+1));
256
 
257
always @(posedge clk)
258
        level <= #1 {2{diff[aw]}} | diff[aw-1:aw-2];
259
 
260
////////////////////////////////////////////////////////////////////
261
//
262
// Registered Full_n & Empty_n Flags
263
//
264
 
265
always @(posedge clk)
266
        re_r <= #1 re;
267
 
268
always @(posedge clk)
269
        diff_r <= #1 diff;
270
 
271
always @(posedge clk)
272
        empty_n_r <= #1 (diff_r < n) | ((diff_r==n) & (re | re_r));
273
 
274
always @(posedge clk)
275
        we_r <= #1 we;
276
 
277
always @(posedge clk)
278
        full_n_r <= #1 (diff_r > max_size-n) | ((diff_r==max_size-n) & (we | we_r));
279
 
280
////////////////////////////////////////////////////////////////////
281
//
282
// Sanity Check
283
//
284
 
285
// synopsys translate_off
286
always @(posedge clk)
287
        if(we & full)
288
                $display("%m WARNING: Writing while fifo is FULL (%t)",$time);
289
 
290
always @(posedge clk)
291
        if(re & empty)
292
                $display("%m WARNING: Reading while fifo is EMPTY (%t)",$time);
293
// synopsys translate_on
294
 
295
endmodule
296
 

powered by: WebSVN 2.1.0

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