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

Subversion Repositories pci

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

powered by: WebSVN 2.1.0

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