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

Subversion Repositories pci

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

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

powered by: WebSVN 2.1.0

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