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

Subversion Repositories mpeg2fpga

[/] [mpeg2fpga/] [trunk/] [bench/] [iverilog/] [generic_fifo_sc_b.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kdv
/////////////////////////////////////////////////////////////////////
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: generic_fifo_sc_b.v,v $
51
//               Revision 1.1.1.1  2002/09/25 05:42:04  rudi
52
//               Initial Checkin
53
//
54
//
55
//
56
//
57
//
58
//
59
//
60
//
61
//
62
//
63
//
64
 
65
`include "timescale.v"
66
 
67
/*
68
 
69
Description
70
===========
71
 
72
I/Os
73
----
74
rst     low active, either sync. or async. master reset (see below how to select)
75
clr     synchronous clear (just like reset but always synchronous), high active
76
re      read enable, synchronous, high active
77
we      read enable, synchronous, high active
78
din     Data Input
79
dout    Data Output
80
 
81
full    Indicates the FIFO is full (combinatorial output)
82
full_r  same as above, but registered output (see note below)
83
empty   Indicates the FIFO is empty
84
empty_r same as above, but registered output (see note below)
85
 
86
full_n          Indicates if the FIFO has space for N entries (combinatorial output)
87
full_n_r        same as above, but registered output (see note below)
88
empty_n         Indicates the FIFO has at least N entries (combinatorial output)
89
empty_n_r       same as above, but registered output (see note below)
90
 
91
level           indicates the FIFO level:
92
                2'b00   0-25%    full
93
                2'b01   25-50%   full
94
                2'b10   50-75%   full
95
                2'b11   %75-100% full
96
 
97
combinatorial vs. registered status outputs
98
-------------------------------------------
99
Both the combinatorial and registered status outputs have the same
100
basic functionality. The registered outputs are de-asserted with a
101
1 cycle delay for full_r and empty_r, and a 2 cycle delay for full_n_r
102
and empty_n_r.
103
The combinatorial outputs however, pass through several levels of
104
logic before they are output. The registered status outputs are
105
direct outputs of a flip-flop. The reason both are provided, is
106
that the registered outputs require additional logic inside the
107
FIFO. If you can meet timing of your device with the combinatorial
108
outputs, use them ! The FIFO will be smaller. If the status signals
109
are in the critical pass, use the registered outputs, they have a
110
much smaller output delay (actually only Tcq).
111
 
112
Parameters
113
----------
114
The FIFO takes 3 parameters:
115
dw      Data bus width
116
aw      Address bus width (Determines the FIFO size by evaluating 2^aw)
117
n       N is a second status threshold constant for full_n and empty_n
118
        If you have no need for the second status threshold, do not
119
        connect the outputs and the logic should be removed by your
120
        synthesis tool.
121
 
122
Synthesis Results
123
-----------------
124
In a Spartan 2e a 8 bit wide, 8 entries deep FIFO, takes 85 LUTs and runs
125
at about 116 MHz (IO insertion disabled). The registered status outputs
126
are valid after 2.1NS, the combinatorial once take out to 6.5 NS to be
127
available.
128
 
129
 
130
Misc
131
----
132
This design assumes you will do appropriate status checking externally.
133
 
134
IMPORTANT ! writing while the FIFO is full or reading while the FIFO is
135
empty will place the FIFO in an undefined state.
136
 
137
*/
138
 
139
 
140
// Selecting Sync. or Async Reset
141
// ------------------------------
142
// Uncomment one of the two lines below. The first line for
143
// synchronous reset, the second for asynchronous reset
144
 
145
`define SC_FIFO_ASYNC_RESET                             // Uncomment for Syncr. reset
146
//`define SC_FIFO_ASYNC_RESET   or negedge rst          // Uncomment for Async. reset
147
 
148
 
149
module generic_fifo_sc_b(clk, rst, clr, din, we, dout, re,
150
                        full, empty, full_r, empty_r,
151
                        full_n, empty_n, full_n_r, empty_n_r,
152
                        level);
153
 
154
parameter dw=8;
155
parameter aw=8;
156
parameter n=32;
157
parameter max_size = 1<<aw;
158
 
159
input                   clk, rst, clr;
160
input   [dw-1:0] din;
161
input                   we;
162
output  [dw-1:0] dout;
163
input                   re;
164
output                  full, full_r;
165
output                  empty, empty_r;
166
output                  full_n, full_n_r;
167
output                  empty_n, empty_n_r;
168
output  [1:0]            level;
169
 
170
////////////////////////////////////////////////////////////////////
171
//
172
// Local Wires
173
//
174
 
175
reg     [aw:0]   wp;
176
wire    [aw:0]   wp_pl1;
177
reg     [aw:0]   rp;
178
wire    [aw:0]   rp_pl1;
179
reg             full_r;
180
reg             empty_r;
181
wire    [aw:0]   diff;
182
reg     [aw:0]   diff_r;
183
reg             re_r, we_r;
184
wire            full_n, empty_n;
185
reg             full_n_r, empty_n_r;
186
reg     [1:0]    level;
187
 
188
////////////////////////////////////////////////////////////////////
189
//
190
// Memory Block
191
//
192
 
193
generic_dpram  #(aw,dw) u0(
194
        .rclk(          clk             ),
195
        .rrst(          !rst            ),
196
        .rce(           1'b1            ),
197
        .oe(            1'b1            ),
198
        .raddr(         rp[aw-1:0]       ),
199
        .do(            dout            ),
200
        .wclk(          clk             ),
201
        .wrst(          !rst            ),
202
        .wce(           1'b1            ),
203
        .we(            we              ),
204
        .waddr(         wp[aw-1:0]       ),
205
        .di(            din             )
206
        );
207
 
208
////////////////////////////////////////////////////////////////////
209
//
210
// Misc Logic
211
//
212
 
213
always @(posedge clk `SC_FIFO_ASYNC_RESET)
214
        if(!rst)        wp <= #1 {aw+1{1'b0}};
215
        else
216
        if(clr)         wp <= #1 {aw+1{1'b0}};
217
        else
218
        if(we)          wp <= #1 wp_pl1;
219
 
220
assign wp_pl1 = wp + { {aw{1'b0}}, 1'b1};
221
 
222
always @(posedge clk `SC_FIFO_ASYNC_RESET)
223
        if(!rst)        rp <= #1 {aw+1{1'b0}};
224
        else
225
        if(clr)         rp <= #1 {aw+1{1'b0}};
226
        else
227
        if(re)          rp <= #1 rp_pl1;
228
 
229
assign rp_pl1 = rp + { {aw{1'b0}}, 1'b1};
230
 
231
////////////////////////////////////////////////////////////////////
232
//
233
// Combinatorial Full & Empty Flags
234
//
235
 
236
assign empty = (wp == rp);
237
assign full  = (wp[aw-1:0] == rp[aw-1:0]) & (wp[aw] != rp[aw]);
238
 
239
////////////////////////////////////////////////////////////////////
240
//
241
// Registered Full & Empty Flags
242
//
243
 
244
always @(posedge clk)
245
        empty_r <= #1 (wp == rp) | (re & (wp == rp_pl1));
246
 
247
always @(posedge clk)
248
        full_r <= #1 ((wp[aw-1:0] == rp[aw-1:0]) & (wp[aw] != rp[aw])) |
249
        (we & (wp_pl1[aw-1:0] == rp[aw-1:0]) & (wp_pl1[aw] != rp[aw]));
250
 
251
////////////////////////////////////////////////////////////////////
252
//
253
// Combinatorial Full_n & Empty_n Flags
254
//
255
 
256
assign diff = wp-rp;
257
assign empty_n = diff < n;
258
assign full_n  = !(diff < (max_size-n+1));
259
 
260
always @(posedge clk)
261
        level <= #1 {2{diff[aw]}} | diff[aw-1:aw-2];
262
 
263
////////////////////////////////////////////////////////////////////
264
//
265
// Registered Full_n & Empty_n Flags
266
//
267
 
268
always @(posedge clk)
269
        re_r <= #1 re;
270
 
271
always @(posedge clk)
272
        diff_r <= #1 diff;
273
 
274
always @(posedge clk)
275
        empty_n_r <= #1 (diff_r < n) | ((diff_r==n) & (re | re_r));
276
 
277
always @(posedge clk)
278
        we_r <= #1 we;
279
 
280
always @(posedge clk)
281
        full_n_r <= #1 (diff_r > max_size-n) | ((diff_r==max_size-n) & (we | we_r));
282
 
283
////////////////////////////////////////////////////////////////////
284
//
285
// Sanity Check
286
//
287
 
288
// synopsys translate_off
289
always @(posedge clk)
290
        if(we & full)
291
                $display("%m WARNING: Writing while fifo is FULL (%t)",$time);
292
 
293
always @(posedge clk)
294
        if(re & empty)
295
                $display("%m WARNING: Reading while fifo is EMPTY (%t)",$time);
296
// synopsys translate_on
297
 
298
endmodule
299
 

powered by: WebSVN 2.1.0

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