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

Subversion Repositories pci

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

powered by: WebSVN 2.1.0

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