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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [wb_master.v] - Blame information for rev 26

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

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

powered by: WebSVN 2.1.0

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