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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_9/] [rtl/] [verilog/] [pci_wbr_fifo_control.v] - Blame information for rev 104

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 77 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 104 mihad
// Revision 1.2  2003/03/26 13:16:18  mihad
46
// Added the reset value parameter to the synchronizer flop module.
47
// Added resets to all synchronizer flop instances.
48
// Repaired initial sync value in fifos.
49
//
50 88 mihad
// Revision 1.1  2003/01/27 16:49:31  mihad
51
// Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed.
52
//
53 77 mihad
// Revision 1.6  2002/11/27 20:36:12  mihad
54
// Changed the code a bit to make it more readable.
55
// Functionality not changed in any way.
56
// More robust synchronization in fifos is still pending.
57
//
58
// Revision 1.5  2002/09/30 16:03:04  mihad
59
// Added meta flop module for easier meta stable FF identification during synthesis
60
//
61
// Revision 1.4  2002/09/25 15:53:52  mihad
62
// Removed all logic from asynchronous reset network
63
//
64
// Revision 1.3  2002/02/01 15:25:13  mihad
65
// Repaired a few bugs, updated specification, added test bench files and design document
66
//
67
// Revision 1.2  2001/10/05 08:14:30  mihad
68
// Updated all files with inclusion of timescale file for simulation purposes.
69
//
70
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
71
// New project directory structure
72
//
73
//
74
 
75
/* FIFO_CONTROL module provides read/write address and status generation for
76
   FIFOs implemented with standard dual port SRAM cells in ASIC or FPGA designs */
77
`include "pci_constants.v"
78
// synopsys translate_off
79
`include "timescale.v"
80
// synopsys translate_on
81
 
82
module pci_wbr_fifo_control
83
(
84
    rclock_in,
85
    wclock_in,
86
    renable_in,
87
    wenable_in,
88
    reset_in,
89
    flush_in,
90
    empty_out,
91
    waddr_out,
92
    raddr_out,
93
    rallow_out,
94
    wallow_out
95
) ;
96
 
97
parameter ADDR_LENGTH = 7 ;
98
 
99
// independent clock inputs - rclock_in = read clock, wclock_in = write clock
100
input  rclock_in, wclock_in;
101
 
102
// enable inputs - read address changes on rising edge of rclock_in when reads are allowed
103
//                 write address changes on rising edge of wclock_in when writes are allowed
104
input  renable_in, wenable_in;
105
 
106
// reset input
107
input  reset_in;
108
 
109
// flush input
110
input flush_in ;
111
 
112
// empty status output
113
output empty_out;
114
 
115
// read and write addresses outputs
116
output [(ADDR_LENGTH - 1):0] waddr_out, raddr_out;
117
 
118
// read and write allow outputs
119
output rallow_out, wallow_out ;
120
 
121
// read address register
122
reg [(ADDR_LENGTH - 1):0] raddr ;
123
 
124
// write address register
125
reg [(ADDR_LENGTH - 1):0] waddr;
126
assign waddr_out = waddr ;
127
 
128
// grey code register
129
reg [(ADDR_LENGTH - 1):0] wgrey_addr ;
130
 
131
// next write gray address calculation - bitwise xor between address and shifted address
132
wire [(ADDR_LENGTH - 2):0] calc_wgrey_next  = waddr[(ADDR_LENGTH - 1):1] ^ waddr[(ADDR_LENGTH - 2):0] ;
133
 
134
// grey code register
135
reg [(ADDR_LENGTH - 1):0] rgrey_addr ;
136
 
137
// next read gray address calculation - bitwise xor between address and shifted address
138
wire [(ADDR_LENGTH - 2):0] calc_rgrey_next  = raddr[(ADDR_LENGTH - 1):1] ^ raddr[(ADDR_LENGTH - 2):0] ;
139
 
140
// FF for registered empty flag
141
wire empty ;
142
 
143
// write allow wire
144
wire wallow = wenable_in ;
145
 
146
// write allow output assignment
147
assign wallow_out = wallow ;
148
 
149
// read allow wire
150
wire rallow ;
151
 
152
// clear generation for FFs and registers
153
wire clear = reset_in /*|| flush_in*/ ; // flush changed to synchronous operation
154
 
155
assign empty_out = empty ;
156
 
157
//rallow generation
158
assign rallow = renable_in && !empty ; // reads allowed if read enable is high and FIFO is not empty
159
 
160
// rallow output assignment
161
assign rallow_out = renable_in ;
162
 
163
// at any clock edge that rallow is high, this register provides next read address, so wait cycles are not necessary
164
// when FIFO is empty, this register provides actual read address, so first location can be read
165
reg [(ADDR_LENGTH - 1):0] raddr_plus_one ;
166
 
167
// address output mux - when FIFO is empty, current actual address is driven out, when it is non - empty next address is driven out
168
// done for zero wait state burst
169
assign raddr_out = rallow ? raddr_plus_one : raddr ;
170
 
171
always@(posedge rclock_in or posedge clear)
172
begin
173
    if (clear)
174
    begin
175
        raddr_plus_one <= #`FF_DELAY 2 ;
176
        raddr          <= #`FF_DELAY 1 ;
177
    end
178
    else if (flush_in)
179
    begin
180
        raddr_plus_one <= #`FF_DELAY waddr + 1'b1 ;
181
        raddr          <= #`FF_DELAY waddr ;
182
    end
183
    else if (rallow)
184
    begin
185
        raddr_plus_one <= #`FF_DELAY raddr_plus_one + 1'b1 ;
186
        raddr          <= #`FF_DELAY raddr_plus_one ;
187
    end
188
end
189
 
190
/*-----------------------------------------------------------------------------------------------
191
Read address control consists of Read address counter and Grey Address register
192
--------------------------------------------------------------------------------------------------*/
193
// grey coded address
194
always@(posedge rclock_in or posedge clear)
195
begin
196
    if (clear)
197
    begin
198
        rgrey_addr <= #`FF_DELAY 0 ;
199
    end
200
    else if (flush_in)
201
    begin
202
        rgrey_addr <= #`FF_DELAY wgrey_addr ;   // when flushed, copy value from write side
203
    end
204
    else if (rallow)
205
    begin
206
        rgrey_addr <= #`FF_DELAY {raddr[ADDR_LENGTH - 1], calc_rgrey_next} ;
207
    end
208
end
209
 
210
/*--------------------------------------------------------------------------------------------
211
Write address control consists of write address counter and Grey Code Register
212
----------------------------------------------------------------------------------------------*/
213
// grey coded address for status generation in write clock domain
214
always@(posedge wclock_in or posedge clear)
215
begin
216
    if (clear)
217
    begin
218 104 mihad
        wgrey_addr <= #1 0 ;
219 77 mihad
    end
220
    else
221
    if (wallow)
222
    begin
223 104 mihad
        wgrey_addr <= #1 {waddr[(ADDR_LENGTH - 1)], calc_wgrey_next} ;
224 77 mihad
    end
225
end
226
 
227
// write address counter - nothing special except initial value
228
always@(posedge wclock_in or posedge clear)
229
begin
230
    if (clear)
231
        // initial value is 1
232
        waddr <= #`FF_DELAY 1 ;
233
    else
234
    if (wallow)
235
        waddr <= #`FF_DELAY waddr + 1'b1 ;
236
end
237
 
238
 
239
/*------------------------------------------------------------------------------------------------------------------------------
240
Empty control:
241
Gray coded write address pointer is synchronized to read clock domain and compared to Gray coded read address pointer.
242
If they are equal, fifo is empty.
243
--------------------------------------------------------------------------------------------------------------------------------*/
244
wire [(ADDR_LENGTH - 1):0] rclk_sync_wgrey_addr ;
245
reg  [(ADDR_LENGTH - 1):0] rclk_wgrey_addr ;
246 88 mihad
synchronizer_flop #(ADDR_LENGTH, 0) i_synchronizer_reg_wgrey_addr
247 77 mihad
(
248
    .data_in        (wgrey_addr),
249
    .clk_out        (rclock_in),
250
    .sync_data_out  (rclk_sync_wgrey_addr),
251 88 mihad
    .async_reset    (clear)
252 77 mihad
) ;
253
 
254 88 mihad
always@(posedge rclock_in or posedge clear)
255 77 mihad
begin
256 88 mihad
    if (clear)
257
        rclk_wgrey_addr <= #`FF_DELAY 0 ;
258
    else
259
        rclk_wgrey_addr <= #`FF_DELAY rclk_sync_wgrey_addr ;
260 77 mihad
end
261
 
262
assign empty = (rgrey_addr == rclk_wgrey_addr) ;
263
endmodule

powered by: WebSVN 2.1.0

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