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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [wbw_wbr_fifos.v] - Blame information for rev 67

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

Line No. Rev Author Line
1 2 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "wbw_wbr_fifos.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 67 tadejm
// Revision 1.7  2002/10/11 10:09:01  mihad
46
// Added additional testcase and changed rst name in BIST to trst
47
//
48 63 mihad
// Revision 1.6  2002/10/08 17:17:06  mihad
49
// Added BIST signals for RAMs.
50
//
51 62 mihad
// Revision 1.5  2002/09/30 16:03:04  mihad
52
// Added meta flop module for easier meta stable FF identification during synthesis
53
//
54 59 mihad
// Revision 1.4  2002/09/25 15:53:52  mihad
55
// Removed all logic from asynchronous reset network
56
//
57 58 mihad
// Revision 1.3  2002/02/01 15:25:14  mihad
58
// Repaired a few bugs, updated specification, added test bench files and design document
59
//
60 21 mihad
// Revision 1.2  2001/10/05 08:20:12  mihad
61
// Updated all files with inclusion of timescale file for simulation purposes.
62
//
63 7 mihad
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
64
// New project directory structure
65 2 mihad
//
66 7 mihad
//
67 2 mihad
 
68 21 mihad
`include "pci_constants.v"
69
 
70
// synopsys translate_off
71 7 mihad
`include "timescale.v"
72 21 mihad
// synopsys translate_on
73 2 mihad
 
74 62 mihad
module WBW_WBR_FIFOS
75
(
76
    wb_clock_in,
77
    pci_clock_in,
78
    reset_in,
79
    wbw_wenable_in,
80
    wbw_addr_data_in,
81
    wbw_cbe_in,
82
    wbw_control_in,
83
    wbw_renable_in,
84
    wbw_addr_data_out,
85
    wbw_cbe_out,
86
    wbw_control_out,
87
//    wbw_flush_in,         write fifo flush not used
88
    wbw_almost_full_out,
89
    wbw_full_out,
90
    wbw_empty_out,
91
    wbw_transaction_ready_out,
92
    wbr_wenable_in,
93
    wbr_data_in,
94
    wbr_be_in,
95
    wbr_control_in,
96
    wbr_renable_in,
97
    wbr_data_out,
98
    wbr_be_out,
99
    wbr_control_out,
100
    wbr_flush_in,
101
    wbr_empty_out
102
 
103
`ifdef PCI_BIST
104
    ,
105
    // debug chain signals
106 67 tadejm
    scanb_rst,      // bist scan reset
107
    scanb_clk,      // bist scan clock
108
    scanb_si,       // bist scan serial in
109
    scanb_so,       // bist scan serial out
110
    scanb_sen       // bist scan shift enable
111 62 mihad
`endif
112 2 mihad
) ;
113
 
114
/*-----------------------------------------------------------------------------------------------------------
115
System inputs:
116
wb_clock_in - WISHBONE bus clock
117
pci_clock_in - PCI bus clock
118
reset_in - reset from control logic
119
-------------------------------------------------------------------------------------------------------------*/
120
input wb_clock_in, pci_clock_in, reset_in ;
121
 
122
/*-----------------------------------------------------------------------------------------------------------
123
WISHBONE WRITE FIFO interface signals prefixed with wbw_ - FIFO is used for posted writes initiated by
124 21 mihad
WISHBONE master, traveling through FIFO and are completed on PCI by PCI master interface
125 2 mihad
 
126
write enable signal:
127
wbw_wenable_in = write enable input for WBW_FIFO - driven by WISHBONE slave interface
128
 
129
data input signals:
130
wbw_addr_data_in = data input - data from WISHBONE bus - first entry of transaction is address others are data entries
131
wbw_cbe_in       = bus command/byte enable(~SEL[3:0]) input - first entry of transaction is bus command, other are byte enables
132
wbw_control_in   = control input - encoded control bus input
133
 
134
read enable signal:
135
wbw_renable_in = read enable input driven by PCI master interface
136
 
137
data output signals:
138
wbw_addr_data_out = data output - data from WISHBONE bus - first entry of transaction is address, others are data entries
139
wbw_cbe_out      = bus command/byte enable output - first entry of transaction is bus command, others are byte enables
140
wbw_control_out = control input - encoded control bus input
141
 
142
status signals - monitored by various resources in the core
143
wbw_flush_in = flush signal input for WBW_FIFO - when asserted, fifo is flushed(emptied)
144
wbw_almost_full_out = almost full output from WBW_FIFO
145
wbw_full_out = full output from WBW_FIFO
146
wbw_empty_out = empty output from WBW_FIFO
147
wbw_transaction_ready_out = output indicating that one complete transaction is waiting in WBW_FIFO
148
-----------------------------------------------------------------------------------------------------------*/
149
// input control and data
150
input        wbw_wenable_in ;
151
input [31:0] wbw_addr_data_in ;
152
input [3:0]  wbw_cbe_in ;
153
input [3:0]  wbw_control_in ;
154
 
155
// output control and data
156
input         wbw_renable_in ;
157
output [31:0] wbw_addr_data_out ;
158
output [3:0]  wbw_cbe_out ;
159 21 mihad
output [3:0]  wbw_control_out ;
160 2 mihad
 
161
// flush input
162 58 mihad
// input wbw_flush_in ; // not used
163 2 mihad
 
164
// status outputs
165
output wbw_almost_full_out ;
166
output wbw_full_out ;
167
output wbw_empty_out ;
168
output wbw_transaction_ready_out ;
169
 
170
/*-----------------------------------------------------------------------------------------------------------
171 21 mihad
WISHBONE READ FIFO interface signals prefixed with wbr_ - FIFO is used for holding delayed read completions
172
initiated by master on WISHBONE bus and completed on PCI bus,
173 2 mihad
 
174
write enable signal:
175
wbr_wenable_in = write enable input for WBR_FIFO - driven by PCI master interface
176
 
177
data input signals:
178
wbr_data_in      = data input - data from PCI bus - there is no address entry here, since address is stored in separate register
179
wbr_be_in        = byte enable(~BE#[3:0]) input - byte enables - same through one transaction
180
wbr_control_in   = control input - encoded control bus input
181
 
182
read enable signal:
183
wbr_renable_in = read enable input driven by WISHBONE slave interface
184
 
185
data output signals:
186
wbr_data_out = data output - data from PCI bus
187
wbr_be_out      = byte enable output(~#BE)
188
wbr_control_out = control output - encoded control bus output
189
 
190
status signals - monitored by various resources in the core
191
wbr_flush_in = flush signal input for WBR_FIFO - when asserted, fifo is flushed(emptied)
192
wbr full_out = full output from WBR_FIFO
193
wbr_empty_out = empty output from WBR_FIFO
194
-----------------------------------------------------------------------------------------------------------*/
195
// input control and data
196
input        wbr_wenable_in ;
197
input [31:0] wbr_data_in ;
198
input [3:0]  wbr_be_in ;
199 21 mihad
input [3:0]  wbr_control_in ;
200 2 mihad
 
201
// output control and data
202
input         wbr_renable_in ;
203
output [31:0] wbr_data_out ;
204
output [3:0]  wbr_be_out ;
205 21 mihad
output [3:0]  wbr_control_out ;
206 2 mihad
 
207
// flush input
208 21 mihad
input wbr_flush_in ;
209 2 mihad
 
210
output wbr_empty_out ;
211
 
212 62 mihad
`ifdef PCI_BIST
213
/*-----------------------------------------------------
214
BIST debug chain port signals
215
-----------------------------------------------------*/
216 67 tadejm
input   scanb_rst;      // bist scan reset
217
input   scanb_clk;      // bist scan clock
218
input   scanb_si;       // bist scan serial in
219
output  scanb_so;       // bist scan serial out
220
input   scanb_sen;      // bist scan shift enable
221 62 mihad
`endif
222
 
223 2 mihad
/*-----------------------------------------------------------------------------------------------------------
224
FIFO depth parameters:
225
WBW_DEPTH = defines WBW_FIFO depth
226
WBR_DEPTH = defines WBR_FIFO depth
227
WBW_ADDR_LENGTH = defines WBW_FIFO's location address length = log2(WBW_DEPTH)
228
WBR_ADDR_LENGTH = defines WBR_FIFO's location address length = log2(WBR_DEPTH)
229
-----------------------------------------------------------------------------------------------------------*/
230
parameter WBW_DEPTH = `WBW_DEPTH ;
231
parameter WBW_ADDR_LENGTH = `WBW_ADDR_LENGTH ;
232
parameter WBR_DEPTH = `WBR_DEPTH ;
233
parameter WBR_ADDR_LENGTH = `WBR_ADDR_LENGTH ;
234
 
235
/*-----------------------------------------------------------------------------------------------------------
236
wbw_wallow = WBW_FIFO write allow wire - writes to FIFO are allowed when FIFO isn't full and write enable is 1
237
wbw_rallow = WBW_FIFO read allow wire - reads from FIFO are allowed when FIFO isn't empty and read enable is 1
238
-----------------------------------------------------------------------------------------------------------*/
239
wire wbw_wallow ;
240
wire wbw_rallow ;
241
 
242
/*-----------------------------------------------------------------------------------------------------------
243
wbr_wallow = WBR_FIFO write allow wire - writes to FIFO are allowed when FIFO isn't full and write enable is 1
244
wbr_rallow = WBR_FIFO read allow wire - reads from FIFO are allowed when FIFO isn't empty and read enable is 1
245
-----------------------------------------------------------------------------------------------------------*/
246
wire wbr_wallow ;
247
wire wbr_rallow ;
248
 
249
/*-----------------------------------------------------------------------------------------------------------
250
wires for address port conections from WBW_FIFO control logic to RAM blocks used for WBW_FIFO
251
-----------------------------------------------------------------------------------------------------------*/
252
wire [(WBW_ADDR_LENGTH - 1):0] wbw_raddr ;
253
wire [(WBW_ADDR_LENGTH - 1):0] wbw_waddr ;
254
 
255
/*-----------------------------------------------------------------------------------------------------------
256
wires for address port conections from WBR_FIFO control logic to RAM blocks used for WBR_FIFO
257
-----------------------------------------------------------------------------------------------------------*/
258
wire [(WBR_ADDR_LENGTH - 1):0] wbr_raddr ;
259
wire [(WBR_ADDR_LENGTH - 1):0] wbr_waddr ;
260
 
261
/*-----------------------------------------------------------------------------------------------------------
262
WBW_FIFO transaction counters: used to count incoming transactions and outgoing transactions. When number of
263
input transactions is equal to number of output transactions, it means that there isn't any complete transaction
264
currently present in the FIFO.
265
-----------------------------------------------------------------------------------------------------------*/
266
reg [(WBW_ADDR_LENGTH - 2):0] wbw_inTransactionCount ;
267
reg [(WBW_ADDR_LENGTH - 2):0] wbw_outTransactionCount ;
268
 
269
/*-----------------------------------------------------------------------------------------------------------
270
wires monitoring control bus. When control bus on a write transaction has a value of `LAST, it means that
271
complete transaction is in the FIFO. When control bus on a read transaction has a value of `LAST,
272
it means that there was one complete transaction taken out of FIFO.
273
-----------------------------------------------------------------------------------------------------------*/
274
wire wbw_last_in  = wbw_control_in[`LAST_CTRL_BIT]  ;
275
wire wbw_last_out = wbw_control_out[`LAST_CTRL_BIT] ;
276
 
277
wire wbw_empty ;
278
wire wbr_empty ;
279
 
280
assign wbw_empty_out = wbw_empty ;
281
assign wbr_empty_out = wbr_empty ;
282
 
283
// clear wires for fifos
284 58 mihad
wire wbw_clear = reset_in /*|| wbw_flush_in*/ ; // WBW_FIFO clear flush not used
285
wire wbr_clear = reset_in /*|| wbr_flush_in*/ ; // WBR_FIFO clear - flush changed from asynchronous to synchronous
286 2 mihad
 
287
/*-----------------------------------------------------------------------------------------------------------
288 21 mihad
Definitions of wires for connecting RAM instances
289 2 mihad
-----------------------------------------------------------------------------------------------------------*/
290 21 mihad
wire [39:0] dpram_portA_output ;
291
wire [39:0] dpram_portB_output ;
292 2 mihad
 
293 21 mihad
wire [39:0] dpram_portA_input = {wbw_control_in, wbw_cbe_in, wbw_addr_data_in} ;
294
wire [39:0] dpram_portB_input = {wbr_control_in, wbr_be_in, wbr_data_in} ;
295 2 mihad
 
296 21 mihad
/*-----------------------------------------------------------------------------------------------------------
297
Fifo output assignments - each ram port provides data for different fifo
298
-----------------------------------------------------------------------------------------------------------*/
299
assign wbw_control_out = dpram_portB_output[39:36] ;
300
assign wbr_control_out = dpram_portA_output[39:36] ;
301 2 mihad
 
302 21 mihad
assign wbw_cbe_out     = dpram_portB_output[35:32] ;
303
assign wbr_be_out      = dpram_portA_output[35:32] ;
304 2 mihad
 
305 21 mihad
assign wbw_addr_data_out = dpram_portB_output[31:0] ;
306
assign wbr_data_out      = dpram_portA_output[31:0] ;
307 2 mihad
 
308 21 mihad
`ifdef WB_RAM_DONT_SHARE
309 2 mihad
 
310 21 mihad
    /*-----------------------------------------------------------------------------------------------------------
311
    Piece of code in this ifdef section is used in applications which can provide enough RAM instances to
312
    accomodate four fifos - each occupying its own instance of ram. Ports are connected in such a way,
313
    that instances of RAMs can be changed from two port to dual port ( async read/write port ). In that case,
314
    write port is always port a and read port is port b.
315
    -----------------------------------------------------------------------------------------------------------*/
316 2 mihad
 
317 21 mihad
    /*-----------------------------------------------------------------------------------------------------------
318
    Pad redundant address lines with zeros. This may seem stupid, but it comes in perfect for FPGA impl.
319
    -----------------------------------------------------------------------------------------------------------*/
320
    /*
321
    wire [(`WBW_FIFO_RAM_ADDR_LENGTH - WBW_ADDR_LENGTH - 1):0] wbw_addr_prefix = {( `WBW_FIFO_RAM_ADDR_LENGTH - WBW_ADDR_LENGTH){1'b0}} ;
322
    wire [(`WBR_FIFO_RAM_ADDR_LENGTH - WBR_ADDR_LENGTH - 1):0] wbr_addr_prefix = {( `WBR_FIFO_RAM_ADDR_LENGTH - WBR_ADDR_LENGTH){1'b0}} ;
323
    */
324 2 mihad
 
325 21 mihad
    // compose complete port addresses
326
    wire [(`WB_FIFO_RAM_ADDR_LENGTH-1):0] wbw_whole_waddr = wbw_waddr ;
327
    wire [(`WB_FIFO_RAM_ADDR_LENGTH-1):0] wbw_whole_raddr = wbw_raddr ;
328 2 mihad
 
329 21 mihad
    wire [(`WB_FIFO_RAM_ADDR_LENGTH-1):0] wbr_whole_waddr = wbr_waddr ;
330
    wire [(`WB_FIFO_RAM_ADDR_LENGTH-1):0] wbr_whole_raddr = wbr_raddr ;
331 2 mihad
 
332 21 mihad
    wire wbw_read_enable = 1'b1 ;
333
    wire wbr_read_enable = 1'b1 ;
334 2 mihad
 
335 62 mihad
    `ifdef PCI_BIST
336 67 tadejm
    wire scanb_so_internal ; // wires for connection of debug ports on two rams
337
    wire scanb_si_internal = scanb_so_internal ;
338 62 mihad
    `endif
339
 
340 21 mihad
    // instantiate and connect two generic rams - one for wishbone write fifo and one for wishbone read fifo
341
    WB_TPRAM #(`WB_FIFO_RAM_ADDR_LENGTH, 40) wbw_fifo_storage
342
    (
343
        // Generic synchronous two-port RAM interface
344
        .clk_a(wb_clock_in),
345
        .rst_a(reset_in),
346
        .ce_a(1'b1),
347
        .we_a(wbw_wallow),
348
        .oe_a(1'b1),
349
        .addr_a(wbw_whole_waddr),
350
        .di_a(dpram_portA_input),
351
        .do_a(),
352 2 mihad
 
353 21 mihad
        .clk_b(pci_clock_in),
354
        .rst_b(reset_in),
355
        .ce_b(wbw_read_enable),
356
        .we_b(1'b0),
357
        .oe_b(1'b1),
358
        .addr_b(wbw_whole_raddr),
359
        .di_b(40'h00_0000_0000),
360
        .do_b(dpram_portB_output)
361 62 mihad
 
362
    `ifdef PCI_BIST
363
        ,
364 67 tadejm
        .scanb_rst      (scanb_rst),
365
        .scanb_clk      (scanb_clk),
366
        .scanb_si       (scanb_si),
367
        .scanb_so       (scanb_so_internal),
368
        .scanb_sen      (scanb_sen)
369 62 mihad
    `endif
370 21 mihad
    );
371 2 mihad
 
372 21 mihad
    WB_TPRAM #(`WB_FIFO_RAM_ADDR_LENGTH, 40) wbr_fifo_storage
373
    (
374
        // Generic synchronous two-port RAM interface
375
        .clk_a(pci_clock_in),
376
        .rst_a(reset_in),
377
        .ce_a(1'b1),
378
        .we_a(wbr_wallow),
379
        .oe_a(1'b1),
380
        .addr_a(wbr_whole_waddr),
381
        .di_a(dpram_portB_input),
382
        .do_a(),
383 2 mihad
 
384 21 mihad
        .clk_b(wb_clock_in),
385
        .rst_b(reset_in),
386
        .ce_b(wbr_read_enable),
387
        .we_b(1'b0),
388
        .oe_b(1'b1),
389
        .addr_b(wbr_whole_raddr),
390
        .di_b(40'h00_0000_0000),
391
        .do_b(dpram_portA_output)
392 62 mihad
 
393
    `ifdef PCI_BIST
394
        ,
395 67 tadejm
        .scanb_rst      (scanb_rst),
396
        .scanb_clk      (scanb_clk),
397
        .scanb_si       (scanb_si_internal),
398
        .scanb_so       (scanb_so),
399
        .scanb_sen      (scanb_sen)
400 62 mihad
    `endif
401 21 mihad
    );
402 2 mihad
 
403 21 mihad
`else // RAM blocks sharing between two fifos
404 2 mihad
 
405 21 mihad
    /*-----------------------------------------------------------------------------------------------------------
406
    Code section under this ifdef is used for implementation where RAM instances are too expensive. In this
407
    case one RAM instance is used for both - WISHBONE read and WISHBONE write fifo.
408
    -----------------------------------------------------------------------------------------------------------*/
409
    /*-----------------------------------------------------------------------------------------------------------
410
    Address prefix definition - since both FIFOs reside in same RAM instance, storage is separated by MSB
411
    addresses. WISHBONE write fifo addresses are padded with zeros on the MSB side ( at least one address line
412
    must be used for this ), WISHBONE read fifo addresses are padded with ones on the right ( at least one ).
413
    -----------------------------------------------------------------------------------------------------------*/
414
    wire [(`WB_FIFO_RAM_ADDR_LENGTH - WBW_ADDR_LENGTH - 1):0] wbw_addr_prefix = {( `WB_FIFO_RAM_ADDR_LENGTH - WBW_ADDR_LENGTH){1'b0}} ;
415
    wire [(`WB_FIFO_RAM_ADDR_LENGTH - WBR_ADDR_LENGTH - 1):0] wbr_addr_prefix = {( `WB_FIFO_RAM_ADDR_LENGTH - WBR_ADDR_LENGTH){1'b1}} ;
416 2 mihad
 
417
    /*-----------------------------------------------------------------------------------------------------------
418 21 mihad
    Port A address generation for RAM instance. RAM instance must be full two port RAM - read and write capability
419
    on both sides.
420
    Port A is clocked by WISHBONE clock, DIA is input for wbw_fifo, DOA is output for wbr_fifo.
421
    Address is multiplexed so operation can be switched between fifos. Default is a read on port.
422 2 mihad
    -----------------------------------------------------------------------------------------------------------*/
423 21 mihad
    wire [(`WB_FIFO_RAM_ADDR_LENGTH-1):0] portA_addr = wbw_wallow ? {wbw_addr_prefix, wbw_waddr} : {wbr_addr_prefix, wbr_raddr} ;
424
 
425
    /*-----------------------------------------------------------------------------------------------------------
426
    Port B is clocked by PCI clock, DIB is input for wbr_fifo, DOB is output for wbw_fifo.
427
    Address is multiplexed so operation can be switched between fifos. Default is a read on port.
428
    -----------------------------------------------------------------------------------------------------------*/
429
    wire [(`WB_FIFO_RAM_ADDR_LENGTH-1):0] portB_addr  = wbr_wallow ? {wbr_addr_prefix, wbr_waddr} : {wbw_addr_prefix, wbw_raddr} ;
430
 
431
    wire portA_enable      = 1'b1 ;
432
 
433
    wire portB_enable      = 1'b1 ;
434
 
435
    // instantiate RAM for these two fifos
436
    WB_TPRAM #(`WB_FIFO_RAM_ADDR_LENGTH, 40) wbu_fifo_storage
437
    (
438
        // Generic synchronous two-port RAM interface
439
        .clk_a(wb_clock_in),
440
        .rst_a(reset_in),
441
        .ce_a(portA_enable),
442
        .we_a(wbw_wallow),
443
        .oe_a(1'b1),
444
        .addr_a(portA_addr),
445
        .di_a(dpram_portA_input),
446
        .do_a(dpram_portA_output),
447
        .clk_b(pci_clock_in),
448
        .rst_b(reset_in),
449
        .ce_b(portB_enable),
450
        .we_b(wbr_wallow),
451
        .oe_b(1'b1),
452
        .addr_b(portB_addr),
453
        .di_b(dpram_portB_input),
454
        .do_b(dpram_portB_output)
455 62 mihad
 
456
    `ifdef PCI_BIST
457
        ,
458 67 tadejm
        .scanb_rst      (scanb_rst),
459
        .scanb_clk      (scanb_clk),
460
        .scanb_si       (scanb_si),
461
        .scanb_so       (scanb_so),
462
        .scanb_sen      (scanb_sen)
463 62 mihad
    `endif
464 21 mihad
    );
465
 
466 2 mihad
`endif
467
 
468
/*-----------------------------------------------------------------------------------------------------------
469
Instantiation of two control logic modules - one for WBW_FIFO and one for WBR_FIFO
470
-----------------------------------------------------------------------------------------------------------*/
471
WBW_FIFO_CONTROL #(WBW_ADDR_LENGTH) wbw_fifo_ctrl
472 21 mihad
(
473
    .rclock_in(pci_clock_in),
474
    .wclock_in(wb_clock_in),
475
    .renable_in(wbw_renable_in),
476
    .wenable_in(wbw_wenable_in),
477
    .reset_in(reset_in),
478 58 mihad
//    .flush_in(wbw_flush_in),
479 21 mihad
    .almost_full_out(wbw_almost_full_out),
480
    .full_out(wbw_full_out),
481
    .empty_out(wbw_empty),
482
    .waddr_out(wbw_waddr),
483
    .raddr_out(wbw_raddr),
484
    .rallow_out(wbw_rallow),
485
    .wallow_out(wbw_wallow)
486
);
487 2 mihad
 
488
WBR_FIFO_CONTROL #(WBR_ADDR_LENGTH) wbr_fifo_ctrl
489 21 mihad
(   .rclock_in(wb_clock_in),
490
    .wclock_in(pci_clock_in),
491
    .renable_in(wbr_renable_in),
492
    .wenable_in(wbr_wenable_in),
493
    .reset_in(reset_in),
494
    .flush_in(wbr_flush_in),
495
    .empty_out(wbr_empty),
496
    .waddr_out(wbr_waddr),
497
    .raddr_out(wbr_raddr),
498
    .rallow_out(wbr_rallow),
499
    .wallow_out(wbr_wallow)
500
);
501 2 mihad
 
502
 
503
// in and out transaction counters and grey codes
504
reg  [(WBW_ADDR_LENGTH-2):0] inGreyCount ;
505
reg  [(WBW_ADDR_LENGTH-2):0] outGreyCount ;
506
wire [(WBW_ADDR_LENGTH-2):0] inNextGreyCount = {wbw_inTransactionCount[(WBW_ADDR_LENGTH-2)], wbw_inTransactionCount[(WBW_ADDR_LENGTH-2):1] ^ wbw_inTransactionCount[(WBW_ADDR_LENGTH-3):0]} ;
507
wire [(WBW_ADDR_LENGTH-2):0] outNextGreyCount = {wbw_outTransactionCount[(WBW_ADDR_LENGTH-2)], wbw_outTransactionCount[(WBW_ADDR_LENGTH-2):1] ^ wbw_outTransactionCount[(WBW_ADDR_LENGTH-3):0]} ;
508
 
509 21 mihad
// input transaction counter increment - when last data of transaction is written to fifo
510 2 mihad
wire in_count_en  = wbw_wallow && wbw_last_in ;
511 21 mihad
 
512
// output transaction counter increment - when last data is on top of fifo and read from it
513 2 mihad
wire out_count_en = wbw_renable_in && wbw_last_out ;
514
 
515 21 mihad
// register holding grey coded count of incoming transactions
516 2 mihad
always@(posedge wb_clock_in or posedge wbw_clear)
517
begin
518
    if (wbw_clear)
519
    begin
520
        inGreyCount[(WBW_ADDR_LENGTH-2)] <= #`FF_DELAY 1'b1 ;
521
        inGreyCount[(WBW_ADDR_LENGTH-3):0] <= #`FF_DELAY {(WBW_ADDR_LENGTH-2),1'b0} ;
522
    end
523
    else
524
    if (in_count_en)
525
        inGreyCount <= #`FF_DELAY inNextGreyCount ;
526
end
527
 
528 21 mihad
// register holding grey coded count of outgoing transactions
529 2 mihad
always@(posedge pci_clock_in or posedge wbw_clear)
530
begin
531
    if (wbw_clear)
532
    begin
533
        outGreyCount[(WBW_ADDR_LENGTH-2)]   <= #`FF_DELAY 1'b1 ;
534
        outGreyCount[(WBW_ADDR_LENGTH-3):0] <= #`FF_DELAY {(WBW_ADDR_LENGTH-2),1'b0} ;
535
    end
536
    else
537
    if (out_count_en)
538
        outGreyCount <= #`FF_DELAY outNextGreyCount ;
539
end
540
 
541 21 mihad
// incoming transactions counter
542 2 mihad
always@(posedge wb_clock_in or posedge wbw_clear)
543
begin
544
    if (wbw_clear)
545
        wbw_inTransactionCount <= #`FF_DELAY {(WBW_ADDR_LENGTH-1){1'b0}} ;
546
    else
547
    if (in_count_en)
548
        wbw_inTransactionCount <= #`FF_DELAY wbw_inTransactionCount + 1'b1 ;
549
end
550
 
551 21 mihad
// outgoing transactions counter
552 2 mihad
always@(posedge pci_clock_in or posedge wbw_clear)
553
begin
554
    if (wbw_clear)
555
        wbw_outTransactionCount <= #`FF_DELAY {(WBW_ADDR_LENGTH-1){1'b0}} ;
556
    else
557
    if (out_count_en)
558
        wbw_outTransactionCount <= #`FF_DELAY wbw_outTransactionCount + 1'b1 ;
559
end
560
 
561
// synchronize transaction ready output to reading clock
562 21 mihad
// transaction ready is set when incoming transaction count is not equal to outgoing transaction count (what goes in must come out logic)
563
// transaction ready is cleared when whole transaction is pulled out of fifo (otherwise it could stay set for additional cycle and result in wrong op.)
564 59 mihad
wire wbw_transaction_ready_flop_i = inGreyCount != outGreyCount ;
565 2 mihad
 
566 59 mihad
meta_flop #(0) i_meta_flop_wbw_transaction_ready
567
(
568
    .rst_i      (wbw_clear),
569
    .clk_i      (pci_clock_in),
570
    .ld_i       (out_count_en),
571
    .ld_val_i   (1'b0),
572
    .en_i       (1'b1),
573
    .d_i        (wbw_transaction_ready_flop_i),
574
    .meta_q_o   (wbw_transaction_ready_out)
575
) ;
576
 
577 2 mihad
endmodule
578
 

powered by: WebSVN 2.1.0

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