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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [wbw_wbr_fifos.v] - Blame information for rev 58

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

powered by: WebSVN 2.1.0

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