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

Subversion Repositories pci

[/] [pci/] [trunk/] [rtl/] [verilog/] [pci_wb_master.v] - Blame information for rev 86

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

Line No. Rev Author Line
1 77 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name: wb_master.v                                      ////
4
////                                                              ////
5
////  This file is part of the "PCI bridge" project               ////
6
////  http://www.opencores.org/cores/pci/                         ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Tadej Markovic, tadej@opencores.org                   ////
10
////                                                              ////
11
////  All additional information is avaliable in the README.txt   ////
12
////  file.                                                       ////
13
////                                                              ////
14
////                                                              ////
15
//////////////////////////////////////////////////////////////////////
16
////                                                              ////
17
//// Copyright (C) 2000 Tadej Markovic, tadej@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 86 mihad
// Revision 1.2  2003/01/30 22:01:09  mihad
46
// Updated synchronization in top level fifo modules.
47
//
48 81 mihad
// Revision 1.1  2003/01/27 16:49:31  mihad
49
// Changed module and file names. Updated scripts accordingly. FIFO synchronizations changed.
50
//
51 77 mihad
// Revision 1.7  2002/12/05 12:19:23  mihad
52
// *** empty log message ***
53
//
54
// Revision 1.6  2002/10/11 14:15:29  mihad
55
// Cleaned up non-blocking assignments in combinatinal logic statements
56
//
57
// Revision 1.5  2002/03/05 11:53:47  mihad
58
// Added some testcases, removed un-needed fifo signals
59
//
60
// Revision 1.4  2002/02/19 16:32:37  mihad
61
// Modified testbench and fixed some bugs
62
//
63
// Revision 1.3  2002/02/01 15:25:13  mihad
64
// Repaired a few bugs, updated specification, added test bench files and design document
65
//
66
// Revision 1.2  2001/10/05 08:14:30  mihad
67
// Updated all files with inclusion of timescale file for simulation purposes.
68
//
69
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
70
// New project directory structure
71
//
72
//
73
 
74
`define WB_FSM_BITS 3 // number of bits needed for FSM states
75
 
76
 
77
`include "bus_commands.v"
78
`include "pci_constants.v"
79
//synopsys translate_off
80
`include "timescale.v"
81
//synopsys translate_on
82
 
83
module pci_wb_master
84
                 (  wb_clock_in,        // CLK_I
85
                    reset_in,           // RST_I
86
 
87
                    pci_tar_read_request,
88
                    pci_tar_address,
89
                    pci_tar_cmd,
90
                    pci_tar_be,
91
                    pci_tar_burst_ok,
92
                    pci_cache_line_size,
93
                    cache_lsize_not_zero,
94
                    wb_read_done_out,
95
                    w_attempt,
96
 
97
                    pcir_fifo_wenable_out,
98
                    pcir_fifo_data_out,
99
                    pcir_fifo_be_out,
100
                    pcir_fifo_control_out,
101
                    //pcir_fifo_renable_out,            for PCI Target !!!
102
                    //pcir_fifo_data_in,                for PCI Target !!!
103
                    //pcir_fifo_be_in,                  for PCI Target !!!
104
                    //pcir_fifo_control_in,             for PCI Target !!!
105
                    //pcir_fifo_flush_out,              for PCI Target !!!
106
                    //pcir_fifo_almost_empty_in,        for PCI Target !!!
107
                    //pcir_fifo_empty_in,               NOT used
108
                    //pcir_fifo_transaction_ready_in,   NOT used
109
                    //pciw_fifo_wenable_out,            for PCI Target !!!
110
                    //pciw_fifo_addr_data_out,          for PCI Target !!!   
111
                    //pciw_fifo_cbe_out,                for PCI Target !!!
112
                    //pciw_fifo_control_out,            for PCI Target !!!       
113
                    pciw_fifo_renable_out,
114
                    pciw_fifo_addr_data_in,
115
                    pciw_fifo_cbe_in,
116
                    pciw_fifo_control_in,
117
                    //pciw_fifo_flush_out,              NOT used
118
                    //pciw_fifo_almost_full_in,         for PCI Target !!!
119
                    //pciw_fifo_full_in,                for PCI Target !!!
120
                    pciw_fifo_almost_empty_in,
121
                    pciw_fifo_empty_in,
122
                    pciw_fifo_transaction_ready_in,
123
 
124
                    pci_error_sig_out,
125
                    pci_error_bc,
126
                    write_rty_cnt_exp_out,
127
                    error_source_out,
128
                    read_rty_cnt_exp_out,
129
 
130
                    CYC_O,
131
                    STB_O,
132
                    WE_O,
133
                    SEL_O,
134
                    ADR_O,
135
                    MDATA_I,
136
                    MDATA_O,
137
                    ACK_I,
138
                    RTY_I,
139
                    ERR_I,
140
                    CAB_O
141
                );
142
 
143
/*----------------------------------------------------------------------------------------------------------------------
144
Various parameters needed for state machine and other stuff
145
----------------------------------------------------------------------------------------------------------------------*/
146
parameter       S_IDLE          = `WB_FSM_BITS'h0 ;
147
parameter       S_WRITE         = `WB_FSM_BITS'h1 ;
148
parameter       S_WRITE_ERR_RTY = `WB_FSM_BITS'h2 ;
149
parameter       S_READ          = `WB_FSM_BITS'h3 ;
150
parameter       S_READ_RTY      = `WB_FSM_BITS'h4 ;
151
parameter       S_TURN_ARROUND  = `WB_FSM_BITS'h5 ;
152
 
153
/*----------------------------------------------------------------------------------------------------------------------
154
System signals inputs
155
wb_clock_in - WISHBONE bus clock input
156
reset_in    - system reset input controlled by bridge's reset logic
157
----------------------------------------------------------------------------------------------------------------------*/
158
input           wb_clock_in ;
159
input           reset_in ;
160
 
161
/*----------------------------------------------------------------------------------------------------------------------
162
Control signals from PCI Target for READS to PCIR_FIFO
163
---------------------------------------------------------------------------------------------------------------------*/
164
input           pci_tar_read_request ;      // read request from PCI Target
165
input   [31:0]  pci_tar_address ;           // address for requested read from PCI Target                   
166
input   [3:0]   pci_tar_cmd ;               // command for requested read from PCI Target                   
167
input   [3:0]   pci_tar_be ;                // byte enables for requested read from PCI Target              
168
input           pci_tar_burst_ok ;
169
input   [7:0]   pci_cache_line_size ;       // CACHE line size register value for burst length   
170
input           cache_lsize_not_zero ;
171
output          wb_read_done_out ;              // read done and PCIR_FIFO has data ready
172
output          w_attempt ;
173
 
174
reg             wb_read_done_out ;
175
reg             wb_read_done ;
176
 
177
/*----------------------------------------------------------------------------------------------------------------------
178
PCIR_FIFO control signals used for sinking data into PCIR_FIFO and status monitoring
179
---------------------------------------------------------------------------------------------------------------------*/
180
output          pcir_fifo_wenable_out ;     // PCIR_FIFO write enable output
181
output  [31:0]  pcir_fifo_data_out ;        // data output to PCIR_FIFO
182
output  [3:0]   pcir_fifo_be_out ;          // byte enable output to PCIR_FIFO
183
output  [3:0]   pcir_fifo_control_out ;     // control bus output to PCIR_FIFO
184
 
185
reg     [31:0]  pcir_fifo_data_out ;
186
reg             pcir_fifo_wenable_out ;
187
reg             pcir_fifo_wenable ;
188
reg     [3:0]   pcir_fifo_control_out ;
189
reg     [3:0]   pcir_fifo_control ;
190
 
191
/*----------------------------------------------------------------------------------------------------------------------
192
PCIW_FIFO control signals used for fetching data from PCIW_FIFO and status monitoring
193
---------------------------------------------------------------------------------------------------------------------*/
194
output          pciw_fifo_renable_out ;     // read enable for PCIW_FIFO output
195
input   [31:0]  pciw_fifo_addr_data_in ;    // address and data input from PCIW_FIFO
196
input   [3:0]   pciw_fifo_cbe_in ;          // command and byte_enables from PCIW_FIFO
197
input   [3:0]   pciw_fifo_control_in ;      // control bus input from PCIW_FIFO
198
input           pciw_fifo_almost_empty_in ; // almost empty status indicator from PCIW_FIFO
199
input           pciw_fifo_empty_in ;        // empty status indicator from PCIW_FIFO
200
input           pciw_fifo_transaction_ready_in ;    // write transaction is ready in PCIW_FIFO
201
 
202
reg             pciw_fifo_renable_out ;
203
reg             pciw_fifo_renable ;
204
 
205
/*----------------------------------------------------------------------------------------------------------------------
206
Control INPUT / OUTPUT signals for configuration space reporting registers !!!
207
---------------------------------------------------------------------------------------------------------------------*/
208
output          pci_error_sig_out ;         // When error occures (on WB bus, retry counter, etc.)
209
output  [3:0]   pci_error_bc ;              // bus command at which error occured !
210
output          write_rty_cnt_exp_out ;     // Signaling that RETRY counter has expired during write transaction!
211
output          read_rty_cnt_exp_out ;      // Signaling that RETRY counter has expired during read transaction!
212
                                            //  if error_source is '0' other side didn't respond
213
                                            //  if error_source is '1' other side RETRIED for max retry counter value
214
output          error_source_out ;          // Signaling error source - '0' other WB side signaled error OR didn't respond
215
                                            //   if '1' wridge counted max value in retry counter because of RTY responds
216
reg             pci_error_sig_out ;
217
reg             write_rty_cnt_exp_out ;
218
reg             read_rty_cnt_exp_out ;
219
reg             error_source_out ;
220
 
221
/*----------------------------------------------------------------------------------------------------------------------
222
WISHBONE bus interface signals - can be connected directly to WISHBONE bus
223
---------------------------------------------------------------------------------------------------------------------*/
224
output          CYC_O ;         // cycle indicator output
225
output          STB_O ;         // strobe output - data is valid when strobe and cycle indicator are high
226
output          WE_O  ;         // write enable output - 1 - write operation, 0 - read operation
227
output  [3:0]   SEL_O ;         // Byte select outputs
228
output  [31:0]  ADR_O ;         // WISHBONE address output
229
input   [31:0]  MDATA_I ;       // WISHBONE slave interface input data bus
230
output  [31:0]  MDATA_O ;       // WISHBONE slave interface output data bus
231
input           ACK_I ;         // Acknowledge input - qualifies valid data on data output bus or received data on data input bus
232
input           RTY_I ;         // retry input - signals from WISHBONE slave that cycle should be terminated and retried later
233
input           ERR_I ;         // Signals from WISHBONE slave that access resulted in an error
234
output          CAB_O ;         // consecutive address burst output - indicated that master will do a serial address transfer in current cycle
235
 
236
reg             CYC_O ;
237
reg             STB_O ;
238
reg             WE_O  ;
239
reg     [3:0]   SEL_O ;
240
reg     [31:0]  MDATA_O ;
241
reg             CAB_O ;
242
 
243
 
244
/*###########################################################################################################
245
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
246
    LOGIC, COUNTERS, STATE MACHINE and some control register bits
247
    =============================================================
248
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
249
###########################################################################################################*/
250
 
251
reg             last_data_transferred ; // signal is set by STATE MACHINE after each complete transfere !
252
 
253
// wire for write attempt - 1 when PCI Target attempt to write and PCIW_FIFO has a write transaction ready
254
`ifdef REGISTER_WBM_OUTPUTS
255
    reg     w_attempt;
256
    always@(posedge wb_clock_in or posedge reset_in)
257
    begin
258
        if (reset_in)
259
            w_attempt <= #`FF_DELAY 1'b0;
260
        else
261
        begin
262
            if (pciw_fifo_transaction_ready_in && ~pciw_fifo_empty_in)
263
                w_attempt <= #`FF_DELAY 1'b1;
264
            else
265
                if (last_data_transferred)
266
                    w_attempt <= #`FF_DELAY 1'b0;
267
        end
268
    end
269
`else
270
    assign w_attempt = ( pciw_fifo_transaction_ready_in && ~pciw_fifo_empty_in ) ;
271
`endif
272
 
273
// wire for read attempt - 1 when PCI Target is attempting a read and PCIR_FIFO is not full !
274
// because of transaction ordering, PCI Master must not start read untill all writes are done -> at that
275
//   moment PCIW_FIFO is empty !!! (when read is pending PCI Target will block new reads and writes)
276 81 mihad
wire r_attempt = ( pci_tar_read_request && !w_attempt && pciw_fifo_empty_in ) ;
277 77 mihad
 
278
// Signal is used for reads on WB, when there is retry!
279
reg             first_wb_data_access ;
280
 
281
reg             last_data_from_pciw_fifo ;  // signal tells when there is last data in pciw_fifo
282
reg             last_data_from_pciw_fifo_reg ;
283
reg             last_data_to_pcir_fifo ;    // signal tells when there will be last data for pcir_fifo
284
 
285
// Logic used in State Machine logic implemented out of State Machine because of less delay!
286
always@(pciw_fifo_control_in or pciw_fifo_almost_empty_in)
287
begin
288
    if (pciw_fifo_control_in[`LAST_CTRL_BIT] || pciw_fifo_almost_empty_in) // if last data is going to be transfered
289
        last_data_from_pciw_fifo = 1'b1 ; // signal for last data from PCIW_FIFO
290
    else
291
        last_data_from_pciw_fifo = 1'b0 ;
292
end
293
 
294
    reg read_count_load;
295
    reg read_count_enable;
296
 
297
    reg [(`PCIR_ADDR_LENGTH - 1):0] max_read_count ;
298
    always@(pci_cache_line_size or cache_lsize_not_zero or pci_tar_cmd)
299
    begin
300
        if (cache_lsize_not_zero)
301
            if ( (pci_cache_line_size >= `PCIR_DEPTH) || (~pci_tar_cmd[1] && ~pci_tar_cmd[0]) )
302
                // If cache line size is larger than FIFO or BC_MEM_READ_MUL command is performed!
303
                max_read_count = `PCIR_DEPTH - 1'b1;
304
            else
305
                max_read_count = pci_cache_line_size ;
306
        else
307
            max_read_count = 1'b1;
308
    end
309
 
310
    reg [(`PCIR_ADDR_LENGTH - 1):0] read_count ;
311
 
312
    // cache line bound indicator - it signals when data for one complete cacheline was read
313
    wire read_bound_comb = ~|( { read_count[(`PCIR_ADDR_LENGTH - 1):2], read_count[0] } ) ;
314
 
315
    reg  read_bound ;
316
    always@(posedge wb_clock_in or posedge reset_in)
317
    begin
318
        if ( reset_in )
319
            read_bound <= #`FF_DELAY 1'b0 ;
320
        else if (read_count_load)
321
            read_bound <= #`FF_DELAY 1'b0 ;
322
        else if ( read_count_enable )
323
            read_bound <= #`FF_DELAY read_bound_comb ;
324
    end
325
 
326
    // down counter with load
327
    always@(posedge reset_in or posedge wb_clock_in)
328
    begin
329
        if (reset_in)
330
            read_count <= #`FF_DELAY 0 ;
331
        else
332
        if (read_count_load)
333
            read_count <= #`FF_DELAY max_read_count ;
334
        else
335
        if (read_count_enable)
336
            read_count <= #`FF_DELAY read_count - 1'b1 ;
337
    end
338
 
339
// Logic used in State Machine logic implemented out of State Machine because of less delay!
340
//   definition of signal telling, when there is last data written into FIFO
341
always@(pci_tar_cmd or pci_tar_burst_ok or read_bound)
342
begin
343
    // burst is OK for reads when there is ((MEM_READ_LN or MEM_READ_MUL) and AD[1:0]==2'b00) OR
344
    //   (MEM_READ and Prefetchable_IMAGE and AD[1:0]==2'b00) -> pci_tar_burst_ok
345
    case ({pci_tar_cmd, pci_tar_burst_ok})
346
    {`BC_MEM_READ, 1'b1},
347
    {`BC_MEM_READ_LN, 1'b1} :
348
    begin   // when burst cycle
349
        if (read_bound)
350
            last_data_to_pcir_fifo = 1'b1 ;
351
        else
352
            last_data_to_pcir_fifo = 1'b0 ;
353
    end
354
    {`BC_MEM_READ_MUL, 1'b1} :
355
    begin   // when burst cycle
356
        if (read_bound)
357
            last_data_to_pcir_fifo = 1'b1 ;
358
        else
359
            last_data_to_pcir_fifo = 1'b0 ;
360
    end
361
    default :
362
    // {`BC_IO_READ, 1'b0},
363
    // {`BC_IO_READ, 1'b1},
364
    // {`BC_MEM_READ, 1'b0},
365
    // {`BC_MEM_READ_LN, 1'b0},
366
    // {`BC_MEM_READ_MUL, 1'b0}:
367
    begin   // when single cycle
368
        last_data_to_pcir_fifo = 1'b1 ;
369
    end
370
    endcase
371
end
372
 
373 86 mihad
reg             wait_for_wb_response ;
374
 
375
`ifdef PCI_WBM_NO_RESPONSE_CNT_DISABLE
376
wire set_retry = 1'b0 ;
377
 
378
`else
379 77 mihad
reg     [3:0]   wb_no_response_cnt ;
380
reg     [3:0]   wb_response_value ;
381
reg             set_retry ; // 
382
 
383
// internal WB no response retry generator counter!
384
always@(posedge reset_in or posedge wb_clock_in)
385
begin
386
    if (reset_in)
387
        wb_no_response_cnt <= #`FF_DELAY 4'h0 ;
388
    else
389
        wb_no_response_cnt <= #`FF_DELAY wb_response_value ;
390
end
391
// internal WB no response retry generator logic
392
always@(wait_for_wb_response or wb_no_response_cnt)
393
begin
394
    if (wb_no_response_cnt == 4'h8) // when there isn't response for 8 clocks, set internal retry
395
    begin
396
        wb_response_value = 4'h0 ;
397
        set_retry = 1'b1 ;
398
    end
399
    else
400
    begin
401
        if (wait_for_wb_response)
402
            wb_response_value = wb_no_response_cnt + 1'h1 ; // count clocks when no response
403
        else
404
            wb_response_value = 4'h0 ;
405
        set_retry = 1'b0 ;
406
    end
407
end
408 86 mihad
`endif
409 77 mihad
 
410
wire    retry = RTY_I || set_retry ; // retry signal - logic OR function between RTY_I and internal WB no response retry!
411
reg     [7:0]   rty_counter ; // output from retry counter
412
reg     [7:0]   rty_counter_in ; // input value - output value + 1 OR output value
413
reg             rty_counter_almost_max_value ; // signal tells when retry counter riches maximum value - 1!
414
reg             reset_rty_cnt ; // signal for asynchronous reset of retry counter after each complete transfere
415
 
416
// sinchronous signal after each transfere and asynchronous signal 'reset_rty_cnt' after reset  
417
//   for reseting the retry counter
418
always@(posedge reset_in or posedge wb_clock_in)
419
begin
420
    if (reset_in)
421
        reset_rty_cnt <= #`FF_DELAY 1'b1 ; // asynchronous set when reset signal is active
422
    else
423
        reset_rty_cnt <= #`FF_DELAY ACK_I || ERR_I || last_data_transferred ; // synchronous set after completed transfere
424
end
425
 
426
// Retry counter register control
427
always@(posedge reset_in or posedge wb_clock_in)
428
begin
429
    if (reset_in)
430
        rty_counter <= #`FF_DELAY 8'h00 ;
431
    else
432
    begin
433
        if (reset_rty_cnt)
434
            rty_counter <= #`FF_DELAY 8'h00 ;
435
        else if (retry)
436
            rty_counter <= #`FF_DELAY rty_counter_in ;
437
    end
438
end
439
// Retry counter logic
440
always@(rty_counter)
441
begin
442
    if(rty_counter == `WB_RTY_CNT_MAX - 1'b1) // stop counting
443
    begin
444
        rty_counter_in = rty_counter ;
445
        rty_counter_almost_max_value = 1'b1 ;
446
    end
447
    else
448
    begin
449
        rty_counter_in = rty_counter + 1'b1 ; // count up
450
        rty_counter_almost_max_value = 1'b0 ;
451
    end
452
end
453
 
454
reg     [31:0]  addr_cnt_out ;  // output value from address counter to WB ADDRESS output
455
reg     [31:0]  addr_cnt_in ;   // input address value to address counter
456
reg             addr_into_cnt ; // control signal for loading starting address into counter
457
reg             addr_count ; // control signal for count enable
458
reg     [3:0]   bc_register ; // used when error occures during writes!
459
 
460
// wb address counter register control
461
always@(posedge wb_clock_in or posedge reset_in)
462
begin
463
    if (reset_in) // reset counter
464
    begin
465
        addr_cnt_out <= #`FF_DELAY 32'h0000_0000 ;
466
        bc_register  <= #`FF_DELAY 4'h0 ;
467
    end
468
    else
469
    begin
470
        addr_cnt_out <= #`FF_DELAY addr_cnt_in ; // count up or hold value depending on cache line counter logic
471
        if (addr_into_cnt)
472
            bc_register  <= #`FF_DELAY pciw_fifo_cbe_in ;
473
    end
474
end
475
 
476
// when '1', the bus command is IO command - not supported commands are checked in pci_decoder modules
477
wire    io_memory_bus_command = !pci_tar_cmd[3] && !pci_tar_cmd[2] ;
478
 
479
// wb address counter logic
480
always@(addr_into_cnt or r_attempt or addr_count or pciw_fifo_addr_data_in or pci_tar_address or addr_cnt_out or
481
        io_memory_bus_command)
482
begin
483
    if (addr_into_cnt) // load starting address into counter
484
    begin
485
        if (r_attempt)
486
        begin // if read request, then load read addresss from PCI Target
487
            addr_cnt_in = {pci_tar_address[31:2], pci_tar_address[1] && io_memory_bus_command,
488
                                                  pci_tar_address[0] && io_memory_bus_command} ;
489
        end
490
        else
491
        begin // if not read request, then load write address from PCIW_FIFO
492
            addr_cnt_in = pciw_fifo_addr_data_in[31:0] ;
493
        end
494
    end
495
    else
496
    if (addr_count)
497
    begin
498
        addr_cnt_in = addr_cnt_out + 3'h4 ; // count up for 32-bit alligned address 
499
    end
500
    else
501
    begin
502
        addr_cnt_in = addr_cnt_out ;
503
    end
504
end
505
 
506
reg wb_stb_o ; // Internal signal for driwing STB_O on WB bus
507
reg wb_we_o ; // Internal signal for driwing WE_O on WB bus
508
reg wb_cyc_o ; // Internal signal for driwing CYC_O on WB bus and for enableing burst signal generation
509
 
510
reg retried ; // Signal is output value from FF and is set for one clock period after retried_d is set
511
reg retried_d ; // Signal is set whenever cycle is retried and is input to FF for delaying -> used in S_IDLE state
512
reg retried_write;
513
reg rty_i_delayed; // Dignal used for determinig the source of retry!
514
 
515
reg     first_data_is_burst ; // Signal is set in S_WRITE or S_READ states, when data transfere is burst!
516
reg     first_data_is_burst_reg ;
517
wire    burst_transfer ; // This signal is set when data transfere is burst and is reset with RESET or last data transfered
518
 
519
// FFs output signals tell, when there is first data out from FIFO (for BURST checking)
520
//   and for delaying retried signal
521
always@(posedge wb_clock_in or posedge reset_in)
522
begin
523
    if (reset_in) // reset signals
524
    begin
525
        retried <= #`FF_DELAY 1'b0 ;
526
        retried_write <= #`FF_DELAY 1'b0 ;
527
        rty_i_delayed <= #`FF_DELAY 1'B0 ;
528
    end
529
    else
530
    begin
531
        retried <= #`FF_DELAY retried_d ; // delaying retried signal  
532
        retried_write <= #`FF_DELAY retried ;
533
        rty_i_delayed <= #`FF_DELAY RTY_I ;
534
    end
535
end
536
 
537
// Determinig if first data is a part of BURST or just a single transfere!
538
always@(addr_into_cnt or r_attempt or pci_tar_burst_ok or max_read_count or
539
        pciw_fifo_control_in or pciw_fifo_empty_in)
540
begin
541
    if (addr_into_cnt)
542
    begin
543
        if (r_attempt)
544
        begin
545
                // burst is OK for reads when there is ((MEM_READ_LN or MEM_READ_MUL) and AD[1:0]==2'b00) OR
546
                //   (MEM_READ and Prefetchable_IMAGE and AD[1:0]==2'b00) -> pci_tar_burst_ok
547
            if  (pci_tar_burst_ok && (max_read_count != 8'h1))
548
                first_data_is_burst = 1'b1 ;
549
            else
550
                first_data_is_burst = 1'b0 ;
551
        end
552
        else
553
        begin
554
            first_data_is_burst = 1'b0 ;
555
        end
556
    end
557
    else
558
        first_data_is_burst = pciw_fifo_control_in[`BURST_BIT] && ~pciw_fifo_empty_in && ~pciw_fifo_control_in[`LAST_CTRL_BIT];
559
end
560
 
561
// FF for seting and reseting burst_transfer signal
562
always@(posedge wb_clock_in or posedge reset_in)
563
begin
564
    if (reset_in)
565
        first_data_is_burst_reg <= #`FF_DELAY 1'b0 ;
566
    else
567
    begin
568
        if (last_data_transferred || first_data_is_burst)
569
            first_data_is_burst_reg <= #`FF_DELAY ~last_data_transferred ;
570
    end
571
end
572
`ifdef REGISTER_WBM_OUTPUTS
573
    assign  burst_transfer = first_data_is_burst || first_data_is_burst_reg ;
574
`else
575
    assign  burst_transfer = (first_data_is_burst && ~last_data_transferred) || first_data_is_burst_reg ;
576
`endif
577
 
578
reg [(`WB_FSM_BITS - 1):0]  c_state ; //current state register
579
reg [(`WB_FSM_BITS - 1):0]  n_state ; //next state input to current state register
580
 
581
// state machine register control
582
always@(posedge wb_clock_in or posedge reset_in)
583
begin
584
    if (reset_in) // reset state machine ti S_IDLE state
585
        c_state <= #`FF_DELAY S_IDLE ;
586
    else
587
        c_state <= #`FF_DELAY n_state ;
588
end
589
 
590
// state machine logic
591
always@(c_state or
592
        ACK_I or
593
        RTY_I or
594
        ERR_I or
595
        w_attempt or
596
        r_attempt or
597
        retried or
598
        rty_i_delayed or
599
        pci_tar_read_request or
600
        rty_counter_almost_max_value or
601
        set_retry or
602
        last_data_to_pcir_fifo or
603
        first_wb_data_access or
604
        last_data_from_pciw_fifo_reg
605
        )
606
begin
607
    case (c_state)
608
    S_IDLE:
609
        begin
610
            // Default values for signals not used in this state
611
            pcir_fifo_wenable = 1'b0 ;
612
            pcir_fifo_control = 4'h0 ;
613
            addr_count = 1'b0 ;
614
            read_count_enable = 1'b0 ;
615
            pci_error_sig_out = 1'b0 ;
616
            error_source_out = 1'b0 ;
617
            retried_d = 1'b0 ;
618
            last_data_transferred = 1'b0 ;
619
            wb_read_done = 1'b0 ;
620
            wait_for_wb_response = 1'b0 ;
621
            write_rty_cnt_exp_out = 1'b0 ;
622
            pci_error_sig_out = 1'b0 ;
623
            read_rty_cnt_exp_out = 1'b0 ;
624
            case ({w_attempt, r_attempt, retried})
625
            3'b101 : // Write request for PCIW_FIFO to WB bus transaction
626
            begin    // If there was retry, the same transaction must be initiated
627
                pciw_fifo_renable = 1'b0 ; // the same data
628
                addr_into_cnt = 1'b0 ; // the same address
629
                read_count_load = 1'b0 ; // no need for cache line when there is write
630
                n_state = S_WRITE ;
631
            end
632
            3'b100 : // Write request for PCIW_FIFO to WB bus transaction
633
            begin    // If there is new transaction
634
                pciw_fifo_renable = 1'b1 ; // first location is address (in FIFO), next will be data
635
                addr_into_cnt = 1'b1 ; // address must be latched into address counter
636
                read_count_load = 1'b0 ; // no need for cache line when there is write
637
                n_state = S_WRITE ;
638
            end
639
            3'b011 : // Read request from PCI Target for WB bus to PCIR_FIFO transaction
640
            begin    // If there was retry, the same transaction must be initiated
641
                addr_into_cnt = 1'b0 ; // the same address
642
                read_count_load = 1'b0 ; // cache line counter must not be changed for retried read
643
                pciw_fifo_renable = 1'b0 ; // don't read from FIFO, when read transaction from WB to FIFO
644
                n_state = S_READ ;
645
            end
646
            3'b010 : // Read request from PCI Target for WB bus to PCIR_FIFO transaction
647
            begin    // If there is new transaction
648
                addr_into_cnt = 1'b1 ; // address must be latched into counter from separate request bus
649
                read_count_load = 1'b1 ; // cache line size must be latched into its counter
650
                pciw_fifo_renable = 1'b0 ; // don't read from FIFO, when read transaction from WB to FIFO
651
                n_state = S_READ ;
652
            end
653
            default : // stay in IDLE state
654
            begin
655
                pciw_fifo_renable = 1'b0 ;
656
                addr_into_cnt = 1'b0 ;
657
                read_count_load = 1'b0 ;
658
                n_state = S_IDLE ;
659
            end
660
            endcase
661
            wb_stb_o = 1'b0 ;
662
            wb_we_o = 1'b0 ;
663
            wb_cyc_o = 1'b0 ;
664
        end
665
    S_WRITE: // WRITE from PCIW_FIFO to WB bus
666
        begin
667
            // Default values for signals not used in this state
668
            pcir_fifo_wenable = 1'b0 ;
669
            pcir_fifo_control = 4'h0 ;
670
            addr_into_cnt = 1'b0 ;
671
            read_count_load = 1'b0 ;
672
            read_count_enable = 1'b0 ;
673
            wb_read_done = 1'b0 ;
674
            read_rty_cnt_exp_out = 1'b0 ;
675
            case ({ACK_I, ERR_I, RTY_I})
676
            3'b100 : // If writting of one data is acknowledged
677
            begin
678
                pciw_fifo_renable = 1'b1 ; // prepare next value (address when new trans., data when burst tran.)
679
                addr_count = 1'b1 ; // prepare next address if there will be burst
680
                pci_error_sig_out = 1'b0 ; // there was no error
681
                error_source_out = 1'b0 ;
682
                retried_d = 1'b0 ; // there was no retry
683
                write_rty_cnt_exp_out = 1'b0 ; // there was no retry
684
                wait_for_wb_response = 1'b0 ;
685
                if (last_data_from_pciw_fifo_reg) // if last data was transfered
686
                begin
687
                    n_state = S_IDLE ;
688
                    last_data_transferred = 1'b1 ; // signal for last data transfered
689
                end
690
                else
691
                begin
692
                    n_state = S_WRITE ;
693
                    last_data_transferred = 1'b0 ;
694
                end
695
            end
696
            3'b010 : // If writting of one data is terminated with ERROR
697
            begin
698
                pciw_fifo_renable = 1'b1 ; // prepare next value (address when new trans., data when cleaning FIFO)
699
                addr_count = 1'b0 ; // no need for new address
700
                retried_d = 1'b0 ; // there was no retry
701
                last_data_transferred = 1'b1 ; // signal for last data transfered
702
                pci_error_sig_out = 1'b1 ; // segnal for error reporting
703
                error_source_out = 1'b0 ; // error source from other side of WB bus
704
                write_rty_cnt_exp_out = 1'b0 ; // there was no retry
705
                wait_for_wb_response = 1'b0 ;
706
                if (last_data_from_pciw_fifo_reg) // if last data was transfered
707
                    n_state = S_IDLE ; // go to S_IDLE for new transfere
708
                else // if there wasn't last data of transfere
709
                    n_state = S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO
710
            end
711
            3'b001 : // If writting of one data is retried
712
            begin
713
                addr_count = 1'b0 ;
714
                last_data_transferred = 1'b0 ;
715
                retried_d = 1'b1 ; // there was a retry
716
                wait_for_wb_response = 1'b0 ;
717
                if(rty_counter_almost_max_value) // If retry counter reached maximum allowed value
718
                begin
719
                        if (last_data_from_pciw_fifo_reg) // if last data was transfered
720
                        pciw_fifo_renable = 1'b0 ;
721
                        else // if there wasn't last data of transfere
722
                            pciw_fifo_renable = 1'b1 ;
723
                        n_state = S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO
724
                    write_rty_cnt_exp_out = 1'b1 ; // signal for reporting write counter expired
725
                    pci_error_sig_out = 1'b1 ;
726
                    error_source_out = 1'b1 ; // error ocuerd because of retry counter
727
                end
728
                else
729
                begin
730
                        pciw_fifo_renable = 1'b0 ;
731
                    n_state = S_IDLE ; // go to S_IDLE state for retrying the transaction
732
                    write_rty_cnt_exp_out = 1'b0 ; // retry counter hasn't expired yet
733
                    pci_error_sig_out = 1'b0 ;
734
                    error_source_out = 1'b0 ;
735
                end
736
            end
737
            default :
738
            begin
739
                addr_count = 1'b0 ;
740
                last_data_transferred = 1'b0 ;
741
                wait_for_wb_response = 1'b1 ; // wait for WB device to response (after 8 clocks RTY CNT is incremented)
742
                error_source_out = 1'b0 ; // if error ocures, error source is from other WB bus side
743
                if((rty_counter_almost_max_value)&&(set_retry)) // when no WB response and RTY CNT reached maximum allowed value 
744
                begin
745
                    retried_d = 1'b1 ;
746
                        if (last_data_from_pciw_fifo_reg) // if last data was transfered
747
                        pciw_fifo_renable = 1'b0 ;
748
                        else // if there wasn't last data of transfere
749
                            pciw_fifo_renable = 1'b1 ;
750
                        n_state = S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO
751
                    write_rty_cnt_exp_out = 1'b1 ; // signal for reporting write counter expired
752
                    pci_error_sig_out = 1'b1 ; // signal for error reporting
753
                end
754
                else
755
                begin
756
                        pciw_fifo_renable = 1'b0 ;
757
                    retried_d = 1'b0 ;
758
                    n_state = S_WRITE ; // stay in S_WRITE state to wait WB to response
759
                    write_rty_cnt_exp_out = 1'b0 ; // retry counter hasn't expired yet
760
                    pci_error_sig_out = 1'b0 ;
761
                end
762
            end
763
            endcase
764
            wb_stb_o = 1'b1 ;
765
            wb_we_o = 1'b1 ;
766
            wb_cyc_o = 1'b1 ;
767
        end
768
    S_WRITE_ERR_RTY: // Clean current write transaction from PCIW_FIFO if ERROR or Retry counter expired occures
769
        begin
770
`ifdef REGISTER_WBM_OUTPUTS
771
            pciw_fifo_renable = !last_data_from_pciw_fifo_reg ; // put out next data (untill last data or FIFO empty)
772
`else
773
            pciw_fifo_renable = 1'b1 ; // put out next data (untill last data or FIFO empty)
774
`endif
775
            last_data_transferred = 1'b1 ; // after exiting this state, negedge of this signal is used
776
            // Default values for signals not used in this state
777
            pcir_fifo_wenable = 1'b0 ;
778
            pcir_fifo_control = 4'h0 ;
779
            addr_into_cnt = 1'b0 ;
780
            read_count_load = 1'b0 ;
781
            read_count_enable = 1'b0 ;
782
            addr_count = 1'b0 ;
783
            pci_error_sig_out = 1'b0 ;
784
            error_source_out = 1'b0 ;
785
            retried_d = 1'b0 ;
786
            wb_read_done = 1'b0 ;
787
            write_rty_cnt_exp_out = 1'b0 ;
788
            read_rty_cnt_exp_out = 1'b0 ;
789
            wait_for_wb_response = 1'b0 ;
790
            // If last data is cleaned out from PCIW_FIFO
791
            if (last_data_from_pciw_fifo_reg)
792
                n_state = S_IDLE ;
793
            else
794
                n_state = S_WRITE_ERR_RTY ; // Clean until last data is cleaned out from FIFO
795
            wb_stb_o = 1'b0 ;
796
            wb_we_o = 1'b0 ;
797
            wb_cyc_o = 1'b0 ;
798
        end
799
    S_READ: // READ from WB bus to PCIR_FIFO
800
        begin
801
            // Default values for signals not used in this state
802
            pciw_fifo_renable = 1'b0 ;
803
            addr_into_cnt = 1'b0 ;
804
            read_count_load = 1'b0 ;
805
            pci_error_sig_out = 1'b0 ;
806
            error_source_out = 1'b0 ;
807
            write_rty_cnt_exp_out = 1'b0 ;
808
            case ({ACK_I, ERR_I, RTY_I})
809
            3'b100 : // If reading of one data is acknowledged
810
            begin
811
                pcir_fifo_wenable = 1'b1 ; // enable writting data into PCIR_FIFO
812
                addr_count = 1'b1 ; // prepare next address if there will be burst
813
                read_count_enable = 1'b1 ; // decrease counter value for cache line size
814
                retried_d = 1'b0 ; // there was no retry
815
                read_rty_cnt_exp_out = 1'b0 ; // there was no retry
816
                wait_for_wb_response = 1'b0 ;
817
                // if last data was transfered
818
                if (last_data_to_pcir_fifo)
819
                begin
820
                    pcir_fifo_control[`LAST_CTRL_BIT]       = 1'b1 ; // FIFO must indicate LAST data transfered
821
                    pcir_fifo_control[`DATA_ERROR_CTRL_BIT] = 1'b0 ;
822
                    pcir_fifo_control[`UNUSED_CTRL_BIT]     = 1'b0 ;
823
                    pcir_fifo_control[`ADDR_CTRL_BIT]       = 1'b0 ;
824
                    last_data_transferred = 1'b1 ; // signal for last data transfered
825
                    wb_read_done = 1'b1 ; // signal last data of read transaction for PCI Target
826
                    n_state = S_TURN_ARROUND ;
827
                end
828
                else // if not last data transfered
829
                begin
830
                    pcir_fifo_control = 4'h0 ; // ZERO for control code
831
                    last_data_transferred = 1'b0 ; // not last data transfered
832
                    wb_read_done = 1'b0 ; // read is not done yet
833
                    n_state = S_READ ;
834
                end
835
            end
836
            3'b010 : // If reading of one data is terminated with ERROR
837
            begin
838
                pcir_fifo_wenable = 1'b1 ; // enable for writting to FIFO data with ERROR
839
                addr_count = 1'b0 ; // no need for new address
840
                pcir_fifo_control[`LAST_CTRL_BIT]       = 1'b0 ;
841
                pcir_fifo_control[`DATA_ERROR_CTRL_BIT] = 1'b1 ; // FIFO must indicate the DATA with ERROR
842
                pcir_fifo_control[`UNUSED_CTRL_BIT]     = 1'b0 ;
843
                pcir_fifo_control[`ADDR_CTRL_BIT]       = 1'b0 ;
844
                last_data_transferred = 1'b1 ; // signal for last data transfered
845
                wb_read_done = 1'b1 ; // signal last data of read transaction for PCI Target
846
                read_count_enable = 1'b0 ; // no need for cache line, when error occures
847
                n_state = S_TURN_ARROUND ;
848
                retried_d = 1'b0 ; // there was no retry
849
                wait_for_wb_response = 1'b0 ;
850
                read_rty_cnt_exp_out = 1'b0 ; // there was no retry
851
            end
852
            3'b001 : // If reading of one data is retried
853
            begin
854
                pcir_fifo_wenable = 1'b0 ;
855
                pcir_fifo_control = 4'h0 ;
856
                addr_count = 1'b0 ;
857
                read_count_enable = 1'b0 ;
858
                wait_for_wb_response = 1'b0 ;
859
                case ({first_wb_data_access, rty_counter_almost_max_value})
860
                2'b10 :
861
                begin  // if first data of the cycle (CYC_O) is retried - after each retry CYC_O goes inactive 
862
                    n_state = S_IDLE ; // go to S_IDLE state for retrying the transaction
863
                    read_rty_cnt_exp_out = 1'b0 ; // retry counter hasn't expired yet   
864
                    last_data_transferred = 1'b0 ;
865
                    wb_read_done = 1'b0 ;
866
                    retried_d = 1'b1 ; // there was a retry
867
                end
868
                2'b11 :
869
                begin  // if retry counter reached maximum value
870
                    n_state = S_READ_RTY ; // go here to wait for PCI Target to remove read request
871
                    read_rty_cnt_exp_out = 1'b1 ; // signal for reporting read counter expired  
872
                    last_data_transferred = 1'b0 ;
873
                    wb_read_done = 1'b0 ;
874
                    retried_d = 1'b1 ; // there was a retry
875
                end
876
                default : // if retry occures after at least 1 data was transferred without breaking cycle (CYC_O inactive)
877
                begin     // then PCI device will retry access!
878
                    n_state = S_TURN_ARROUND ; // go to S_TURN_ARROUND state 
879
                    read_rty_cnt_exp_out = 1'b0 ; // retry counter hasn't expired  
880
                    last_data_transferred = 1'b1 ;
881
                    wb_read_done = 1'b1 ;
882
                    retried_d = 1'b0 ; // retry must not be retried, since there is not a first data
883
                end
884
                endcase
885
            end
886
            default :
887
            begin
888
                addr_count = 1'b0 ;
889
                read_count_enable = 1'b0 ;
890
                read_rty_cnt_exp_out = 1'b0 ;
891
                wait_for_wb_response = 1'b1 ; // wait for WB device to response (after 8 clocks RTY CNT is incremented)
892
                if((rty_counter_almost_max_value)&&(set_retry)) // when no WB response and RTY CNT reached maximum allowed value 
893
                begin
894
                    retried_d = 1'b1 ;
895
                    n_state = S_TURN_ARROUND ; // go here to stop read request
896
                    pcir_fifo_wenable = 1'b1 ;
897
                    pcir_fifo_control[`LAST_CTRL_BIT]       = 1'b0 ;
898
                    pcir_fifo_control[`DATA_ERROR_CTRL_BIT] = 1'b1 ; // FIFO must indicate the DATA with ERROR
899
                    pcir_fifo_control[`UNUSED_CTRL_BIT]     = 1'b0 ;
900
                    pcir_fifo_control[`ADDR_CTRL_BIT]       = 1'b0 ;
901
                    last_data_transferred = 1'b1 ;
902
                    wb_read_done = 1'b1 ;
903
                end
904
                else
905
                begin
906
                    retried_d = 1'b0 ;
907
                    n_state = S_READ ; // stay in S_READ state to wait WB to response
908
                    pcir_fifo_wenable = 1'b0 ;
909
                    pcir_fifo_control = 4'h0 ;
910
                    last_data_transferred = 1'b0 ;
911
                    wb_read_done = 1'b0 ;
912
                end
913
            end
914
            endcase
915
            wb_stb_o = 1'b1 ;
916
            wb_we_o = 1'b0 ;
917
            wb_cyc_o = 1'b1 ;
918
        end
919
    S_READ_RTY: // Wait for PCI Target to remove read request, when retry counter reaches maximum value!
920
        begin
921
            // Default values for signals not used in this state
922
            pciw_fifo_renable = 1'b0 ;
923
            pcir_fifo_wenable = 1'b0 ;
924
            pcir_fifo_control = 4'h0 ;
925
            addr_into_cnt = 1'b0 ;
926
            read_count_load = 1'b0 ;
927
            read_count_enable = 1'b0 ;
928
            addr_count = 1'b0 ;
929
            pci_error_sig_out = 1'b0 ;
930
            error_source_out = 1'b0 ;
931
            retried_d = 1'b0 ;
932
            wb_read_done = 1'b0 ;
933
            write_rty_cnt_exp_out = 1'b0 ;
934
            read_rty_cnt_exp_out = 1'b0 ;
935
            wait_for_wb_response = 1'b0 ;
936
            // wait for PCI Target to remove read request
937
            if (pci_tar_read_request)
938
            begin
939
                n_state = S_READ_RTY ; // stay in this state until read request is removed
940
                last_data_transferred = 1'b0 ;
941
            end
942
            else // when read request is removed
943
            begin
944
                n_state = S_IDLE ;
945
                last_data_transferred = 1'b1 ; // when read request is removed, there is "last" data
946
            end
947
            wb_stb_o = 1'b0 ;
948
            wb_we_o = 1'b0 ;
949
            wb_cyc_o = 1'b0 ;
950
        end
951
    S_TURN_ARROUND: // Turn arround cycle after writting to PCIR_FIFO (for correct data when reading from PCIW_FIFO) 
952
        begin
953
            // Default values for signals not used in this state
954
            pciw_fifo_renable = 1'b0 ;
955
            pcir_fifo_wenable = 1'b0 ;
956
            pcir_fifo_control = 4'h0 ;
957
            addr_into_cnt = 1'b0 ;
958
            read_count_load = 1'b0 ;
959
            read_count_enable = 1'b0 ;
960
            addr_count = 1'b0 ;
961
            pci_error_sig_out = 1'b0 ;
962
            error_source_out = 1'b0 ;
963
            retried_d = 1'b0 ;
964
            last_data_transferred = 1'b1 ;
965
            wb_read_done = 1'b0 ;
966
            write_rty_cnt_exp_out = 1'b0 ;
967
            read_rty_cnt_exp_out = 1'b0 ;
968
            wait_for_wb_response = 1'b0 ;
969
            n_state = S_IDLE ;
970
            wb_stb_o = 1'b0 ;
971
            wb_we_o = 1'b0 ;
972
            wb_cyc_o = 1'b0 ;
973
        end
974
    default :
975
        begin
976
            // Default values for signals not used in this state
977
            pciw_fifo_renable = 1'b0 ;
978
            pcir_fifo_wenable = 1'b0 ;
979
            pcir_fifo_control = 4'h0 ;
980
            addr_into_cnt = 1'b0 ;
981
            read_count_load = 1'b0 ;
982
            read_count_enable = 1'b0 ;
983
            addr_count = 1'b0 ;
984
            pci_error_sig_out = 1'b0 ;
985
            error_source_out = 1'b0 ;
986
            retried_d = 1'b0 ;
987
            last_data_transferred = 1'b0 ;
988
            wb_read_done = 1'b0 ;
989
            write_rty_cnt_exp_out = 1'b0 ;
990
            read_rty_cnt_exp_out = 1'b0 ;
991
            wait_for_wb_response = 1'b0 ;
992
            n_state = S_IDLE ;
993
            wb_stb_o = 1'b0 ;
994
            wb_we_o = 1'b0 ;
995
            wb_cyc_o = 1'b0 ;
996
        end
997
    endcase
998
end
999
 
1000
// Signal for retry monitor in state machine when there is read and first (or single) data access
1001
wire ack_rty_response = ACK_I || RTY_I ;
1002
 
1003
// Signal first_wb_data_access is set when no WB cycle present till end of first data access of WB cycle on WB bus
1004
always@(posedge wb_clock_in or posedge reset_in)
1005
begin
1006
    if (reset_in)
1007
        first_wb_data_access = 1'b1 ;
1008
    else
1009
    begin
1010
        if (~wb_cyc_o)
1011
            first_wb_data_access = 1'b1 ;
1012
        else if (ack_rty_response)
1013
            first_wb_data_access = 1'b0 ;
1014
    end
1015
end
1016
 
1017
reg     [3:0]   wb_sel_o;
1018
always@(pciw_fifo_cbe_in or pci_tar_be or wb_we_o or burst_transfer or pci_tar_read_request)
1019
begin
1020
    case ({wb_we_o, burst_transfer, pci_tar_read_request})
1021
    3'b100,
1022
    3'b101,
1023
    3'b110,
1024
    3'b111:
1025
        wb_sel_o = ~pciw_fifo_cbe_in ;
1026
    3'b011:
1027
        wb_sel_o = 4'hf ;
1028
    default:
1029
        wb_sel_o = ~pci_tar_be ;
1030
    endcase
1031
end
1032
 
1033
// Signals to FIFO
1034
assign  pcir_fifo_be_out = 4'hf ; // pci_tar_be ;
1035
 
1036
// OUTPUT signals
1037
assign  pci_error_bc = bc_register ;
1038
 
1039
assign  ADR_O = addr_cnt_out ;
1040
 
1041
`ifdef REGISTER_WBM_OUTPUTS
1042
 
1043
    reg     no_sel_o_change_due_rty;
1044
    reg     wb_cyc_reg ;
1045
    always@(posedge wb_clock_in or posedge reset_in)
1046
    begin
1047
        if (reset_in)
1048
        begin
1049
                no_sel_o_change_due_rty <= #`FF_DELAY 1'b0;
1050
            CYC_O   <= #`FF_DELAY 1'h0 ;
1051
            STB_O   <= #`FF_DELAY 1'h0 ;
1052
            WE_O    <= #`FF_DELAY 1'h0 ;
1053
            CAB_O   <= #`FF_DELAY 1'h0 ;
1054
            MDATA_O <= #`FF_DELAY 32'h0 ;
1055
            SEL_O   <= #`FF_DELAY 4'h0 ;
1056
            wb_cyc_reg <= #`FF_DELAY 1'h0 ;
1057
            wb_read_done_out <= #`FF_DELAY 1'b0 ;
1058
            pcir_fifo_data_out <= #`FF_DELAY 32'h0 ;
1059
            pcir_fifo_wenable_out <= #`FF_DELAY 1'b0 ;
1060
            pcir_fifo_control_out <= #`FF_DELAY 1'b0 ;
1061
        end
1062
        else
1063
        begin
1064
                if (w_attempt)
1065
                    if (ACK_I || ERR_I || last_data_transferred)
1066
                        no_sel_o_change_due_rty <= #`FF_DELAY 1'b0;
1067
                    else if (retry)
1068
                        no_sel_o_change_due_rty <= #`FF_DELAY 1'b1;
1069
            if (wb_cyc_o)
1070
            begin // retry = RTY_I || set_retry
1071
                CYC_O   <= #`FF_DELAY ~((ACK_I || retry || ERR_I) && (last_data_transferred || retried_d)) ;
1072
                CAB_O   <= #`FF_DELAY ~((ACK_I || retry || ERR_I) && (last_data_transferred || retried_d)) && burst_transfer ;
1073
                STB_O   <= #`FF_DELAY ~((ACK_I || retry || ERR_I) && (last_data_transferred || retried_d)) ;
1074
            end
1075
            WE_O    <= #`FF_DELAY wb_we_o ;
1076
            if (((wb_cyc_o && ~wb_cyc_reg && !retried_write) || ACK_I) && wb_we_o)
1077
                MDATA_O <= #`FF_DELAY pciw_fifo_addr_data_in ;
1078
            if (w_attempt)
1079
            begin
1080
                if (((wb_cyc_o && ~wb_cyc_reg && !retried_write) || ACK_I) && wb_we_o)
1081
                    SEL_O   <= #`FF_DELAY ~pciw_fifo_cbe_in ;
1082
            end
1083
            else
1084
            begin
1085
                if ((wb_cyc_o && ~wb_cyc_reg) || ACK_I)
1086
                    SEL_O   <= #`FF_DELAY wb_sel_o ;
1087
            end
1088
            wb_cyc_reg <= #`FF_DELAY wb_cyc_o ;
1089
            wb_read_done_out <= #`FF_DELAY wb_read_done ;
1090
            pcir_fifo_data_out <= #`FF_DELAY MDATA_I ;
1091
            pcir_fifo_wenable_out <= #`FF_DELAY pcir_fifo_wenable ;
1092
            pcir_fifo_control_out <= #`FF_DELAY pcir_fifo_control ;
1093
        end
1094
    end
1095
    always@(pciw_fifo_renable or last_data_from_pciw_fifo_reg or wb_cyc_o or wb_cyc_reg or wb_we_o or retried_write or
1096
            pciw_fifo_control_in or pciw_fifo_empty_in)
1097
    begin
1098
        pciw_fifo_renable_out <=    #`FF_DELAY (pciw_fifo_renable && ~wb_cyc_o) ||
1099
                                    (pciw_fifo_renable && ~last_data_from_pciw_fifo_reg) ||
1100
                                    (wb_cyc_o && ~wb_cyc_reg && wb_we_o && !retried_write) ;
1101
        last_data_from_pciw_fifo_reg <= #`FF_DELAY pciw_fifo_control_in[`ADDR_CTRL_BIT] || pciw_fifo_empty_in ;
1102
    end
1103
`else
1104
    always@(wb_cyc_o or wb_stb_o or wb_we_o or burst_transfer or pciw_fifo_addr_data_in or wb_sel_o or
1105
            wb_read_done or MDATA_I or pcir_fifo_wenable or pcir_fifo_control)
1106
    begin
1107
        CYC_O   = wb_cyc_o ;
1108
        STB_O   = wb_stb_o ;
1109
        WE_O    = wb_we_o ;
1110
        CAB_O   = wb_cyc_o & burst_transfer ;
1111
        MDATA_O = pciw_fifo_addr_data_in ;
1112
        SEL_O   = wb_sel_o ;
1113
        wb_read_done_out = wb_read_done ;
1114
        pcir_fifo_data_out = MDATA_I ;
1115
        pcir_fifo_wenable_out = pcir_fifo_wenable ;
1116
        pcir_fifo_control_out = pcir_fifo_control ;
1117
    end
1118
    always@(pciw_fifo_renable or last_data_from_pciw_fifo)
1119
    begin
1120
        pciw_fifo_renable_out = pciw_fifo_renable ;
1121
        last_data_from_pciw_fifo_reg = last_data_from_pciw_fifo ;
1122
    end
1123
`endif
1124
 
1125
 
1126
endmodule
1127
 

powered by: WebSVN 2.1.0

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