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

Subversion Repositories mpeg2fpga

[/] [mpeg2fpga/] [trunk/] [bench/] [iverilog/] [generic_fifo_dc.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_dc.v,v 1.1.1.1 2002/09/25 05:42:02 rudi Exp $
42
//
43
//  $Date: 2002/09/25 05:42:02 $
44
//  $Revision: 1.1.1.1 $
45
//  $Author: rudi $
46
//  $Locker:  $
47
//  $State: Exp $
48
//
49
// Change History:
50
//               $Log: generic_fifo_dc.v,v $
51
//               Revision 1.1.1.1  2002/09/25 05:42:02  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
rd_clk  Read Port Clock
75
wr_clk  Write Port Clock
76
rst     low active, either sync. or async. master reset (see below how to select)
77
clr     synchronous clear (just like reset but always synchronous), high active
78
re      read enable, synchronous, high active
79
we      read enable, synchronous, high active
80
din     Data Input
81
dout    Data Output
82
 
83
full    Indicates the FIFO is full (driven at the rising edge of wr_clk)
84
empty   Indicates the FIFO is empty (driven at the rising edge of rd_clk)
85
 
86
full_n  Indicates if the FIFO has space for N entries (driven of wr_clk)
87
empty_n Indicates the FIFO has at least N entries (driven of rd_clk)
88
 
89
level           indicates the FIFO level:
90
                2'b00   0-25%    full
91
                2'b01   25-50%   full
92
                2'b10   50-75%   full
93
                2'b11   %75-100% full
94
 
95
Status Timing
96
-------------
97
All status outputs are registered. They are asserted immediately
98
as the full/empty condition occurs, however, there is a 2 cycle
99
delay before they are de-asserted once the condition is not true
100
anymore.
101
 
102
Parameters
103
----------
104
The FIFO takes 3 parameters:
105
dw      Data bus width
106
aw      Address bus width (Determines the FIFO size by evaluating 2^aw)
107
n       N is a second status threshold constant for full_n and empty_n
108
        If you have no need for the second status threshold, do not
109
        connect the outputs and the logic should be removed by your
110
        synthesis tool.
111
 
112
Synthesis Results
113
-----------------
114
In a Spartan 2e a 8 bit wide, 8 entries deep FIFO, takes 85 LUTs and runs
115
at about 116 MHz (IO insertion disabled). The registered status outputs
116
are valid after 2.1NS, the combinatorial once take out to 6.5 NS to be
117
available.
118
 
119
Misc
120
----
121
This design assumes you will do appropriate status checking externally.
122
 
123
IMPORTANT ! writing while the FIFO is full or reading while the FIFO is
124
empty will place the FIFO in an undefined state.
125
 
126
*/
127
 
128
 
129
// Selecting Sync. or Async Reset
130
// ------------------------------
131
// Uncomment one of the two lines below. The first line for
132
// synchronous reset, the second for asynchronous reset
133
 
134
//`define DC_FIFO_ASYNC_RESET                           // Uncomment for Syncr. reset
135
`define DC_FIFO_ASYNC_RESET     or negedge rst          // Uncomment for Async. reset
136
 
137
 
138
module generic_fifo_dc(rd_clk, wr_clk, rst, clr, din, we, dout, re,
139
                        full, empty, full_n, empty_n, level );
140
 
141
parameter dw=8;
142
parameter aw=8;
143
parameter n=32;
144
parameter max_size = 1<<aw;
145
 
146
input                   rd_clk, wr_clk, rst, clr;
147
input   [dw-1:0] din;
148
input                   we;
149
output  [dw-1:0] dout;
150
input                   re;
151
output                  full;
152
output                  empty;
153
output                  full_n;
154
output                  empty_n;
155
output  [1:0]            level;
156
 
157
////////////////////////////////////////////////////////////////////
158
//
159
// Local Wires
160
//
161
 
162
reg     [aw:0]           wp;
163
wire    [aw:0]           wp_pl1;
164
reg     [aw:0]           rp;
165
wire    [aw:0]           rp_pl1;
166
reg     [aw:0]           wp_s, rp_s;
167
wire    [aw:0]           diff;
168
reg     [aw:0]           diff_r1, diff_r2;
169
reg                     re_r, we_r;
170
reg                     full, empty, full_n, empty_n;
171
reg     [1:0]            level;
172
 
173
////////////////////////////////////////////////////////////////////
174
//
175
// Memory Block
176
//
177
 
178
generic_dpram  #(aw,dw) u0(
179
        .rclk(          rd_clk          ),
180
        .rrst(          !rst            ),
181
        .rce(           1'b1            ),
182
        .oe(            1'b1            ),
183
        .raddr(         rp[aw-1:0]       ),
184
        .do(            dout            ),
185
        .wclk(          wr_clk          ),
186
        .wrst(          !rst            ),
187
        .wce(           1'b1            ),
188
        .we(            we              ),
189
        .waddr(         wp[aw-1:0]       ),
190
        .di(            din             )
191
        );
192
 
193
////////////////////////////////////////////////////////////////////
194
//
195
// Read/Write Pointers Logic
196
//
197
 
198
always @(posedge wr_clk `DC_FIFO_ASYNC_RESET)
199
        if(!rst)        wp <= #1 {aw+1{1'b0}};
200
        else
201
        if(clr)         wp <= #1 {aw+1{1'b0}};
202
        else
203
        if(we)          wp <= #1 wp_pl1;
204
 
205
assign wp_pl1 = wp + { {aw{1'b0}}, 1'b1};
206
 
207
always @(posedge rd_clk `DC_FIFO_ASYNC_RESET)
208
        if(!rst)        rp <= #1 {aw+1{1'b0}};
209
        else
210
        if(clr)         rp <= #1 {aw+1{1'b0}};
211
        else
212
        if(re)          rp <= #1 rp_pl1;
213
 
214
assign rp_pl1 = rp + { {aw{1'b0}}, 1'b1};
215
 
216
////////////////////////////////////////////////////////////////////
217
//
218
// Synchronization Logic
219
//
220
 
221
// write pointer
222
always @(posedge rd_clk)        wp_s <= #1 wp;
223
 
224
// read pointer
225
always @(posedge wr_clk)        rp_s <= #1 rp;
226
 
227
////////////////////////////////////////////////////////////////////
228
//
229
// Registered Full & Empty Flags
230
//
231
 
232
always @(posedge rd_clk)
233
        empty <= #1 (wp_s == rp) | (re & (wp_s == rp_pl1));
234
 
235
always @(posedge wr_clk)
236
        full <= #1 ((wp[aw-1:0] == rp_s[aw-1:0]) & (wp[aw] != rp_s[aw])) |
237
        (we & (wp_pl1[aw-1:0] == rp_s[aw-1:0]) & (wp_pl1[aw] != rp_s[aw]));
238
 
239
////////////////////////////////////////////////////////////////////
240
//
241
// Registered Full_n & Empty_n Flags
242
//
243
 
244
assign diff = wp-rp;
245
 
246
always @(posedge rd_clk)
247
        re_r <= #1 re;
248
 
249
always @(posedge rd_clk)
250
        diff_r1 <= #1 diff;
251
 
252
always @(posedge rd_clk)
253
        empty_n <= #1 (diff_r1 < n) | ((diff_r1==n) & (re | re_r));
254
 
255
always @(posedge wr_clk)
256
        we_r <= #1 we;
257
 
258
always @(posedge wr_clk)
259
        diff_r2 <= #1 diff;
260
 
261
always @(posedge wr_clk)
262
        full_n <= #1 (diff_r2 > max_size-n) | ((diff_r2==max_size-n) & (we | we_r));
263
 
264
always @(posedge wr_clk)
265
        level <= #1 {2{diff[aw]}} | diff[aw-1:aw-2];
266
 
267
 
268
////////////////////////////////////////////////////////////////////
269
//
270
// Sanity Check
271
//
272
 
273
// synopsys translate_off
274
always @(posedge wr_clk)
275
        if(we & full)
276
                $display("%m WARNING: Writing while fifo is FULL (%t)",$time);
277
 
278
always @(posedge rd_clk)
279
        if(re & empty)
280
                $display("%m WARNING: Reading while fifo is EMPTY (%t)",$time);
281
// synopsys translate_on
282
 
283
endmodule
284
 

powered by: WebSVN 2.1.0

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