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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_11/] [rtl/] [verilog/] [pci_wbw_wbr_fifos.v] - Blame information for rev 77

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

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

powered by: WebSVN 2.1.0

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