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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [wbr_fifo_control.v] - Blame information for rev 154

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "wbr_fifo_control.v"                              ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Miha Dolenc (mihad@opencores.org)                     ////
10
////                                                              ////
11
////  All additional information is avaliable in the README       ////
12
////  file.                                                       ////
13
////                                                              ////
14
////                                                              ////
15
//////////////////////////////////////////////////////////////////////
16
////                                                              ////
17
//// Copyright (C) 2001 Miha Dolenc, mihad@opencores.org          ////
18
////                                                              ////
19
//// This source file may be used and distributed without         ////
20
//// restriction provided that this copyright statement is not    ////
21
//// removed from the file and that any derivative work contains  ////
22
//// the original copyright notice and the associated disclaimer. ////
23
////                                                              ////
24
//// This source file is free software; you can redistribute it   ////
25
//// and/or modify it under the terms of the GNU Lesser General   ////
26
//// Public License as published by the Free Software Foundation; ////
27
//// either version 2.1 of the License, or (at your option) any   ////
28
//// later version.                                               ////
29
////                                                              ////
30
//// This source is distributed in the hope that it will be       ////
31
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
32
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
33
//// PURPOSE.  See the GNU Lesser General Public License for more ////
34
//// details.                                                     ////
35
////                                                              ////
36
//// You should have received a copy of the GNU Lesser General    ////
37
//// Public License along with this source; if not, download it   ////
38
//// from http://www.opencores.org/lgpl.shtml                     ////
39
////                                                              ////
40
//////////////////////////////////////////////////////////////////////
41
//
42
// CVS Revision History
43
//
44
// $Log: not supported by cvs2svn $
45 71 mihad
// Revision 1.5  2002/09/30 16:03:04  mihad
46
// Added meta flop module for easier meta stable FF identification during synthesis
47
//
48 59 mihad
// Revision 1.4  2002/09/25 15:53:52  mihad
49
// Removed all logic from asynchronous reset network
50
//
51 58 mihad
// Revision 1.3  2002/02/01 15:25:13  mihad
52
// Repaired a few bugs, updated specification, added test bench files and design document
53
//
54 21 mihad
// Revision 1.2  2001/10/05 08:14:30  mihad
55
// Updated all files with inclusion of timescale file for simulation purposes.
56
//
57 6 mihad
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
58
// New project directory structure
59 2 mihad
//
60 6 mihad
//
61 2 mihad
 
62
/* FIFO_CONTROL module provides read/write address and status generation for
63
   FIFOs implemented with standard dual port SRAM cells in ASIC or FPGA designs */
64 21 mihad
`include "pci_constants.v"
65
// synopsys translate_off
66 6 mihad
`include "timescale.v"
67 21 mihad
// synopsys translate_on
68 2 mihad
 
69
module WBR_FIFO_CONTROL
70
(
71
    rclock_in,
72 21 mihad
    wclock_in,
73
    renable_in,
74
    wenable_in,
75
    reset_in,
76
    flush_in,
77
    empty_out,
78
    waddr_out,
79
    raddr_out,
80
    rallow_out,
81 2 mihad
    wallow_out
82
) ;
83
 
84
parameter ADDR_LENGTH = 7 ;
85
 
86
// independent clock inputs - rclock_in = read clock, wclock_in = write clock
87
input  rclock_in, wclock_in;
88
 
89
// enable inputs - read address changes on rising edge of rclock_in when reads are allowed
90
//                 write address changes on rising edge of wclock_in when writes are allowed
91
input  renable_in, wenable_in;
92
 
93
// reset input
94
input  reset_in;
95
 
96
// flush input
97
input flush_in ;
98
 
99
// empty status output
100
output empty_out;
101
 
102
// read and write addresses outputs
103
output [(ADDR_LENGTH - 1):0] waddr_out, raddr_out;
104
 
105
// read and write allow outputs
106
output rallow_out, wallow_out ;
107
 
108
// read address register
109
reg [(ADDR_LENGTH - 1):0] raddr ;
110
 
111
// write address register
112
reg [(ADDR_LENGTH - 1):0] waddr;
113
assign waddr_out = waddr ;
114
 
115
// grey code registers
116
// grey code pipeline for write address
117
reg [(ADDR_LENGTH - 1):0] wgrey_addr ; // current
118
reg [(ADDR_LENGTH - 1):0] wgrey_next ; // next
119
 
120
// next write gray address calculation - bitwise xor between address and shifted address
121
wire [(ADDR_LENGTH - 2):0] calc_wgrey_next  = waddr[(ADDR_LENGTH - 1):1] ^ waddr[(ADDR_LENGTH - 2):0] ;
122
 
123
// grey code pipeline for read address
124
reg [(ADDR_LENGTH - 1):0] rgrey_addr ; // current
125
reg [(ADDR_LENGTH - 1):0] rgrey_next ; // next
126
 
127
// next read gray address calculation - bitwise xor between address and shifted address
128
wire [(ADDR_LENGTH - 2):0] calc_rgrey_next  = raddr[(ADDR_LENGTH - 1):1] ^ raddr[(ADDR_LENGTH - 2):0] ;
129
 
130
// FF for registered empty flag
131 59 mihad
wire empty ;
132 2 mihad
 
133
// write allow wire
134
wire wallow = wenable_in ;
135
 
136
// write allow output assignment
137
assign wallow_out = wallow ;
138
 
139
// read allow wire
140
wire rallow ;
141
 
142
// clear generation for FFs and registers
143 58 mihad
wire clear = reset_in /*|| flush_in*/ ; // flush changed to synchronous operation
144 2 mihad
 
145 21 mihad
reg wclock_nempty_detect ;
146
always@(posedge reset_in or posedge wclock_in)
147
begin
148
    if (reset_in)
149
        wclock_nempty_detect <= #`FF_DELAY 1'b0 ;
150
    else
151
        wclock_nempty_detect <= #`FF_DELAY (rgrey_addr != wgrey_addr) ;
152
end
153 2 mihad
 
154 21 mihad
// special synchronizing mechanism for different implementations - in synchronous imp., empty is prolonged for 1 clock edge if no write clock comes after initial write
155 59 mihad
wire stretched_empty ;
156 2 mihad
 
157 59 mihad
wire stretched_empty_flop_i = empty && !wclock_nempty_detect ;
158
 
159
meta_flop #(1) i_meta_flop_stretched_empty
160
(
161
    .rst_i      (clear),
162
    .clk_i      (rclock_in),
163
    .ld_i       (1'b0),
164
    .ld_val_i   (1'b0),
165
    .en_i       (1'b1),
166
    .d_i        (stretched_empty_flop_i),
167
    .meta_q_o   (stretched_empty)
168
) ;
169
 
170 21 mihad
// empty output is actual empty + 1 read clock cycle ( stretched empty )
171
assign empty_out = empty  || stretched_empty ;
172 2 mihad
 
173 21 mihad
//rallow generation
174 59 mihad
assign rallow = renable_in && !empty && !stretched_empty ; // reads allowed if read enable is high and FIFO is not empty
175 2 mihad
 
176 21 mihad
// rallow output assignment
177
assign rallow_out = renable_in ;
178 2 mihad
 
179 21 mihad
// at any clock edge that rallow is high, this register provides next read address, so wait cycles are not necessary
180
// when FIFO is empty, this register provides actual read address, so first location can be read
181
reg [(ADDR_LENGTH - 1):0] raddr_plus_one ;
182 2 mihad
 
183 21 mihad
// address output mux - when FIFO is empty, current actual address is driven out, when it is non - empty next address is driven out
184
// done for zero wait state burst
185
assign raddr_out = rallow ? raddr_plus_one : raddr ;
186 2 mihad
 
187 21 mihad
always@(posedge rclock_in or posedge clear)
188
begin
189
    if (clear)
190 71 mihad
    begin
191 21 mihad
        raddr_plus_one <= #`FF_DELAY 3 ;
192 71 mihad
        raddr          <= #`FF_DELAY 2 ;
193
    end
194 58 mihad
    else if (flush_in)
195 71 mihad
    begin
196
        raddr_plus_one <= #`FF_DELAY waddr + 1'b1 ;
197
        raddr          <= #`FF_DELAY waddr ;
198
    end
199 21 mihad
    else if (rallow)
200 71 mihad
    begin
201 21 mihad
        raddr_plus_one <= #`FF_DELAY raddr_plus_one + 1'b1 ;
202 71 mihad
        raddr          <= #`FF_DELAY raddr_plus_one ;
203
    end
204 21 mihad
end
205 2 mihad
 
206
/*-----------------------------------------------------------------------------------------------
207
Read address control consists of Read address counter and Grey Address pipeline
208 21 mihad
There are 3 Grey addresses:
209 2 mihad
    - rgrey_addr is Grey Code of current read address
210
    - rgrey_next is Grey Code of next read address
211
--------------------------------------------------------------------------------------------------*/
212 71 mihad
// grey coded address pipeline for status generation in read clock domain
213 2 mihad
always@(posedge rclock_in or posedge clear)
214
begin
215 21 mihad
    if (clear)
216 71 mihad
    begin
217 21 mihad
        rgrey_addr <= #`FF_DELAY 0 ;
218 71 mihad
        rgrey_next <= #`FF_DELAY 1 ;
219
    end
220 58 mihad
    else if (flush_in)
221 71 mihad
    begin
222 58 mihad
        rgrey_addr <= #`FF_DELAY wgrey_addr ;   // when flushed, copy value from write side
223 71 mihad
        rgrey_next <= #`FF_DELAY wgrey_next ;
224
    end
225 58 mihad
    else if (rallow)
226 71 mihad
    begin
227 21 mihad
        rgrey_addr <= #`FF_DELAY rgrey_next ;
228
        rgrey_next <= #`FF_DELAY {raddr[ADDR_LENGTH - 1], calc_rgrey_next} ;
229 71 mihad
    end
230 2 mihad
end
231
 
232
/*--------------------------------------------------------------------------------------------
233
Write address control consists of write address counter and two Grey Code Registers:
234
    - wgrey_addr represents current Grey Coded write address
235
    - wgrey_next represents Grey Coded next write address
236
----------------------------------------------------------------------------------------------*/
237 71 mihad
// grey coded address pipeline for status generation in write clock domain
238 2 mihad
always@(posedge wclock_in or posedge clear)
239
begin
240 21 mihad
    if (clear)
241 2 mihad
    begin
242 21 mihad
        wgrey_addr <= #`FF_DELAY 0 ;
243 71 mihad
        wgrey_next <= #`FF_DELAY 1 ;
244 2 mihad
    end
245 21 mihad
    else
246
    if (wallow)
247 71 mihad
    begin
248 21 mihad
        wgrey_addr <= #`FF_DELAY wgrey_next ;
249 71 mihad
        wgrey_next <= #`FF_DELAY {waddr[(ADDR_LENGTH - 1)], calc_wgrey_next} ;
250 2 mihad
    end
251
end
252
 
253 21 mihad
// write address counter - nothing special except initial value
254 2 mihad
always@(posedge wclock_in or posedge clear)
255
begin
256 21 mihad
    if (clear)
257
        // initial value is 2
258
        waddr <= #`FF_DELAY 2 ;
259
    else
260
    if (wallow)
261
        waddr <= #`FF_DELAY waddr + 1'b1 ;
262 2 mihad
end
263
 
264
 
265
/*------------------------------------------------------------------------------------------------------------------------------
266
Registered empty control:
267 21 mihad
registered empty is set on rising edge of rclock_in,
268 2 mihad
when only one location is used and read in/from fifo. It's kept high until something is written to FIFO, which is registered on
269
the next read clock.
270
--------------------------------------------------------------------------------------------------------------------------------*/
271
// combinatorial input for registered emty FlipFlop
272
wire reg_empty = (rallow && (rgrey_next == wgrey_addr)) || (rgrey_addr == wgrey_addr) ;
273
 
274 59 mihad
meta_flop #(1) i_meta_flop_empty
275
(
276
    .rst_i      (clear),
277
    .clk_i      (rclock_in),
278
    .ld_i       (flush_in),
279
    .ld_val_i   (1'b1),
280
    .en_i       (1'b1),
281
    .d_i        (reg_empty),
282
    .meta_q_o   (empty)
283
) ;
284 2 mihad
 
285
endmodule

powered by: WebSVN 2.1.0

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