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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_9/] [rtl/] [verilog/] [pci_wb_master.v] - Blame information for rev 154

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

powered by: WebSVN 2.1.0

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