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 59

Go to most recent revision | 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 59 mihad
// Revision 1.4  2002/09/25 15:53:52  mihad
46
// Removed all logic from asynchronous reset network
47
//
48 58 mihad
// Revision 1.3  2002/02/01 15:25:13  mihad
49
// Repaired a few bugs, updated specification, added test bench files and design document
50
//
51 21 mihad
// Revision 1.2  2001/10/05 08:14:30  mihad
52
// Updated all files with inclusion of timescale file for simulation purposes.
53
//
54 6 mihad
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
55
// New project directory structure
56 2 mihad
//
57 6 mihad
//
58 2 mihad
 
59
/* FIFO_CONTROL module provides read/write address and status generation for
60
   FIFOs implemented with standard dual port SRAM cells in ASIC or FPGA designs */
61 21 mihad
`include "pci_constants.v"
62
// synopsys translate_off
63 6 mihad
`include "timescale.v"
64 21 mihad
// synopsys translate_on
65 2 mihad
 
66
module WBR_FIFO_CONTROL
67
(
68
    rclock_in,
69 21 mihad
    wclock_in,
70
    renable_in,
71
    wenable_in,
72
    reset_in,
73
    flush_in,
74
    empty_out,
75
    waddr_out,
76
    raddr_out,
77
    rallow_out,
78 2 mihad
    wallow_out
79
) ;
80
 
81
parameter ADDR_LENGTH = 7 ;
82
 
83
// independent clock inputs - rclock_in = read clock, wclock_in = write clock
84
input  rclock_in, wclock_in;
85
 
86
// enable inputs - read address changes on rising edge of rclock_in when reads are allowed
87
//                 write address changes on rising edge of wclock_in when writes are allowed
88
input  renable_in, wenable_in;
89
 
90
// reset input
91
input  reset_in;
92
 
93
// flush input
94
input flush_in ;
95
 
96
// empty status output
97
output empty_out;
98
 
99
// read and write addresses outputs
100
output [(ADDR_LENGTH - 1):0] waddr_out, raddr_out;
101
 
102
// read and write allow outputs
103
output rallow_out, wallow_out ;
104
 
105
// read address register
106
reg [(ADDR_LENGTH - 1):0] raddr ;
107
 
108
// write address register
109
reg [(ADDR_LENGTH - 1):0] waddr;
110
assign waddr_out = waddr ;
111
 
112
// grey code registers
113
// grey code pipeline for write address
114
reg [(ADDR_LENGTH - 1):0] wgrey_addr ; // current
115
reg [(ADDR_LENGTH - 1):0] wgrey_next ; // next
116
 
117
// next write gray address calculation - bitwise xor between address and shifted address
118
wire [(ADDR_LENGTH - 2):0] calc_wgrey_next  = waddr[(ADDR_LENGTH - 1):1] ^ waddr[(ADDR_LENGTH - 2):0] ;
119
 
120
// grey code pipeline for read address
121
reg [(ADDR_LENGTH - 1):0] rgrey_addr ; // current
122
reg [(ADDR_LENGTH - 1):0] rgrey_next ; // next
123
 
124
// next read gray address calculation - bitwise xor between address and shifted address
125
wire [(ADDR_LENGTH - 2):0] calc_rgrey_next  = raddr[(ADDR_LENGTH - 1):1] ^ raddr[(ADDR_LENGTH - 2):0] ;
126
 
127
// FF for registered empty flag
128 59 mihad
wire empty ;
129 2 mihad
 
130
// write allow wire
131
wire wallow = wenable_in ;
132
 
133
// write allow output assignment
134
assign wallow_out = wallow ;
135
 
136
// read allow wire
137
wire rallow ;
138
 
139
// clear generation for FFs and registers
140 58 mihad
wire clear = reset_in /*|| flush_in*/ ; // flush changed to synchronous operation
141 2 mihad
 
142 21 mihad
reg wclock_nempty_detect ;
143
always@(posedge reset_in or posedge wclock_in)
144
begin
145
    if (reset_in)
146
        wclock_nempty_detect <= #`FF_DELAY 1'b0 ;
147
    else
148
        wclock_nempty_detect <= #`FF_DELAY (rgrey_addr != wgrey_addr) ;
149
end
150 2 mihad
 
151 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
152 59 mihad
wire stretched_empty ;
153 2 mihad
 
154 59 mihad
wire stretched_empty_flop_i = empty && !wclock_nempty_detect ;
155
 
156
meta_flop #(1) i_meta_flop_stretched_empty
157
(
158
    .rst_i      (clear),
159
    .clk_i      (rclock_in),
160
    .ld_i       (1'b0),
161
    .ld_val_i   (1'b0),
162
    .en_i       (1'b1),
163
    .d_i        (stretched_empty_flop_i),
164
    .meta_q_o   (stretched_empty)
165
) ;
166
 
167 21 mihad
// empty output is actual empty + 1 read clock cycle ( stretched empty )
168
assign empty_out = empty  || stretched_empty ;
169 2 mihad
 
170 21 mihad
//rallow generation
171 59 mihad
assign rallow = renable_in && !empty && !stretched_empty ; // reads allowed if read enable is high and FIFO is not empty
172 2 mihad
 
173 21 mihad
// rallow output assignment
174
assign rallow_out = renable_in ;
175 2 mihad
 
176 21 mihad
// at any clock edge that rallow is high, this register provides next read address, so wait cycles are not necessary
177
// when FIFO is empty, this register provides actual read address, so first location can be read
178
reg [(ADDR_LENGTH - 1):0] raddr_plus_one ;
179 2 mihad
 
180 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
181
// done for zero wait state burst
182
assign raddr_out = rallow ? raddr_plus_one : raddr ;
183 2 mihad
 
184 21 mihad
always@(posedge rclock_in or posedge clear)
185
begin
186
    if (clear)
187
        // initial value is 3
188
        raddr_plus_one <= #`FF_DELAY 3 ;
189 58 mihad
    else if (flush_in)
190
        raddr_plus_one <= #`FF_DELAY waddr + 1'b1 ; // when read fifo is flushed, values from write side are copied to read side
191 21 mihad
    else if (rallow)
192
        raddr_plus_one <= #`FF_DELAY raddr_plus_one + 1'b1 ;
193
end
194 2 mihad
 
195 21 mihad
// raddr is filled with raddr_plus_one on rising read clock edge when rallow is high
196
always@(posedge rclock_in or posedge clear)
197
begin
198
    if (clear)
199
        // initial value is 2
200
        raddr <= #`FF_DELAY 2 ;
201 58 mihad
    else if (flush_in)
202
        raddr <= #`FF_DELAY waddr ;                 // when flushed, copy value from write side
203 21 mihad
    else if (rallow)
204
        raddr <= #`FF_DELAY raddr_plus_one ;
205
end
206 2 mihad
 
207
/*-----------------------------------------------------------------------------------------------
208
Read address control consists of Read address counter and Grey Address pipeline
209 21 mihad
There are 3 Grey addresses:
210 2 mihad
    - rgrey_addr is Grey Code of current read address
211
    - rgrey_next is Grey Code of next read address
212
--------------------------------------------------------------------------------------------------*/
213
 
214
// grey code register for read address - represents current Read Address
215
always@(posedge rclock_in or posedge clear)
216
begin
217 21 mihad
    if (clear)
218
        // initial value is 0
219
        rgrey_addr <= #`FF_DELAY 0 ;
220 58 mihad
    else if (flush_in)
221
        rgrey_addr <= #`FF_DELAY wgrey_addr ;   // when flushed, copy value from write side
222
    else if (rallow)
223 21 mihad
        rgrey_addr <= #`FF_DELAY rgrey_next ;
224 2 mihad
end
225
 
226 21 mihad
// grey code register for next read address - represents Grey Code of next read address
227 2 mihad
always@(posedge rclock_in or posedge clear)
228
begin
229 21 mihad
    if (clear)
230
        // initial value is 1
231
        rgrey_next <= #`FF_DELAY 1 ;
232 58 mihad
    else if (flush_in)
233
        rgrey_next <= #`FF_DELAY wgrey_next ;
234
    else if (rallow)
235 21 mihad
        rgrey_next <= #`FF_DELAY {raddr[ADDR_LENGTH - 1], calc_rgrey_next} ;
236 2 mihad
end
237
 
238
/*--------------------------------------------------------------------------------------------
239
Write address control consists of write address counter and two Grey Code Registers:
240
    - wgrey_addr represents current Grey Coded write address
241
    - wgrey_next represents Grey Coded next write address
242
----------------------------------------------------------------------------------------------*/
243
// grey code register for write address
244
always@(posedge wclock_in or posedge clear)
245
begin
246 21 mihad
    if (clear)
247 2 mihad
    begin
248 21 mihad
        // initial value is 0
249
        wgrey_addr <= #`FF_DELAY 0 ;
250 2 mihad
    end
251 21 mihad
    else
252
    if (wallow)
253
        wgrey_addr <= #`FF_DELAY wgrey_next ;
254 2 mihad
end
255
 
256
// grey code register for next write address
257
always@(posedge wclock_in or posedge clear)
258
begin
259 21 mihad
    if (clear)
260 2 mihad
    begin
261 21 mihad
        // initial value is 1
262
        wgrey_next <= #`FF_DELAY 1 ;
263 2 mihad
    end
264 21 mihad
    else
265
    if (wallow)
266
        wgrey_next <= #`FF_DELAY {waddr[(ADDR_LENGTH - 1)], calc_wgrey_next} ;
267 2 mihad
end
268
 
269 21 mihad
// write address counter - nothing special except initial value
270 2 mihad
always@(posedge wclock_in or posedge clear)
271
begin
272 21 mihad
    if (clear)
273
        // initial value is 2
274
        waddr <= #`FF_DELAY 2 ;
275
    else
276
    if (wallow)
277
        waddr <= #`FF_DELAY waddr + 1'b1 ;
278 2 mihad
end
279
 
280
 
281
/*------------------------------------------------------------------------------------------------------------------------------
282
Registered empty control:
283 21 mihad
registered empty is set on rising edge of rclock_in,
284 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
285
the next read clock.
286
--------------------------------------------------------------------------------------------------------------------------------*/
287
// combinatorial input for registered emty FlipFlop
288
wire reg_empty = (rallow && (rgrey_next == wgrey_addr)) || (rgrey_addr == wgrey_addr) ;
289
 
290 59 mihad
meta_flop #(1) i_meta_flop_empty
291
(
292
    .rst_i      (clear),
293
    .clk_i      (rclock_in),
294
    .ld_i       (flush_in),
295
    .ld_val_i   (1'b1),
296
    .en_i       (1'b1),
297
    .d_i        (reg_empty),
298
    .meta_q_o   (empty)
299
) ;
300 2 mihad
 
301
endmodule

powered by: WebSVN 2.1.0

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