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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_1/] [rtl/] [verilog/] [wbw_wbr_fifos.v] - Blame information for rev 154

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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