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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_00/] [rtl/] [verilog/] [pciw_pcir_fifos.v] - Blame information for rev 41

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

powered by: WebSVN 2.1.0

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