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 62

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

powered by: WebSVN 2.1.0

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