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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [pciw_pcir_fifos.v] - Blame information for rev 67

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

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

powered by: WebSVN 2.1.0

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