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 59

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

powered by: WebSVN 2.1.0

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