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 154

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

powered by: WebSVN 2.1.0

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