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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_6/] [rtl/] [verilog/] [pci_wbr_fifo_control.v] - Blame information for rev 88

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

powered by: WebSVN 2.1.0

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