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

Subversion Repositories pci

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

powered by: WebSVN 2.1.0

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