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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_3/] [rtl/] [verilog/] [wb_master.v] - Diff between revs 21 and 26

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 21 Rev 26
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////                                                              ////
////                                                              ////
////  File name: wb_master.v                                      ////
////  File name: wb_master.v                                      ////
////                                                              ////
////                                                              ////
////  This file is part of the "PCI bridge" project               ////
////  This file is part of the "PCI bridge" project               ////
////  http://www.opencores.org/cores/pci/                         ////
////  http://www.opencores.org/cores/pci/                         ////
////                                                              ////
////                                                              ////
////  Author(s):                                                  ////
////  Author(s):                                                  ////
////      - Tadej Markovic, tadej@opencores.org                   ////
////      - Tadej Markovic, tadej@opencores.org                   ////
////                                                              ////
////                                                              ////
////  All additional information is avaliable in the README.txt   ////
////  All additional information is avaliable in the README.txt   ////
////  file.                                                       ////
////  file.                                                       ////
////                                                              ////
////                                                              ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////                                                              ////
////                                                              ////
//// Copyright (C) 2000 Tadej Markovic, tadej@opencores.org       ////
//// Copyright (C) 2000 Tadej Markovic, tadej@opencores.org       ////
////                                                              ////
////                                                              ////
//// This source file may be used and distributed without         ////
//// This source file may be used and distributed without         ////
//// restriction provided that this copyright statement is not    ////
//// restriction provided that this copyright statement is not    ////
//// removed from the file and that any derivative work contains  ////
//// removed from the file and that any derivative work contains  ////
//// the original copyright notice and the associated disclaimer. ////
//// the original copyright notice and the associated disclaimer. ////
////                                                              ////
////                                                              ////
//// This source file is free software; you can redistribute it   ////
//// This source file is free software; you can redistribute it   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// Public License as published by the Free Software Foundation; ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any   ////
//// either version 2.1 of the License, or (at your option) any   ////
//// later version.                                               ////
//// later version.                                               ////
////                                                              ////
////                                                              ////
//// This source is distributed in the hope that it will be       ////
//// This source is distributed in the hope that it will be       ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// details.                                                     ////
//// details.                                                     ////
////                                                              ////
////                                                              ////
//// You should have received a copy of the GNU Lesser General    ////
//// You should have received a copy of the GNU Lesser General    ////
//// Public License along with this source; if not, download it   ////
//// Public License along with this source; if not, download it   ////
//// from http://www.opencores.org/lgpl.shtml                     ////
//// from http://www.opencores.org/lgpl.shtml                     ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//
//
// CVS Revision History
// CVS Revision History
//
//
// $Log: not supported by cvs2svn $
// $Log: not supported by cvs2svn $
 
// Revision 1.3  2002/02/01 15:25:13  mihad
 
// Repaired a few bugs, updated specification, added test bench files and design document
 
//
// Revision 1.2  2001/10/05 08:14:30  mihad
// Revision 1.2  2001/10/05 08:14:30  mihad
// Updated all files with inclusion of timescale file for simulation purposes.
// Updated all files with inclusion of timescale file for simulation purposes.
//
//
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
// Revision 1.1.1.1  2001/10/02 15:33:47  mihad
// New project directory structure
// New project directory structure
//
//
//
//
 
 
`define WB_FSM_BITS 3 // number of bits needed for FSM states
`define WB_FSM_BITS 3 // number of bits needed for FSM states
 
 
 
 
`include "bus_commands.v"
`include "bus_commands.v"
`include "pci_constants.v"
`include "pci_constants.v"
//synopsys translate_off
//synopsys translate_off
`include "timescale.v"
`include "timescale.v"
//synopsys translate_on
//synopsys translate_on
 
 
module WB_MASTER (  wb_clock_in,                // CLK_I
module WB_MASTER (  wb_clock_in,                // CLK_I
                    reset_in,                   // RST_I
                    reset_in,                   // RST_I
 
 
                    pci_tar_read_request,
                    pci_tar_read_request,
                                        pci_tar_address,
                                        pci_tar_address,
                                        pci_tar_cmd,
                                        pci_tar_cmd,
                                        pci_tar_be,
                                        pci_tar_be,
                                        pci_tar_burst_ok,
                                        pci_tar_burst_ok,
                                        pci_cache_line_size,
                                        pci_cache_line_size,
                                        cache_lsize_not_zero,
                                        cache_lsize_not_zero,
                                        wb_read_done_out,
                                        wb_read_done_out,
 
                                        w_attempt,
 
 
                                        pcir_fifo_wenable_out,
                                        pcir_fifo_wenable_out,
                                        pcir_fifo_data_out,
                                        pcir_fifo_data_out,
                                        pcir_fifo_be_out,
                                        pcir_fifo_be_out,
                                        pcir_fifo_control_out,
                                        pcir_fifo_control_out,
                                        //pcir_fifo_renable_out,                        for PCI Target !!!
                                        //pcir_fifo_renable_out,                        for PCI Target !!!
                                        //pcir_fifo_data_in,                            for PCI Target !!!
                                        //pcir_fifo_data_in,                            for PCI Target !!!
                                        //pcir_fifo_be_in,                                      for PCI Target !!!
                                        //pcir_fifo_be_in,                                      for PCI Target !!!
                                        //pcir_fifo_control_in,                         for PCI Target !!!
                                        //pcir_fifo_control_in,                         for PCI Target !!!
                                        //pcir_fifo_flush_out,                          for PCI Target !!!
                                        //pcir_fifo_flush_out,                          for PCI Target !!!
                                        pcir_fifo_almost_full_in,
 
                                        pcir_fifo_full_in,
 
                                        //pcir_fifo_almost_empty_in,            for PCI Target !!!
                                        //pcir_fifo_almost_empty_in,            for PCI Target !!!
                                        //pcir_fifo_empty_in,                           NOT used
                                        //pcir_fifo_empty_in,                           NOT used
                                        //pcir_fifo_transaction_ready_in,       NOT used
                                        //pcir_fifo_transaction_ready_in,       NOT used
                                        //pciw_fifo_wenable_out,                        for PCI Target !!!
                                        //pciw_fifo_wenable_out,                        for PCI Target !!!
                                        //pciw_fifo_addr_data_out,                      for PCI Target !!!   
                                        //pciw_fifo_addr_data_out,                      for PCI Target !!!   
                                        //pciw_fifo_cbe_out,                            for PCI Target !!!
                                        //pciw_fifo_cbe_out,                            for PCI Target !!!
                                        //pciw_fifo_control_out,                        for PCI Target !!!       
                                        //pciw_fifo_control_out,                        for PCI Target !!!       
                                        pciw_fifo_renable_out,
                                        pciw_fifo_renable_out,
                                        pciw_fifo_addr_data_in,
                                        pciw_fifo_addr_data_in,
                                        pciw_fifo_cbe_in,
                                        pciw_fifo_cbe_in,
                                        pciw_fifo_control_in,
                                        pciw_fifo_control_in,
                                        //pciw_fifo_flush_out,                          NOT used
                                        //pciw_fifo_flush_out,                          NOT used
                                        //pciw_fifo_almost_full_in,             for PCI Target !!!
                                        //pciw_fifo_almost_full_in,             for PCI Target !!!
                                        //pciw_fifo_full_in,                            for PCI Target !!!
                                        //pciw_fifo_full_in,                            for PCI Target !!!
                                        pciw_fifo_almost_empty_in,
                                        pciw_fifo_almost_empty_in,
                                        pciw_fifo_empty_in,
                                        pciw_fifo_empty_in,
                                        pciw_fifo_transaction_ready_in,
                                        pciw_fifo_transaction_ready_in,
 
 
                                        pci_error_sig_out,
                                        pci_error_sig_out,
                                        pci_error_bc,
                                        pci_error_bc,
                                        write_rty_cnt_exp_out,
                                        write_rty_cnt_exp_out,
                                        error_source_out,
                                        error_source_out,
                                        read_rty_cnt_exp_out,
                                        read_rty_cnt_exp_out,
 
 
                    CYC_O,
                    CYC_O,
                    STB_O,
                    STB_O,
                    WE_O,
                    WE_O,
                    SEL_O,
                    SEL_O,
                    ADR_O,
                    ADR_O,
                    MDATA_I,
                    MDATA_I,
                    MDATA_O,
                    MDATA_O,
                    ACK_I,
                    ACK_I,
                    RTY_I,
                    RTY_I,
                    ERR_I,
                    ERR_I,
                    CAB_O
                    CAB_O
                );
                );
 
 
/*----------------------------------------------------------------------------------------------------------------------
/*----------------------------------------------------------------------------------------------------------------------
Various parameters needed for state machine and other stuff
Various parameters needed for state machine and other stuff
----------------------------------------------------------------------------------------------------------------------*/
----------------------------------------------------------------------------------------------------------------------*/
parameter               S_IDLE                  = `WB_FSM_BITS'h0 ;
parameter               S_IDLE                  = `WB_FSM_BITS'h0 ;
parameter               S_WRITE                 = `WB_FSM_BITS'h1 ;
parameter               S_WRITE                 = `WB_FSM_BITS'h1 ;
parameter               S_WRITE_ERR_RTY = `WB_FSM_BITS'h2 ;
parameter               S_WRITE_ERR_RTY = `WB_FSM_BITS'h2 ;
parameter               S_READ                  = `WB_FSM_BITS'h3 ;
parameter               S_READ                  = `WB_FSM_BITS'h3 ;
parameter               S_READ_RTY              = `WB_FSM_BITS'h4 ;
parameter               S_READ_RTY              = `WB_FSM_BITS'h4 ;
parameter               S_TURN_ARROUND  = `WB_FSM_BITS'h5 ;
parameter               S_TURN_ARROUND  = `WB_FSM_BITS'h5 ;
 
 
/*----------------------------------------------------------------------------------------------------------------------
/*----------------------------------------------------------------------------------------------------------------------
System signals inputs
System signals inputs
wb_clock_in - WISHBONE bus clock input
wb_clock_in - WISHBONE bus clock input
reset_in    - system reset input controlled by bridge's reset logic
reset_in    - system reset input controlled by bridge's reset logic
----------------------------------------------------------------------------------------------------------------------*/
----------------------------------------------------------------------------------------------------------------------*/
input                   wb_clock_in ;
input                   wb_clock_in ;
input                   reset_in ;
input                   reset_in ;
 
 
/*----------------------------------------------------------------------------------------------------------------------
/*----------------------------------------------------------------------------------------------------------------------
Control signals from PCI Target for READS to PCIR_FIFO
Control signals from PCI Target for READS to PCIR_FIFO
---------------------------------------------------------------------------------------------------------------------*/
---------------------------------------------------------------------------------------------------------------------*/
input                   pci_tar_read_request ;          // read request from PCI Target
input                   pci_tar_read_request ;          // read request from PCI Target
input   [31:0]   pci_tar_address ;                       // address for requested read from PCI Target                                   
input   [31:0]   pci_tar_address ;                       // address for requested read from PCI Target                                   
input   [3:0]    pci_tar_cmd ;                           // command for requested read from PCI Target                                   
input   [3:0]    pci_tar_cmd ;                           // command for requested read from PCI Target                                   
input   [3:0]    pci_tar_be ;                            // byte enables for requested read from PCI Target              
input   [3:0]    pci_tar_be ;                            // byte enables for requested read from PCI Target              
input                   pci_tar_burst_ok ;
input                   pci_tar_burst_ok ;
input   [7:0]    pci_cache_line_size ;           // CACHE line size register value for burst length   
input   [7:0]    pci_cache_line_size ;           // CACHE line size register value for burst length   
input                   cache_lsize_not_zero ;
input                   cache_lsize_not_zero ;
output                  wb_read_done_out ;                              // read done and PCIR_FIFO has data ready
output                  wb_read_done_out ;                              // read done and PCIR_FIFO has data ready
 
output                  w_attempt ;
 
 
reg                             wb_read_done_out ;
reg                             wb_read_done_out ;
reg                             wb_read_done ;
reg                             wb_read_done ;
 
 
/*----------------------------------------------------------------------------------------------------------------------
/*----------------------------------------------------------------------------------------------------------------------
PCIR_FIFO control signals used for sinking data into PCIR_FIFO and status monitoring
PCIR_FIFO control signals used for sinking data into PCIR_FIFO and status monitoring
---------------------------------------------------------------------------------------------------------------------*/
---------------------------------------------------------------------------------------------------------------------*/
output                  pcir_fifo_wenable_out ;         // PCIR_FIFO write enable output
output                  pcir_fifo_wenable_out ;         // PCIR_FIFO write enable output
output  [31:0]   pcir_fifo_data_out ;            // data output to PCIR_FIFO
output  [31:0]   pcir_fifo_data_out ;            // data output to PCIR_FIFO
output  [3:0]    pcir_fifo_be_out ;                      // byte enable output to PCIR_FIFO
output  [3:0]    pcir_fifo_be_out ;                      // byte enable output to PCIR_FIFO
output  [3:0]    pcir_fifo_control_out ;         // control bus output to PCIR_FIFO
output  [3:0]    pcir_fifo_control_out ;         // control bus output to PCIR_FIFO
input                   pcir_fifo_almost_full_in ;      // almost full status indicator from PCIR_FIFO
 
input                   pcir_fifo_full_in ;                     // full status indicator from PCIR_FIFO
 
 
 
reg             [31:0]   pcir_fifo_data_out ;
reg             [31:0]   pcir_fifo_data_out ;
reg                             pcir_fifo_wenable_out ;
reg                             pcir_fifo_wenable_out ;
reg                             pcir_fifo_wenable ;
reg                             pcir_fifo_wenable ;
reg             [3:0]    pcir_fifo_control_out ;
reg             [3:0]    pcir_fifo_control_out ;
reg             [3:0]    pcir_fifo_control ;
reg             [3:0]    pcir_fifo_control ;
 
 
/*----------------------------------------------------------------------------------------------------------------------
/*----------------------------------------------------------------------------------------------------------------------
PCIW_FIFO control signals used for fetching data from PCIW_FIFO and status monitoring
PCIW_FIFO control signals used for fetching data from PCIW_FIFO and status monitoring
---------------------------------------------------------------------------------------------------------------------*/
---------------------------------------------------------------------------------------------------------------------*/
output                  pciw_fifo_renable_out ;         // read enable for PCIW_FIFO output
output                  pciw_fifo_renable_out ;         // read enable for PCIW_FIFO output
input   [31:0]   pciw_fifo_addr_data_in ;        // address and data input from PCIW_FIFO
input   [31:0]   pciw_fifo_addr_data_in ;        // address and data input from PCIW_FIFO
input   [3:0]    pciw_fifo_cbe_in ;                      // command and byte_enables from PCIW_FIFO
input   [3:0]    pciw_fifo_cbe_in ;                      // command and byte_enables from PCIW_FIFO
input   [3:0]    pciw_fifo_control_in ;          // control bus input from PCIW_FIFO
input   [3:0]    pciw_fifo_control_in ;          // control bus input from PCIW_FIFO
input                   pciw_fifo_almost_empty_in ;     // almost empty status indicator from PCIW_FIFO
input                   pciw_fifo_almost_empty_in ;     // almost empty status indicator from PCIW_FIFO
input                   pciw_fifo_empty_in ;            // empty status indicator from PCIW_FIFO
input                   pciw_fifo_empty_in ;            // empty status indicator from PCIW_FIFO
input                   pciw_fifo_transaction_ready_in ;        // write transaction is ready in PCIW_FIFO
input                   pciw_fifo_transaction_ready_in ;        // write transaction is ready in PCIW_FIFO
 
 
reg                             pciw_fifo_renable_out ;
reg                             pciw_fifo_renable_out ;
reg                             pciw_fifo_renable ;
reg                             pciw_fifo_renable ;
 
 
/*----------------------------------------------------------------------------------------------------------------------
/*----------------------------------------------------------------------------------------------------------------------
Control INPUT / OUTPUT signals for configuration space reporting registers !!!
Control INPUT / OUTPUT signals for configuration space reporting registers !!!
---------------------------------------------------------------------------------------------------------------------*/
---------------------------------------------------------------------------------------------------------------------*/
output                  pci_error_sig_out ;                     // When error occures (on WB bus, retry counter, etc.)
output                  pci_error_sig_out ;                     // When error occures (on WB bus, retry counter, etc.)
output  [3:0]   pci_error_bc ;                           // bus command at which error occured !
output  [3:0]   pci_error_bc ;                           // bus command at which error occured !
output                  write_rty_cnt_exp_out ;         // Signaling that RETRY counter has expired during write transaction!
output                  write_rty_cnt_exp_out ;         // Signaling that RETRY counter has expired during write transaction!
output                  read_rty_cnt_exp_out ;          // Signaling that RETRY counter has expired during read transaction!
output                  read_rty_cnt_exp_out ;          // Signaling that RETRY counter has expired during read transaction!
                                                                                        //  if error_source is '0' other side didn't respond
                                                                                        //  if error_source is '0' other side didn't respond
                                                                                        //  if error_source is '1' other side RETRIED for max retry counter value
                                                                                        //  if error_source is '1' other side RETRIED for max retry counter value
output                  error_source_out ;                      // Signaling error source - '0' other WB side signaled error OR didn't respond
output                  error_source_out ;                      // Signaling error source - '0' other WB side signaled error OR didn't respond
                                                                                        //   if '1' wridge counted max value in retry counter because of RTY responds
                                                                                        //   if '1' wridge counted max value in retry counter because of RTY responds
reg                             pci_error_sig_out ;
reg                             pci_error_sig_out ;
reg                             write_rty_cnt_exp_out ;
reg                             write_rty_cnt_exp_out ;
reg                             read_rty_cnt_exp_out ;
reg                             read_rty_cnt_exp_out ;
reg                             error_source_out ;
reg                             error_source_out ;
 
 
/*----------------------------------------------------------------------------------------------------------------------
/*----------------------------------------------------------------------------------------------------------------------
WISHBONE bus interface signals - can be connected directly to WISHBONE bus
WISHBONE bus interface signals - can be connected directly to WISHBONE bus
---------------------------------------------------------------------------------------------------------------------*/
---------------------------------------------------------------------------------------------------------------------*/
output          CYC_O ;                 // cycle indicator output
output          CYC_O ;                 // cycle indicator output
output          STB_O ;                 // strobe output - data is valid when strobe and cycle indicator are high
output          STB_O ;                 // strobe output - data is valid when strobe and cycle indicator are high
output          WE_O  ;                 // write enable output - 1 - write operation, 0 - read operation
output          WE_O  ;                 // write enable output - 1 - write operation, 0 - read operation
output  [3:0]   SEL_O ;                  // Byte select outputs
output  [3:0]   SEL_O ;                  // Byte select outputs
output  [31:0]  ADR_O ;                  // WISHBONE address output
output  [31:0]  ADR_O ;                  // WISHBONE address output
input   [31:0]  MDATA_I ;                // WISHBONE slave interface input data bus
input   [31:0]  MDATA_I ;                // WISHBONE slave interface input data bus
output  [31:0]  MDATA_O ;                // WISHBONE slave interface output data bus
output  [31:0]  MDATA_O ;                // WISHBONE slave interface output data bus
input           ACK_I ;                 // Acknowledge input - qualifies valid data on data output bus or received data on data input bus
input           ACK_I ;                 // Acknowledge input - qualifies valid data on data output bus or received data on data input bus
input           RTY_I ;                 // retry input - signals from WISHBONE slave that cycle should be terminated and retried later
input           RTY_I ;                 // retry input - signals from WISHBONE slave that cycle should be terminated and retried later
input           ERR_I ;                 // Signals from WISHBONE slave that access resulted in an error
input           ERR_I ;                 // Signals from WISHBONE slave that access resulted in an error
output          CAB_O ;                 // consecutive address burst output - indicated that master will do a serial address transfer in current cycle
output          CAB_O ;                 // consecutive address burst output - indicated that master will do a serial address transfer in current cycle
 
 
reg                     CYC_O ;
reg                     CYC_O ;
reg                     STB_O ;
reg                     STB_O ;
reg                     WE_O  ;
reg                     WE_O  ;
reg             [3:0]   SEL_O ;
reg             [3:0]   SEL_O ;
reg             [31:0]  MDATA_O ;
reg             [31:0]  MDATA_O ;
reg                     CAB_O ;
reg                     CAB_O ;
 
 
 
 
/*###########################################################################################################
/*###########################################################################################################
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
        LOGIC, COUNTERS, STATE MACHINE and some control register bits
        LOGIC, COUNTERS, STATE MACHINE and some control register bits
        =============================================================
        =============================================================
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
###########################################################################################################*/
###########################################################################################################*/
 
 
 
reg                             last_data_transferred ; // signal is set by STATE MACHINE after each complete transfere !
 
 
// wire for write attempt - 1 when PCI Target attempt to write and PCIW_FIFO has a write transaction ready
// wire for write attempt - 1 when PCI Target attempt to write and PCIW_FIFO has a write transaction ready
wire w_attempt = ( pciw_fifo_transaction_ready_in && ~pciw_fifo_empty_in ) ;
`ifdef REGISTER_WBM_OUTPUTS
 
        reg             w_attempt;
 
        always@(posedge wb_clock_in or posedge reset_in)
 
        begin
 
                if (reset_in)
 
                        w_attempt <= #`FF_DELAY 1'b0;
 
                else
 
                begin
 
                        if (pciw_fifo_transaction_ready_in && ~pciw_fifo_empty_in)
 
                                w_attempt <= #`FF_DELAY 1'b1;
 
                        else
 
                                if (last_data_transferred)
 
                                        w_attempt <= #`FF_DELAY 1'b0;
 
                end
 
        end
 
`else
 
        assign w_attempt = ( pciw_fifo_transaction_ready_in && ~pciw_fifo_empty_in ) ;
 
`endif
 
 
// wire for read attempt - 1 when PCI Target is attempting a read and PCIR_FIFO is not full !
// wire for read attempt - 1 when PCI Target is attempting a read and PCIR_FIFO is not full !
// because of transaction ordering, PCI Master must not start read untill all writes are done -> at that
// because of transaction ordering, PCI Master must not start read untill all writes are done -> at that
//   moment PCIW_FIFO is empty !!! (when read is pending PCI Target will block new reads and writes)
//   moment PCIW_FIFO is empty !!! (when read is pending PCI Target will block new reads and writes)
wire r_attempt = ( pci_tar_read_request && ~pcir_fifo_full_in && pciw_fifo_empty_in ) ;
wire r_attempt = ( pci_tar_read_request && !w_attempt);// pciw_fifo_empty_in ) ; 
 
 
// Signal is used for reads on WB, when there is retry!
// Signal is used for reads on WB, when there is retry!
reg                             first_wb_data_access ;
reg                             first_wb_data_access ;
 
 
reg                             last_data_from_pciw_fifo ;      // signal tells when there is last data in pciw_fifo
reg                             last_data_from_pciw_fifo ;      // signal tells when there is last data in pciw_fifo
reg                             last_data_from_pciw_fifo_reg ;
reg                             last_data_from_pciw_fifo_reg ;
reg                             last_data_to_pcir_fifo ;        // signal tells when there will be last data for pcir_fifo
reg                             last_data_to_pcir_fifo ;        // signal tells when there will be last data for pcir_fifo
 
 
// Logic used in State Machine logic implemented out of State Machine because of less delay!
// Logic used in State Machine logic implemented out of State Machine because of less delay!
always@(pciw_fifo_control_in or pciw_fifo_almost_empty_in)
always@(pciw_fifo_control_in or pciw_fifo_almost_empty_in)
begin
begin
        if (pciw_fifo_control_in[`LAST_CTRL_BIT] || pciw_fifo_almost_empty_in) // if last data is going to be transfered
        if (pciw_fifo_control_in[`LAST_CTRL_BIT] || pciw_fifo_almost_empty_in) // if last data is going to be transfered
                last_data_from_pciw_fifo <= 1'b1 ; // signal for last data from PCIW_FIFO
                last_data_from_pciw_fifo <= 1'b1 ; // signal for last data from PCIW_FIFO
        else
        else
                last_data_from_pciw_fifo <= 1'b0 ;
                last_data_from_pciw_fifo <= 1'b0 ;
end
end
 
 
 
 
        reg read_count_load;
        reg read_count_load;
        reg read_count_enable;
        reg read_count_enable;
 
 
        reg [(`PCIR_ADDR_LENGTH - 1):0] max_read_count ;
        reg [(`PCIR_ADDR_LENGTH - 1):0] max_read_count ;
        always@(pci_cache_line_size or cache_lsize_not_zero or pci_tar_cmd)
        always@(pci_cache_line_size or cache_lsize_not_zero or pci_tar_cmd)
        begin
        begin
                if (cache_lsize_not_zero)
                if (cache_lsize_not_zero)
                    if ( (pci_cache_line_size >= `PCIR_DEPTH) || (~pci_tar_cmd[1] && ~pci_tar_cmd[0]) )
                    if ( (pci_cache_line_size >= `PCIR_DEPTH) || (~pci_tar_cmd[1] && ~pci_tar_cmd[0]) )
                        // If cache line size is larger than FIFO or BC_MEM_READ_MUL command is performed!
                        // If cache line size is larger than FIFO or BC_MEM_READ_MUL command is performed!
                        max_read_count = `PCIR_DEPTH - 1'b1;
                        max_read_count = `PCIR_DEPTH - 1'b1;
                    else
                    else
                    max_read_count = pci_cache_line_size ;
                    max_read_count = pci_cache_line_size ;
            else
            else
                max_read_count = 1'b1;
                max_read_count = 1'b1;
        end
        end
 
 
        reg [(`PCIR_ADDR_LENGTH - 1):0] read_count ;
        reg [(`PCIR_ADDR_LENGTH - 1):0] read_count ;
 
 
        // cache line bound indicator - it signals when data for one complete cacheline was read
        // cache line bound indicator - it signals when data for one complete cacheline was read
        wire read_bound_comb = ~|( { read_count[(`PCIR_ADDR_LENGTH - 1):2], read_count[0] } ) ;
        wire read_bound_comb = ~|( { read_count[(`PCIR_ADDR_LENGTH - 1):2], read_count[0] } ) ;
 
 
        reg  read_bound ;
        reg  read_bound ;
        always@(posedge wb_clock_in or posedge reset_in)
        always@(posedge wb_clock_in or posedge reset_in)
        begin
        begin
            if ( reset_in )
            if ( reset_in )
                read_bound <= #`FF_DELAY 1'b0 ;
                read_bound <= #`FF_DELAY 1'b0 ;
            else if (read_count_load)
            else if (read_count_load)
                read_bound <= #`FF_DELAY 1'b0 ;
                read_bound <= #`FF_DELAY 1'b0 ;
            else if ( read_count_enable )
            else if ( read_count_enable )
                read_bound <= #`FF_DELAY read_bound_comb ;
                read_bound <= #`FF_DELAY read_bound_comb ;
        end
        end
 
 
        // down counter with load
        // down counter with load
        always@(posedge reset_in or posedge wb_clock_in)
        always@(posedge reset_in or posedge wb_clock_in)
        begin
        begin
            if (reset_in)
            if (reset_in)
                read_count <= #`FF_DELAY 0 ;
                read_count <= #`FF_DELAY 0 ;
            else
            else
            if (read_count_load)
            if (read_count_load)
                read_count <= #`FF_DELAY max_read_count ;
                read_count <= #`FF_DELAY max_read_count ;
            else
            else
            if (read_count_enable)
            if (read_count_enable)
                read_count <= #`FF_DELAY read_count - 1'b1 ;
                read_count <= #`FF_DELAY read_count - 1'b1 ;
        end
        end
 
 
 
 
 
 
wire    [7:0]    cache_line_wire ; // wire assigned directly from cache_line register !!!
 
// Logic used in State Machine logic implemented out of State Machine because of less delay!
// Logic used in State Machine logic implemented out of State Machine because of less delay!
//   definition of signal telling, when there is last data written into FIFO
//   definition of signal telling, when there is last data written into FIFO
always@(pci_tar_cmd or pci_tar_burst_ok or read_bound or pcir_fifo_almost_full_in)
always@(pci_tar_cmd or pci_tar_burst_ok or read_bound)
begin
begin
        // burst is OK for reads when there is ((MEM_READ_LN or MEM_READ_MUL) and AD[1:0]==2'b00) OR
        // burst is OK for reads when there is ((MEM_READ_LN or MEM_READ_MUL) and AD[1:0]==2'b00) OR
        //   (MEM_READ and Prefetchable_IMAGE and AD[1:0]==2'b00) -> pci_tar_burst_ok
        //   (MEM_READ and Prefetchable_IMAGE and AD[1:0]==2'b00) -> pci_tar_burst_ok
        case ({pci_tar_cmd, pci_tar_burst_ok})
        case ({pci_tar_cmd, pci_tar_burst_ok})
        {`BC_MEM_READ, 1'b1},
        {`BC_MEM_READ, 1'b1},
        {`BC_MEM_READ_LN, 1'b1} :
        {`BC_MEM_READ_LN, 1'b1} :
        begin   // when burst cycle
        begin   // when burst cycle
                if (/*(cache_line_wire == 8'h1) || pcir_fifo_almost_full_in*/ read_bound)
                if (read_bound)
                        last_data_to_pcir_fifo <= 1'b1 ;
                        last_data_to_pcir_fifo <= 1'b1 ;
                else
                else
                        last_data_to_pcir_fifo <= 1'b0 ;
                        last_data_to_pcir_fifo <= 1'b0 ;
        end
        end
        {`BC_MEM_READ_MUL, 1'b1} :
        {`BC_MEM_READ_MUL, 1'b1} :
        begin   // when burst cycle
        begin   // when burst cycle
                if (pcir_fifo_almost_full_in)
                if (read_bound)
                        last_data_to_pcir_fifo <= 1'b1 ;
                        last_data_to_pcir_fifo <= 1'b1 ;
                else
                else
                        last_data_to_pcir_fifo <= 1'b0 ;
                        last_data_to_pcir_fifo <= 1'b0 ;
        end
        end
        default :
        default :
        // {`BC_IO_READ, 1'b0},
        // {`BC_IO_READ, 1'b0},
        // {`BC_IO_READ, 1'b1},
        // {`BC_IO_READ, 1'b1},
        // {`BC_MEM_READ, 1'b0},
        // {`BC_MEM_READ, 1'b0},
        // {`BC_MEM_READ_LN, 1'b0},
        // {`BC_MEM_READ_LN, 1'b0},
        // {`BC_MEM_READ_MUL, 1'b0}:
        // {`BC_MEM_READ_MUL, 1'b0}:
        begin   // when single cycle
        begin   // when single cycle
                last_data_to_pcir_fifo <= 1'b1 ;
                last_data_to_pcir_fifo <= 1'b1 ;
        end
        end
        endcase
        endcase
end
end
 
 
reg             [3:0]    wb_no_response_cnt ;
reg             [3:0]    wb_no_response_cnt ;
reg             [3:0]    wb_response_value ;
reg             [3:0]    wb_response_value ;
reg                             wait_for_wb_response ;
reg                             wait_for_wb_response ;
reg                             set_retry ; // 
reg                             set_retry ; // 
 
 
// internal WB no response retry generator counter!
// internal WB no response retry generator counter!
always@(posedge reset_in or posedge wb_clock_in)
always@(posedge reset_in or posedge wb_clock_in)
begin
begin
        if (reset_in)
        if (reset_in)
                wb_no_response_cnt <= #`FF_DELAY 4'h0 ;
                wb_no_response_cnt <= #`FF_DELAY 4'h0 ;
        else
        else
                wb_no_response_cnt <= #`FF_DELAY wb_response_value ;
                wb_no_response_cnt <= #`FF_DELAY wb_response_value ;
end
end
// internal WB no response retry generator logic
// internal WB no response retry generator logic
always@(wait_for_wb_response or wb_no_response_cnt or ACK_I or ERR_I or RTY_I)
always@(wait_for_wb_response or wb_no_response_cnt or ACK_I or ERR_I or RTY_I)
begin
begin
        if (wb_no_response_cnt == 4'h8) // when there isn't response for 8 clocks, set internal retry
        if (wb_no_response_cnt == 4'h8) // when there isn't response for 8 clocks, set internal retry
        begin
        begin
                wb_response_value <= 4'h0 ;
                wb_response_value <= 4'h0 ;
                set_retry <= 1'b1 ;
                set_retry <= 1'b1 ;
        end
        end
        else
        else
        begin
        begin
                if (ACK_I || ERR_I || RTY_I) // if device responded, then ZERO must be written into counter
                if (ACK_I || ERR_I || RTY_I) // if device responded, then ZERO must be written into counter
                        wb_response_value <= 4'h0 ;
                        wb_response_value <= 4'h0 ;
                else
                else
                if (wait_for_wb_response)
                if (wait_for_wb_response)
                        wb_response_value <= wb_no_response_cnt + 1'h1 ; // count clocks when no response
                        wb_response_value <= wb_no_response_cnt + 1'h1 ; // count clocks when no response
                else
                else
                        wb_response_value <= wb_no_response_cnt ;
                        wb_response_value <= wb_no_response_cnt ;
                set_retry <= 1'b0 ;
                set_retry <= 1'b0 ;
        end
        end
end
end
 
 
wire    retry = RTY_I || set_retry ; // retry signal - logic OR function between RTY_I and internal WB no response retry!
wire    retry = RTY_I || set_retry ; // retry signal - logic OR function between RTY_I and internal WB no response retry!
reg             [7:0]    rty_counter ; // output from retry counter
reg             [7:0]    rty_counter ; // output from retry counter
reg             [7:0]    rty_counter_in ; // input value - output value + 1 OR output value
reg             [7:0]    rty_counter_in ; // input value - output value + 1 OR output value
reg                             rty_counter_max_value ; // signal tells when retry counter riches maximum value!
reg                             rty_counter_max_value ; // signal tells when retry counter riches maximum value!
reg                             reset_rty_cnt ; // signal for asynchronous reset of retry counter after each complete transfere
reg                             reset_rty_cnt ; // signal for asynchronous reset of retry counter after each complete transfere
reg                             last_data_transferred ; // signal is set by STATE MACHINE after each complete transfere !
 
 
 
// sinchronous signal after each transfere and asynchronous signal 'reset_rty_cnt' after reset  
// sinchronous signal after each transfere and asynchronous signal 'reset_rty_cnt' after reset  
//   for reseting the retry counter
//   for reseting the retry counter
always@(posedge reset_in or posedge wb_clock_in)
always@(posedge reset_in or posedge wb_clock_in)
begin
begin
        if (reset_in)
        if (reset_in)
                reset_rty_cnt <= 1'b1 ; // asynchronous set when reset signal is active
                reset_rty_cnt <= 1'b1 ; // asynchronous set when reset signal is active
        else
        else
                reset_rty_cnt <= ACK_I || ERR_I ; // synchronous set after completed transfere
                reset_rty_cnt <= ACK_I || ERR_I || last_data_transferred ; // synchronous set after completed transfere
end
end
 
 
// Retry counter register control
// Retry counter register control
always@(posedge reset_in or posedge wb_clock_in)
always@(posedge reset_in or posedge wb_clock_in)
begin
begin
        if (reset_in)
        if (reset_in)
                rty_counter <= #`FF_DELAY 8'h00 ;
                rty_counter <= #`FF_DELAY 8'h00 ;
        else
        else
        begin
        begin
                if (reset_rty_cnt)
                if (reset_rty_cnt)
                        rty_counter <= #`FF_DELAY 8'h00 ;
                        rty_counter <= #`FF_DELAY 8'h00 ;
                else if (retry)
                else if (retry)
                        rty_counter <= #`FF_DELAY rty_counter_in ;
                        rty_counter <= #`FF_DELAY rty_counter_in ;
        end
        end
end
end
// Retry counter logic
// Retry counter logic
always@(rty_counter)
always@(rty_counter)
begin
begin
        if(rty_counter == `WB_RTY_CNT_MAX) // stop counting
        if(rty_counter == `WB_RTY_CNT_MAX) // stop counting
        begin
        begin
        rty_counter_in <= rty_counter ;
        rty_counter_in <= rty_counter ;
        rty_counter_max_value <= 1'b1 ;
        rty_counter_max_value <= 1'b1 ;
        end
        end
        else
        else
        begin
        begin
        rty_counter_in <= rty_counter + 1'b1 ; // count up
        rty_counter_in <= rty_counter + 1'b1 ; // count up
        rty_counter_max_value <= 1'b0 ;
        rty_counter_max_value <= 1'b0 ;
        end
        end
end
end
 
 
reg             [7:0]    cache_line ; // output from cache line down-counter
/*reg           [7:0]   cache_line ; // output from cache line down-counter
reg             [7:0]    cache_line_in ; // input to cache line counter
reg             [7:0]   cache_line_in ; // input to cache line counter
reg                             cache_line_into_cnt ; // control signal for loading cache line size to counter
reg                             cache_line_into_cnt ; // control signal for loading cache line size to counter
reg                             cache_line_count ; // control signal for count enable
reg                             cache_line_count ; // control signal for count enable
reg                             cache_line_reg_used ; // if pci_cache_line_size is ZERO then all PCIR_FIFO is read
reg                             cache_line_reg_used ; // if pci_cache_line_size is ZERO then all PCIR_FIFO is read
 
 
assign  cache_line_wire = cache_line ;
assign  cache_line_wire = cache_line ;
// cache line size down-counter register control
// cache line size down-counter register control
always@(posedge wb_clock_in or posedge reset_in)
always@(posedge wb_clock_in or posedge reset_in)
begin
begin
        if (reset_in) // reset counter
        if (reset_in) // reset counter
                cache_line <= #`FF_DELAY 8'h00 ;
                cache_line <= #`FF_DELAY 8'h00 ;
        else
        else
                cache_line <= #`FF_DELAY cache_line_in ; // count down or hold value depending on cache line counter logic
                cache_line <= #`FF_DELAY cache_line_in ; // count down or hold value depending on cache line counter logic
end
end
// cache line size down-counter logic
// cache line size down-counter logic
always@(cache_line_into_cnt or cache_line_count or pci_cache_line_size or cache_lsize_not_zero or cache_line)
always@(cache_line_into_cnt or cache_line_count or pci_cache_line_size or cache_lsize_not_zero or cache_line)
begin
begin
        if (cache_line_into_cnt) // load cache line size into counter
        if (cache_line_into_cnt) // load cache line size into counter
        begin
        begin
                if (cache_lsize_not_zero)
                if (cache_lsize_not_zero)
                        cache_line_in = pci_cache_line_size ;
                        cache_line_in = pci_cache_line_size ;
                else
                else
                        cache_line_in = 8'h01 ;
                        cache_line_in = 8'h01 ;
        end
        end
        else
        else
        if (cache_line_count)
        if (cache_line_count)
        begin
        begin
                cache_line_in = cache_line - 1'h1 ; // count down
                cache_line_in = cache_line - 1'h1 ; // count down
        end
        end
        else
        else
        begin
        begin
                cache_line_in = cache_line ;
                cache_line_in = cache_line ;
        end
        end
end
end
 
*/
 
 
 
 
reg             [31:0]   addr_cnt_out ;  // output value from address counter to WB ADDRESS output
reg             [31:0]   addr_cnt_out ;  // output value from address counter to WB ADDRESS output
reg             [31:0]   addr_cnt_in ;   // input address value to address counter
reg             [31:0]   addr_cnt_in ;   // input address value to address counter
reg                             addr_into_cnt ; // control signal for loading starting address into counter
reg                             addr_into_cnt ; // control signal for loading starting address into counter
reg                             addr_count ; // control signal for count enable
reg                             addr_count ; // control signal for count enable
reg             [3:0]    bc_register ; // used when error occures during writes!
reg             [3:0]    bc_register ; // used when error occures during writes!
 
 
// wb address counter register control
// wb address counter register control
always@(posedge wb_clock_in or posedge reset_in)
always@(posedge wb_clock_in or posedge reset_in)
begin
begin
        if (reset_in) // reset counter
        if (reset_in) // reset counter
        begin
        begin
                addr_cnt_out <= #`FF_DELAY 32'h0000_0000 ;
                addr_cnt_out <= #`FF_DELAY 32'h0000_0000 ;
                bc_register  <= #`FF_DELAY 4'h0 ;
                bc_register  <= #`FF_DELAY 4'h0 ;
        end
        end
        else
        else
        begin
        begin
                addr_cnt_out <= #`FF_DELAY addr_cnt_in ; // count up or hold value depending on cache line counter logic
                addr_cnt_out <= #`FF_DELAY addr_cnt_in ; // count up or hold value depending on cache line counter logic
                if (addr_into_cnt)
                if (addr_into_cnt)
                        bc_register  <= #`FF_DELAY pciw_fifo_cbe_in ;
                        bc_register  <= #`FF_DELAY pciw_fifo_cbe_in ;
        end
        end
end
end
 
 
// when '1', the bus command is IO command - not supported commands are checked in pci_decoder modules
// when '1', the bus command is IO command - not supported commands are checked in pci_decoder modules
wire    io_memory_bus_command = !pci_tar_cmd[3] && !pci_tar_cmd[2] ;
wire    io_memory_bus_command = !pci_tar_cmd[3] && !pci_tar_cmd[2] ;
 
 
// wb address counter logic
// wb address counter logic
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
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
                io_memory_bus_command)
                io_memory_bus_command)
begin
begin
        if (addr_into_cnt) // load starting address into counter
        if (addr_into_cnt) // load starting address into counter
        begin
        begin
                if (r_attempt)
                if (r_attempt)
                begin // if read request, then load read addresss from PCI Target
                begin // if read request, then load read addresss from PCI Target
                        addr_cnt_in = {pci_tar_address[31:2], pci_tar_address[1] && io_memory_bus_command,
                        addr_cnt_in = {pci_tar_address[31:2], pci_tar_address[1] && io_memory_bus_command,
                                                                                                  pci_tar_address[0] && io_memory_bus_command} ;
                                                                                                  pci_tar_address[0] && io_memory_bus_command} ;
                end
                end
                else
                else
                begin // if not read request, then load write address from PCIW_FIFO
                begin // if not read request, then load write address from PCIW_FIFO
                        addr_cnt_in = pciw_fifo_addr_data_in[31:0] ;
                        addr_cnt_in = pciw_fifo_addr_data_in[31:0] ;
                end
                end
        end
        end
        else
        else
        if (addr_count)
        if (addr_count)
        begin
        begin
                addr_cnt_in = addr_cnt_out + 3'h4 ; // count up for 32-bit alligned address 
                addr_cnt_in = addr_cnt_out + 3'h4 ; // count up for 32-bit alligned address 
        end
        end
        else
        else
        begin
        begin
                addr_cnt_in = addr_cnt_out ;
                addr_cnt_in = addr_cnt_out ;
        end
        end
end
end
 
 
reg wb_stb_o ; // Internal signal for driwing STB_O on WB bus
reg wb_stb_o ; // Internal signal for driwing STB_O on WB bus
reg wb_we_o ; // Internal signal for driwing WE_O on WB bus
reg wb_we_o ; // Internal signal for driwing WE_O on WB bus
reg wb_cyc_o ; // Internal signal for driwing CYC_O on WB bus and for enableing burst signal generation
reg wb_cyc_o ; // Internal signal for driwing CYC_O on WB bus and for enableing burst signal generation
 
 
reg     retried ; // Signal is output value from FF and is set for one clock period after retried_d is set
reg     retried ; // Signal is output value from FF and is set for one clock period after retried_d is set
reg     retried_d ; // Signal is set whenever cycle is retried and is input to FF for delaying -> used in S_IDLE state
reg     retried_d ; // Signal is set whenever cycle is retried and is input to FF for delaying -> used in S_IDLE state
 
reg retried_write;
 
reg rty_i_delayed; // Dignal used for determinig the source of retry!
 
 
reg             first_data_is_burst ; // Signal is set in S_WRITE or S_READ states, when data transfere is burst!
reg             first_data_is_burst ; // Signal is set in S_WRITE or S_READ states, when data transfere is burst!
reg             first_data_is_burst_reg ;
reg             first_data_is_burst_reg ;
wire    burst_transfer ; // This signal is set when data transfere is burst and is reset with RESET or last data transfered
wire    burst_transfer ; // This signal is set when data transfere is burst and is reset with RESET or last data transfered
 
 
// FFs output signals tell, when there is first data out from FIFO (for BURST checking)
// FFs output signals tell, when there is first data out from FIFO (for BURST checking)
//   and for delaying retried signal
//   and for delaying retried signal
always@(posedge wb_clock_in or posedge reset_in)
always@(posedge wb_clock_in or posedge reset_in)
begin
begin
        if (reset_in) // reset signals
        if (reset_in) // reset signals
        begin
        begin
                retried <= #`FF_DELAY 1'b0 ;
                retried <= #`FF_DELAY 1'b0 ;
 
                retried_write <= #`FF_DELAY 1'b0 ;
 
                rty_i_delayed <= #`FF_DELAY 1'B0 ;
        end
        end
        else
        else
        begin
        begin
                retried <= #`FF_DELAY retried_d ; // delaying retried signal  
                retried <= #`FF_DELAY retried_d ; // delaying retried signal  
 
                retried_write <= #`FF_DELAY retried ;
 
                rty_i_delayed <= #`FF_DELAY RTY_I ;
        end
        end
end
end
 
 
// Determinig if first data is a part of BURST or just a single transfere!
// Determinig if first data is a part of BURST or just a single transfere!
always@(addr_into_cnt or r_attempt or pci_tar_burst_ok or max_read_count or
always@(addr_into_cnt or r_attempt or pci_tar_burst_ok or max_read_count or
                pciw_fifo_control_in or pciw_fifo_empty_in)
                pciw_fifo_control_in or pciw_fifo_empty_in)
begin
begin
        if (addr_into_cnt)
        if (addr_into_cnt)
        begin
        begin
                if (r_attempt)
                if (r_attempt)
                begin
                begin
                                // burst is OK for reads when there is ((MEM_READ_LN or MEM_READ_MUL) and AD[1:0]==2'b00) OR
                                // burst is OK for reads when there is ((MEM_READ_LN or MEM_READ_MUL) and AD[1:0]==2'b00) OR
                                //   (MEM_READ and Prefetchable_IMAGE and AD[1:0]==2'b00) -> pci_tar_burst_ok
                                //   (MEM_READ and Prefetchable_IMAGE and AD[1:0]==2'b00) -> pci_tar_burst_ok
                        if  (pci_tar_burst_ok && (max_read_count != 8'h1))
                        if  (pci_tar_burst_ok && (max_read_count != 8'h1))
                                first_data_is_burst <= 1'b1 ;
                                first_data_is_burst <= 1'b1 ;
                        else
                        else
                                first_data_is_burst <= 1'b0 ;
                                first_data_is_burst <= 1'b0 ;
                end
                end
                else
                else
                begin
                begin
                        first_data_is_burst <= 1'b0 ;
                        first_data_is_burst <= 1'b0 ;
                end
                end
        end
        end
        else
        else
                first_data_is_burst <= pciw_fifo_control_in[`BURST_BIT] && ~pciw_fifo_empty_in ;
                first_data_is_burst <= pciw_fifo_control_in[`BURST_BIT] && ~pciw_fifo_empty_in ;
end
end
 
 
// FF for seting and reseting burst_transfer signal
// FF for seting and reseting burst_transfer signal
always@(posedge wb_clock_in or posedge reset_in)
always@(posedge wb_clock_in or posedge reset_in)
begin
begin
        if (reset_in)
        if (reset_in)
                first_data_is_burst_reg <= #`FF_DELAY 1'b0 ;
                first_data_is_burst_reg <= #`FF_DELAY 1'b0 ;
        else
        else
        begin
        begin
                if (last_data_transferred || first_data_is_burst)
                if (last_data_transferred || first_data_is_burst)
                        first_data_is_burst_reg <= #`FF_DELAY ~last_data_transferred ;
                        first_data_is_burst_reg <= #`FF_DELAY ~last_data_transferred ;
        end
        end
end
end
`ifdef REGISTER_WBM_OUTPUTS
`ifdef REGISTER_WBM_OUTPUTS
        assign  burst_transfer = first_data_is_burst || first_data_is_burst_reg ;
        assign  burst_transfer = first_data_is_burst || first_data_is_burst_reg ;
`else
`else
        assign  burst_transfer = (first_data_is_burst && ~last_data_transferred) || first_data_is_burst_reg ;
        assign  burst_transfer = (first_data_is_burst && ~last_data_transferred) || first_data_is_burst_reg ;
`endif
`endif
 
 
reg [(`WB_FSM_BITS - 1):0]  c_state ; //current state register
reg [(`WB_FSM_BITS - 1):0]  c_state ; //current state register
reg [(`WB_FSM_BITS - 1):0]  n_state ; //next state input to current state register
reg [(`WB_FSM_BITS - 1):0]  n_state ; //next state input to current state register
 
 
// state machine register control
// state machine register control
always@(posedge wb_clock_in or posedge reset_in)
always@(posedge wb_clock_in or posedge reset_in)
begin
begin
    if (reset_in) // reset state machine ti S_IDLE state
    if (reset_in) // reset state machine ti S_IDLE state
        c_state <= #`FF_DELAY S_IDLE ;
        c_state <= #`FF_DELAY S_IDLE ;
    else
    else
        c_state <= #`FF_DELAY n_state ;
        c_state <= #`FF_DELAY n_state ;
end
end
 
 
// state machine logic
// state machine logic
always@(c_state or
always@(c_state or
                ACK_I or
                ACK_I or
                RTY_I or
                RTY_I or
                ERR_I or
                ERR_I or
                w_attempt or
                w_attempt or
                r_attempt or
                r_attempt or
                retried or
                retried or
 
                rty_i_delayed or
                pci_tar_read_request or
                pci_tar_read_request or
                rty_counter_max_value or
                rty_counter_max_value or
                last_data_to_pcir_fifo or
                last_data_to_pcir_fifo or
                first_wb_data_access or
                first_wb_data_access or
                last_data_from_pciw_fifo_reg
                last_data_from_pciw_fifo_reg
                )
                )
begin
begin
    case (c_state)
    case (c_state)
    S_IDLE:
    S_IDLE:
        begin
        begin
                // Default values for signals not used in this state
                // Default values for signals not used in this state
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_control <= 4'h0 ;
                pcir_fifo_control <= 4'h0 ;
                addr_count <= 1'b0 ;
                addr_count <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                pci_error_sig_out <= 1'b0 ;
                pci_error_sig_out <= 1'b0 ;
                error_source_out <= 1'b0 ;
                error_source_out <= 1'b0 ;
                retried_d <= 1'b0 ;
                retried_d <= 1'b0 ;
                last_data_transferred <= 1'b0 ;
                last_data_transferred <= 1'b0 ;
                wb_read_done <= 1'b0 ;
                wb_read_done <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
 
                        read_rty_cnt_exp_out <= 1'b0 ;
 
                        wait_for_wb_response <= 1'b0 ;
                        wait_for_wb_response <= 1'b0 ;
                case ({w_attempt, r_attempt, retried})
                case ({w_attempt, r_attempt, retried})
                3'b101 : // Write request for PCIW_FIFO to WB bus transaction
                3'b101 : // Write request for PCIW_FIFO to WB bus transaction
                begin    // If there was retry, the same transaction must be initiated
                begin    // If there was retry, the same transaction must be initiated
                        pciw_fifo_renable <= 1'b0 ; // the same data
                        pciw_fifo_renable <= 1'b0 ; // the same data
                        addr_into_cnt <= 1'b0 ; // the same address
                        addr_into_cnt <= 1'b0 ; // the same address
                        read_count_load <= 1'b0 ; // no need for cache line when there is write
                        read_count_load <= 1'b0 ; // no need for cache line when there is write
 
                        if (rty_counter_max_value) // If retry counter reached maximum value
 
                        begin
 
                                n_state <= S_WRITE_ERR_RTY ;
 
                                write_rty_cnt_exp_out <= 1'b1 ; // signal for reporting write counter expired
 
                                error_source_out <= rty_i_delayed;
 
                                pci_error_sig_out <= 1'b1 ;
 
                        end
 
                        else
 
                        begin
                        n_state <= S_WRITE ;
                        n_state <= S_WRITE ;
 
                                        write_rty_cnt_exp_out <= 1'b0 ;
 
                                error_source_out <= 1'b0 ;
 
                                pci_error_sig_out <= 1'b0 ;
 
                        end
 
                                read_rty_cnt_exp_out <= 1'b0 ;
                end
                end
                3'b100 : // Write request for PCIW_FIFO to WB bus transaction
                3'b100 : // Write request for PCIW_FIFO to WB bus transaction
                        begin    // If there is new transaction
                        begin    // If there is new transaction
                        pciw_fifo_renable <= 1'b1 ; // first location is address (in FIFO), next will be data
                        pciw_fifo_renable <= 1'b1 ; // first location is address (in FIFO), next will be data
                        addr_into_cnt <= 1'b1 ; // address must be latched into address counter
                        addr_into_cnt <= 1'b1 ; // address must be latched into address counter
                        read_count_load <= 1'b0 ; // no need for cache line when there is write
                        read_count_load <= 1'b0 ; // no need for cache line when there is write
                        n_state <= S_WRITE ;
                        n_state <= S_WRITE ;
 
                                write_rty_cnt_exp_out <= 1'b0 ;
 
                                read_rty_cnt_exp_out <= 1'b0 ;
 
                        error_source_out <= 1'b0 ;
 
                        pci_error_sig_out <= 1'b0 ;
                end
                end
                3'b011 : // Read request from PCI Target for WB bus to PCIR_FIFO transaction
                3'b011 : // Read request from PCI Target for WB bus to PCIR_FIFO transaction
                        begin    // If there was retry, the same transaction must be initiated
                        begin    // If there was retry, the same transaction must be initiated
                        addr_into_cnt <= 1'b0 ; // the same address
                        addr_into_cnt <= 1'b0 ; // the same address
                        read_count_load <= 1'b0 ; // cache line counter must not be changed for retried read
                        read_count_load <= 1'b0 ; // cache line counter must not be changed for retried read
                                pciw_fifo_renable <= 1'b0 ; // don't read from FIFO, when read transaction from WB to FIFO
                                pciw_fifo_renable <= 1'b0 ; // don't read from FIFO, when read transaction from WB to FIFO
 
                        if (rty_counter_max_value) // If retry counter reached maximum value
 
                                begin
 
                                        n_state <= S_READ_RTY;
 
                                        read_rty_cnt_exp_out <= 1'b1 ; // signal for reporting read counter expired
 
                                end
 
                                else
 
                        begin
                        n_state <= S_READ ;
                        n_state <= S_READ ;
 
                                        read_rty_cnt_exp_out <= 1'b0 ;
 
                        end
 
                                write_rty_cnt_exp_out <= 1'b0 ;
 
                                error_source_out <= 1'b0 ;
 
                                pci_error_sig_out <= 1'b0 ;
                        end
                        end
                3'b010 : // Read request from PCI Target for WB bus to PCIR_FIFO transaction
                3'b010 : // Read request from PCI Target for WB bus to PCIR_FIFO transaction
                        begin    // If there is new transaction
                        begin    // If there is new transaction
                        addr_into_cnt <= 1'b1 ; // address must be latched into counter from separate request bus
                        addr_into_cnt <= 1'b1 ; // address must be latched into counter from separate request bus
                        read_count_load <= 1'b1 ; // cache line size must be latched into its counter
                        read_count_load <= 1'b1 ; // cache line size must be latched into its counter
                                pciw_fifo_renable <= 1'b0 ; // don't read from FIFO, when read transaction from WB to FIFO
                                pciw_fifo_renable <= 1'b0 ; // don't read from FIFO, when read transaction from WB to FIFO
                        n_state <= S_READ ;
                        n_state <= S_READ ;
 
                                write_rty_cnt_exp_out <= 1'b0 ;
 
                                read_rty_cnt_exp_out <= 1'b0 ;
 
                                error_source_out <= 1'b0 ;
 
                                pci_error_sig_out <= 1'b0 ;
                end
                end
                default : // stay in IDLE state
                default : // stay in IDLE state
                        begin
                        begin
                        pciw_fifo_renable <= 1'b0 ;
                        pciw_fifo_renable <= 1'b0 ;
                        addr_into_cnt <= 1'b0 ;
                        addr_into_cnt <= 1'b0 ;
                        read_count_load <= 1'b0 ;
                        read_count_load <= 1'b0 ;
                        n_state <= S_IDLE ;
                        n_state <= S_IDLE ;
 
                                write_rty_cnt_exp_out <= 1'b0 ;
 
                                read_rty_cnt_exp_out <= 1'b0 ;
 
                                error_source_out <= 1'b0 ;
 
                                pci_error_sig_out <= 1'b0 ;
                        end
                        end
                endcase
                endcase
                        wb_stb_o <= 1'b0 ;
                        wb_stb_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_cyc_o <= 1'b0 ;
                        wb_cyc_o <= 1'b0 ;
                end
                end
        S_WRITE: // WRITE from PCIW_FIFO to WB bus
        S_WRITE: // WRITE from PCIW_FIFO to WB bus
                begin
                begin
                // Default values for signals not used in this state
                // Default values for signals not used in this state
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_control <= 4'h0 ;
                pcir_fifo_control <= 4'h0 ;
                addr_into_cnt <= 1'b0 ;
                addr_into_cnt <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                wb_read_done <= 1'b0 ;
                wb_read_done <= 1'b0 ;
                        read_rty_cnt_exp_out <= 1'b0 ;
                        read_rty_cnt_exp_out <= 1'b0 ;
                        case ({ACK_I, ERR_I, RTY_I})
                        case ({ACK_I, ERR_I, RTY_I})
                        3'b100 : // If writting of one data is acknowledged
                        3'b100 : // If writting of one data is acknowledged
                begin
                begin
                                pciw_fifo_renable <= 1'b1 ; // prepare next value (address when new trans., data when burst tran.)
                                pciw_fifo_renable <= 1'b1 ; // prepare next value (address when new trans., data when burst tran.)
                        addr_count <= 1'b1 ; // prepare next address if there will be burst
                        addr_count <= 1'b1 ; // prepare next address if there will be burst
                                pci_error_sig_out <= 1'b0 ; // there was no error
                                pci_error_sig_out <= 1'b0 ; // there was no error
                                error_source_out <= 1'b0 ;
                                error_source_out <= 1'b0 ;
                                retried_d <= 1'b0 ; // there was no retry
                                retried_d <= 1'b0 ; // there was no retry
                                write_rty_cnt_exp_out <= 1'b0 ; // there was no retry
                                write_rty_cnt_exp_out <= 1'b0 ; // there was no retry
                                wait_for_wb_response <= 1'b0 ;
                                wait_for_wb_response <= 1'b0 ;
                        if (last_data_from_pciw_fifo_reg) // if last data was transfered
                        if (last_data_from_pciw_fifo_reg) // if last data was transfered
                                begin
                                begin
                                n_state <= S_IDLE ;
                                n_state <= S_IDLE ;
                                last_data_transferred <= 1'b1 ; // signal for last data transfered
                                last_data_transferred <= 1'b1 ; // signal for last data transfered
                                end
                                end
                        else
                        else
                                begin
                                begin
                                n_state <= S_WRITE ;
                                n_state <= S_WRITE ;
                                last_data_transferred <= 1'b0 ;
                                last_data_transferred <= 1'b0 ;
                                end
                                end
                end
                end
                        3'b010 : // If writting of one data is terminated with ERROR
                        3'b010 : // If writting of one data is terminated with ERROR
                begin
                begin
                        pciw_fifo_renable <= 1'b1 ; // prepare next value (address when new trans., data when cleaning FIFO)
                        pciw_fifo_renable <= 1'b1 ; // prepare next value (address when new trans., data when cleaning FIFO)
                        addr_count <= 1'b0 ; // no need for new address
                        addr_count <= 1'b0 ; // no need for new address
                        retried_d <= 1'b0 ; // there was no retry
                        retried_d <= 1'b0 ; // there was no retry
                        last_data_transferred <= 1'b1 ; // signal for last data transfered
                        last_data_transferred <= 1'b1 ; // signal for last data transfered
                        pci_error_sig_out <= 1'b1 ; // segnal for error reporting
                        pci_error_sig_out <= 1'b1 ; // segnal for error reporting
                        error_source_out <= 1'b0 ; // error source from other side of WB bus
                        error_source_out <= 1'b0 ; // error source from other side of WB bus
                                write_rty_cnt_exp_out <= 1'b0 ; // there was no retry
                                write_rty_cnt_exp_out <= 1'b0 ; // there was no retry
                                wait_for_wb_response <= 1'b0 ;
                                wait_for_wb_response <= 1'b0 ;
                                if (last_data_from_pciw_fifo_reg) // if last data was transfered
                                if (last_data_from_pciw_fifo_reg) // if last data was transfered
                                        n_state <= S_IDLE ; // go to S_IDLE for new transfere
                                        n_state <= S_IDLE ; // go to S_IDLE for new transfere
                                else // if there wasn't last data of transfere
                                else // if there wasn't last data of transfere
                                        n_state <= S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO
                                        n_state <= S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO
                end
                end
                        3'b001 : // If writting of one data is retried
                        3'b001 : // If writting of one data is retried
                        begin
                        begin
                                pciw_fifo_renable <= 1'b0 ;
                                pciw_fifo_renable <= 1'b0 ;
                                addr_count <= 1'b0 ;
                                addr_count <= 1'b0 ;
                                last_data_transferred <= 1'b0 ;
                                last_data_transferred <= 1'b0 ;
                                retried_d <= 1'b1 ; // there was a retry
                                retried_d <= 1'b1 ; // there was a retry
                                wait_for_wb_response <= 1'b0 ;
                                wait_for_wb_response <= 1'b0 ;
                                if(rty_counter_max_value) // If retry counter reached maximum allowed value
                                if(rty_counter_max_value) // If retry counter reached maximum allowed value
                                begin
                                begin
                                        n_state <= S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO
                                        n_state <= S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO
                                        write_rty_cnt_exp_out <= 1'b1 ; // signal for reporting write counter expired
                                        write_rty_cnt_exp_out <= 1'b1 ; // signal for reporting write counter expired
                                        pci_error_sig_out <= 1'b1 ;
                                        pci_error_sig_out <= 1'b1 ;
                                        error_source_out <= 1'b1 ; // error ocuerd because of retry counter
                                        error_source_out <= 1'b1 ; // error ocuerd because of retry counter
                                end
                                end
                                else
                                else
                                begin
                                begin
                                        n_state <= S_IDLE ; // go to S_IDLE state for retrying the transaction
                                        n_state <= S_IDLE ; // go to S_IDLE state for retrying the transaction
                                        write_rty_cnt_exp_out <= 1'b0 ; // retry counter hasn't expired yet
                                        write_rty_cnt_exp_out <= 1'b0 ; // retry counter hasn't expired yet
                                        pci_error_sig_out <= 1'b0 ;
                                        pci_error_sig_out <= 1'b0 ;
                                        error_source_out <= 1'b0 ;
                                        error_source_out <= 1'b0 ;
                                end
                                end
                        end
                        end
                        default :
                        default :
                        begin
                        begin
                                pciw_fifo_renable <= 1'b0 ;
                                pciw_fifo_renable <= 1'b0 ;
                                addr_count <= 1'b0 ;
                                addr_count <= 1'b0 ;
                                last_data_transferred <= 1'b0 ;
                                last_data_transferred <= 1'b0 ;
                                retried_d <= 1'b0 ;
                                retried_d <= 1'b0 ;
                                wait_for_wb_response <= 1'b1 ; // wait for WB device to response (after 8 clocks RTY CNT is incremented)
                                wait_for_wb_response <= 1'b1 ; // wait for WB device to response (after 8 clocks RTY CNT is incremented)
                                error_source_out <= 1'b0 ; // if error ocures, error source is from other WB bus side
                                error_source_out <= 1'b0 ; // if error ocures, error source is from other WB bus side
                                if(rty_counter_max_value) // when no WB response and RTY CNT reached maximum allowed value 
                                if(rty_counter_max_value) // when no WB response and RTY CNT reached maximum allowed value 
                                begin
                                begin
                                        n_state <= S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO
                                        n_state <= S_WRITE_ERR_RTY ; // go here to clean this write transaction from PCIW_FIFO
                                        write_rty_cnt_exp_out <= 1'b1 ; // signal for reporting write counter expired
                                        write_rty_cnt_exp_out <= 1'b1 ; // signal for reporting write counter expired
                                pci_error_sig_out <= 1'b1 ; // signal for error reporting
                                pci_error_sig_out <= 1'b1 ; // signal for error reporting
                                end
                                end
                                else
                                else
                                begin
                                begin
                                        n_state <= S_WRITE ; // stay in S_WRITE state to wait WB to response
                                        n_state <= S_WRITE ; // stay in S_WRITE state to wait WB to response
                                        write_rty_cnt_exp_out <= 1'b0 ; // retry counter hasn't expired yet
                                        write_rty_cnt_exp_out <= 1'b0 ; // retry counter hasn't expired yet
                                        pci_error_sig_out <= 1'b0 ;
                                        pci_error_sig_out <= 1'b0 ;
                                end
                                end
                        end
                        end
                        endcase
                        endcase
                        wb_stb_o <= 1'b1 ;
                        wb_stb_o <= 1'b1 ;
                        wb_we_o <= 1'b1 ;
                        wb_we_o <= 1'b1 ;
                        wb_cyc_o <= 1'b1 ;
                        wb_cyc_o <= 1'b1 ;
                end
                end
        S_WRITE_ERR_RTY: // Clean current write transaction from PCIW_FIFO if ERROR or Retry counter expired occures
        S_WRITE_ERR_RTY: // Clean current write transaction from PCIW_FIFO if ERROR or Retry counter expired occures
                begin
                begin
                        pciw_fifo_renable <= 1'b1 ; // put out next data (untill last data or FIFO empty)
                        pciw_fifo_renable <= 1'b1 ; // put out next data (untill last data or FIFO empty)
                        last_data_transferred <= 1'b1 ; // after exiting this state, negedge of this signal is used
                        last_data_transferred <= 1'b1 ; // after exiting this state, negedge of this signal is used
                        // Default values for signals not used in this state
                        // Default values for signals not used in this state
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_control <= 4'h0 ;
                pcir_fifo_control <= 4'h0 ;
                addr_into_cnt <= 1'b0 ;
                addr_into_cnt <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                addr_count <= 1'b0 ;
                addr_count <= 1'b0 ;
                        pci_error_sig_out <= 1'b0 ;
                        pci_error_sig_out <= 1'b0 ;
                        error_source_out <= 1'b0 ;
                        error_source_out <= 1'b0 ;
                        retried_d <= 1'b0 ;
                        retried_d <= 1'b0 ;
                        wb_read_done <= 1'b0 ;
                        wb_read_done <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
                        read_rty_cnt_exp_out <= 1'b0 ;
                        read_rty_cnt_exp_out <= 1'b0 ;
                        wait_for_wb_response <= 1'b0 ;
                        wait_for_wb_response <= 1'b0 ;
                        // If last data is cleaned out from PCIW_FIFO
                        // If last data is cleaned out from PCIW_FIFO
                        if (last_data_from_pciw_fifo_reg)
                        if (last_data_from_pciw_fifo_reg)
                                n_state <= S_IDLE ;
                                n_state <= S_IDLE ;
                        else
                        else
                                n_state <= S_WRITE_ERR_RTY ; // Clean until last data is cleaned out from FIFO
                                n_state <= S_WRITE_ERR_RTY ; // Clean until last data is cleaned out from FIFO
                        wb_stb_o <= 1'b0 ;
                        wb_stb_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_cyc_o <= 1'b0 ;
                        wb_cyc_o <= 1'b0 ;
                end
                end
        S_READ: // READ from WB bus to PCIR_FIFO
        S_READ: // READ from WB bus to PCIR_FIFO
                begin
                begin
                        // Default values for signals not used in this state
                        // Default values for signals not used in this state
                pciw_fifo_renable <= 1'b0 ;
                pciw_fifo_renable <= 1'b0 ;
                addr_into_cnt <= 1'b0 ;
                addr_into_cnt <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_load <= 1'b0 ;
                pci_error_sig_out <= 1'b0 ;
                pci_error_sig_out <= 1'b0 ;
                error_source_out <= 1'b0 ;
                error_source_out <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
                        case ({ACK_I, ERR_I, RTY_I})
                        case ({ACK_I, ERR_I, RTY_I})
                        3'b100 : // If reading of one data is acknowledged
                        3'b100 : // If reading of one data is acknowledged
                begin
                begin
                        pcir_fifo_wenable <= 1'b1 ; // enable writting data into PCIR_FIFO
                        pcir_fifo_wenable <= 1'b1 ; // enable writting data into PCIR_FIFO
                        addr_count <= 1'b1 ; // prepare next address if there will be burst
                        addr_count <= 1'b1 ; // prepare next address if there will be burst
                                read_count_enable <= 1'b1 ; // decrease counter value for cache line size
                                read_count_enable <= 1'b1 ; // decrease counter value for cache line size
                        retried_d <= 1'b0 ; // there was no retry
                        retried_d <= 1'b0 ; // there was no retry
                                read_rty_cnt_exp_out <= 1'b0 ; // there was no retry
                                read_rty_cnt_exp_out <= 1'b0 ; // there was no retry
                                wait_for_wb_response <= 1'b0 ;
                                wait_for_wb_response <= 1'b0 ;
                                // if last data was transfered
                                // if last data was transfered
                        if (last_data_to_pcir_fifo)
                        if (last_data_to_pcir_fifo)
                        begin
                        begin
                                pcir_fifo_control[`LAST_CTRL_BIT]               <= 1'b1 ; // FIFO must indicate LAST data transfered
                                pcir_fifo_control[`LAST_CTRL_BIT]               <= 1'b1 ; // FIFO must indicate LAST data transfered
                                pcir_fifo_control[`DATA_ERROR_CTRL_BIT] <= 1'b0 ;
                                pcir_fifo_control[`DATA_ERROR_CTRL_BIT] <= 1'b0 ;
                                pcir_fifo_control[`UNUSED_CTRL_BIT]             <= 1'b0 ;
                                pcir_fifo_control[`UNUSED_CTRL_BIT]             <= 1'b0 ;
                                pcir_fifo_control[`ADDR_CTRL_BIT]               <= 1'b0 ;
                                pcir_fifo_control[`ADDR_CTRL_BIT]               <= 1'b0 ;
                                last_data_transferred <= 1'b1 ; // signal for last data transfered
                                last_data_transferred <= 1'b1 ; // signal for last data transfered
                                wb_read_done <= 1'b1 ; // signal last data of read transaction for PCI Target
                                wb_read_done <= 1'b1 ; // signal last data of read transaction for PCI Target
                                n_state <= S_TURN_ARROUND ;
                                n_state <= S_TURN_ARROUND ;
                        end
                        end
                        else // if not last data transfered
                        else // if not last data transfered
                        begin
                        begin
                                        pcir_fifo_control <= 4'h0 ; // ZERO for control code
                                        pcir_fifo_control <= 4'h0 ; // ZERO for control code
                                        last_data_transferred <= 1'b0 ; // not last data transfered
                                        last_data_transferred <= 1'b0 ; // not last data transfered
                                        wb_read_done <= 1'b0 ; // read is not done yet
                                        wb_read_done <= 1'b0 ; // read is not done yet
                                        n_state <= S_READ ;
                                        n_state <= S_READ ;
                                end
                                end
                end
                end
                3'b010 : // If reading of one data is terminated with ERROR
                3'b010 : // If reading of one data is terminated with ERROR
                begin
                begin
                        pcir_fifo_wenable <= 1'b1 ; // enable for writting to FIFO data with ERROR
                        pcir_fifo_wenable <= 1'b1 ; // enable for writting to FIFO data with ERROR
                        addr_count <= 1'b0 ; // no need for new address
                        addr_count <= 1'b0 ; // no need for new address
                                pcir_fifo_control[`LAST_CTRL_BIT]               <= 1'b0 ;
                                pcir_fifo_control[`LAST_CTRL_BIT]               <= 1'b0 ;
                        pcir_fifo_control[`DATA_ERROR_CTRL_BIT] <= 1'b1 ; // FIFO must indicate the DATA with ERROR
                        pcir_fifo_control[`DATA_ERROR_CTRL_BIT] <= 1'b1 ; // FIFO must indicate the DATA with ERROR
                        pcir_fifo_control[`UNUSED_CTRL_BIT]             <= 1'b0 ;
                        pcir_fifo_control[`UNUSED_CTRL_BIT]             <= 1'b0 ;
                        pcir_fifo_control[`ADDR_CTRL_BIT]               <= 1'b0 ;
                        pcir_fifo_control[`ADDR_CTRL_BIT]               <= 1'b0 ;
                                last_data_transferred <= 1'b1 ; // signal for last data transfered
                                last_data_transferred <= 1'b1 ; // signal for last data transfered
                                wb_read_done <= 1'b1 ; // signal last data of read transaction for PCI Target
                                wb_read_done <= 1'b1 ; // signal last data of read transaction for PCI Target
                                read_count_enable <= 1'b0 ; // no need for cache line, when error occures
                                read_count_enable <= 1'b0 ; // no need for cache line, when error occures
                                n_state <= S_TURN_ARROUND ;
                                n_state <= S_TURN_ARROUND ;
                                retried_d <= 1'b0 ; // there was no retry
                                retried_d <= 1'b0 ; // there was no retry
                                wait_for_wb_response <= 1'b0 ;
                                wait_for_wb_response <= 1'b0 ;
                                read_rty_cnt_exp_out <= 1'b0 ; // there was no retry
                                read_rty_cnt_exp_out <= 1'b0 ; // there was no retry
                end
                end
                        3'b001 : // If reading of one data is retried
                        3'b001 : // If reading of one data is retried
                begin
                begin
                                pcir_fifo_wenable <= 1'b0 ;
                                pcir_fifo_wenable <= 1'b0 ;
                                pcir_fifo_control <= 4'h0 ;
                                pcir_fifo_control <= 4'h0 ;
                                addr_count <= 1'b0 ;
                                addr_count <= 1'b0 ;
                                read_count_enable <= 1'b0 ;
                                read_count_enable <= 1'b0 ;
                                wait_for_wb_response <= 1'b0 ;
                                wait_for_wb_response <= 1'b0 ;
                                case ({first_wb_data_access, rty_counter_max_value})
                                case ({first_wb_data_access, rty_counter_max_value})
                                2'b10 :
                                2'b10 :
                                begin
                                begin  // if first data of the cycle (CYC_O) is retried - after each retry CYC_O goes inactive 
                                        n_state <= S_IDLE ; // go to S_IDLE state for retrying the transaction
                                        n_state <= S_IDLE ; // go to S_IDLE state for retrying the transaction
                                        read_rty_cnt_exp_out <= 1'b0 ; // retry counter hasn't expired yet   
                                        read_rty_cnt_exp_out <= 1'b0 ; // retry counter hasn't expired yet   
                                        last_data_transferred <= 1'b0 ;
                                        last_data_transferred <= 1'b0 ;
                                        wb_read_done <= 1'b0 ;
                                        wb_read_done <= 1'b0 ;
                                        retried_d <= 1'b1 ; // there was a retry
                                        retried_d <= 1'b1 ; // there was a retry
                                end
                                end
                                2'b11 :
                                2'b11 :
                                begin
                                begin  // if retry counter reached maximum value
                                        n_state <= S_READ_RTY ; // go here to wait for PCI Target to remove read request
                                        n_state <= S_READ_RTY ; // go here to wait for PCI Target to remove read request
                                        read_rty_cnt_exp_out <= 1'b1 ; // signal for reporting read counter expired  
                                        read_rty_cnt_exp_out <= 1'b1 ; // signal for reporting read counter expired  
                                        last_data_transferred <= 1'b0 ;
                                        last_data_transferred <= 1'b0 ;
                                        wb_read_done <= 1'b0 ;
                                        wb_read_done <= 1'b0 ;
                                        retried_d <= 1'b1 ; // there was a retry
                                        retried_d <= 1'b1 ; // there was a retry
                                end
                                end
                                default :
                                default : // if retry occures after at least 1 data was transferred without breaking cycle (CYC_O inactive)
                                begin
                                begin     // then PCI device will retry access!
                                        n_state <= S_TURN_ARROUND ; // go to S_TURN_ARROUND state 
                                        n_state <= S_TURN_ARROUND ; // go to S_TURN_ARROUND state 
                                        read_rty_cnt_exp_out <= 1'b0 ; // retry counter hasn't expired  
                                        read_rty_cnt_exp_out <= 1'b0 ; // retry counter hasn't expired  
                                        last_data_transferred <= 1'b1 ;
                                        last_data_transferred <= 1'b1 ;
                                        wb_read_done <= 1'b1 ;
                                        wb_read_done <= 1'b1 ;
                                        retried_d <= 1'b0 ; // retry must not be retried, since there is not a first data
                                        retried_d <= 1'b0 ; // retry must not be retried, since there is not a first data
                                end
                                end
                                endcase
                                endcase
                        end
                        end
                default :
                default :
                begin
                begin
                                addr_count <= 1'b0 ;
                                addr_count <= 1'b0 ;
                                read_count_enable <= 1'b0 ;
                                read_count_enable <= 1'b0 ;
                                read_rty_cnt_exp_out <= 1'b0 ;
                                read_rty_cnt_exp_out <= 1'b0 ;
                                retried_d <= 1'b0 ;
                                retried_d <= 1'b0 ;
                                wait_for_wb_response <= 1'b1 ; // wait for WB device to response (after 8 clocks RTY CNT is incremented)
                                wait_for_wb_response <= 1'b1 ; // wait for WB device to response (after 8 clocks RTY CNT is incremented)
                                if(rty_counter_max_value) // when no WB response and RTY CNT reached maximum allowed value 
                                if(rty_counter_max_value) // when no WB response and RTY CNT reached maximum allowed value 
                                begin
                                begin
                                        n_state <= S_TURN_ARROUND ; // go here to stop read request
                                        n_state <= S_TURN_ARROUND ; // go here to stop read request
                                        pcir_fifo_wenable <= 1'b1 ;
                                        pcir_fifo_wenable <= 1'b1 ;
                                        pcir_fifo_control[`LAST_CTRL_BIT]               <= 1'b0 ;
                                        pcir_fifo_control[`LAST_CTRL_BIT]               <= 1'b0 ;
                                pcir_fifo_control[`DATA_ERROR_CTRL_BIT] <= 1'b1 ; // FIFO must indicate the DATA with ERROR
                                pcir_fifo_control[`DATA_ERROR_CTRL_BIT] <= 1'b1 ; // FIFO must indicate the DATA with ERROR
                                pcir_fifo_control[`UNUSED_CTRL_BIT]             <= 1'b0 ;
                                pcir_fifo_control[`UNUSED_CTRL_BIT]             <= 1'b0 ;
                                pcir_fifo_control[`ADDR_CTRL_BIT]               <= 1'b0 ;
                                pcir_fifo_control[`ADDR_CTRL_BIT]               <= 1'b0 ;
                                        last_data_transferred <= 1'b1 ;
                                        last_data_transferred <= 1'b1 ;
                                        wb_read_done <= 1'b1 ;
                                        wb_read_done <= 1'b1 ;
                                end
                                end
                                else
                                else
                                begin
                                begin
                                        n_state <= S_READ ; // stay in S_READ state to wait WB to response
                                        n_state <= S_READ ; // stay in S_READ state to wait WB to response
                                        pcir_fifo_wenable <= 1'b0 ;
                                        pcir_fifo_wenable <= 1'b0 ;
                                        pcir_fifo_control <= 4'h0 ;
                                        pcir_fifo_control <= 4'h0 ;
                                        last_data_transferred <= 1'b0 ;
                                        last_data_transferred <= 1'b0 ;
                                        wb_read_done <= 1'b0 ;
                                        wb_read_done <= 1'b0 ;
                                end
                                end
                        end
                        end
                        endcase
                        endcase
                        wb_stb_o <= 1'b1 ;
                        wb_stb_o <= 1'b1 ;
                        wb_we_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_cyc_o <= 1'b1 ;
                        wb_cyc_o <= 1'b1 ;
                end
                end
        S_READ_RTY: // Wait for PCI Target to remove read request, when retry counter reaches maximum value!
        S_READ_RTY: // Wait for PCI Target to remove read request, when retry counter reaches maximum value!
                begin
                begin
                        // Default values for signals not used in this state
                        // Default values for signals not used in this state
                        pciw_fifo_renable <= 1'b0 ;
                        pciw_fifo_renable <= 1'b0 ;
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_control <= 4'h0 ;
                pcir_fifo_control <= 4'h0 ;
                addr_into_cnt <= 1'b0 ;
                addr_into_cnt <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                addr_count <= 1'b0 ;
                addr_count <= 1'b0 ;
                        pci_error_sig_out <= 1'b0 ;
                        pci_error_sig_out <= 1'b0 ;
                        error_source_out <= 1'b0 ;
                        error_source_out <= 1'b0 ;
                        retried_d <= 1'b0 ;
                        retried_d <= 1'b0 ;
                        wb_read_done <= 1'b0 ;
                        wb_read_done <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
                        read_rty_cnt_exp_out <= 1'b0 ;
                        read_rty_cnt_exp_out <= 1'b0 ;
                        wait_for_wb_response <= 1'b0 ;
                        wait_for_wb_response <= 1'b0 ;
                        // wait for PCI Target to remove read request
                        // wait for PCI Target to remove read request
                        if (pci_tar_read_request)
                        if (pci_tar_read_request)
                        begin
                        begin
                                n_state <= S_READ_RTY ; // stay in this state until read request is removed
                                n_state <= S_READ_RTY ; // stay in this state until read request is removed
                                last_data_transferred <= 1'b0 ;
                                last_data_transferred <= 1'b0 ;
                        end
                        end
                        else // when read request is removed
                        else // when read request is removed
                        begin
                        begin
                                n_state <= S_IDLE ;
                                n_state <= S_IDLE ;
                                last_data_transferred <= 1'b1 ; // when read request is removed, there is "last" data
                                last_data_transferred <= 1'b1 ; // when read request is removed, there is "last" data
                        end
                        end
                        wb_stb_o <= 1'b0 ;
                        wb_stb_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_cyc_o <= 1'b0 ;
                        wb_cyc_o <= 1'b0 ;
                end
                end
        S_TURN_ARROUND: // Turn arround cycle after writting to PCIR_FIFO (for correct data when reading from PCIW_FIFO) 
        S_TURN_ARROUND: // Turn arround cycle after writting to PCIR_FIFO (for correct data when reading from PCIW_FIFO) 
                begin
                begin
                        // Default values for signals not used in this state
                        // Default values for signals not used in this state
                        pciw_fifo_renable <= 1'b0 ;
                        pciw_fifo_renable <= 1'b0 ;
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_control <= 4'h0 ;
                pcir_fifo_control <= 4'h0 ;
                addr_into_cnt <= 1'b0 ;
                addr_into_cnt <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                addr_count <= 1'b0 ;
                addr_count <= 1'b0 ;
                        pci_error_sig_out <= 1'b0 ;
                        pci_error_sig_out <= 1'b0 ;
                        error_source_out <= 1'b0 ;
                        error_source_out <= 1'b0 ;
                        retried_d <= 1'b0 ;
                        retried_d <= 1'b0 ;
                        last_data_transferred <= 1'b1 ;
                        last_data_transferred <= 1'b1 ;
                        wb_read_done <= 1'b0 ;
                        wb_read_done <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
                        read_rty_cnt_exp_out <= 1'b0 ;
                        read_rty_cnt_exp_out <= 1'b0 ;
                        wait_for_wb_response <= 1'b0 ;
                        wait_for_wb_response <= 1'b0 ;
                        n_state <= S_IDLE ;
                        n_state <= S_IDLE ;
                        wb_stb_o <= 1'b0 ;
                        wb_stb_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_cyc_o <= 1'b0 ;
                        wb_cyc_o <= 1'b0 ;
                end
                end
        default :
        default :
                begin
                begin
                        // Default values for signals not used in this state
                        // Default values for signals not used in this state
                        pciw_fifo_renable <= 1'b0 ;
                        pciw_fifo_renable <= 1'b0 ;
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_wenable <= 1'b0 ;
                pcir_fifo_control <= 4'h0 ;
                pcir_fifo_control <= 4'h0 ;
                addr_into_cnt <= 1'b0 ;
                addr_into_cnt <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_load <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                read_count_enable <= 1'b0 ;
                addr_count <= 1'b0 ;
                addr_count <= 1'b0 ;
                        pci_error_sig_out <= 1'b0 ;
                        pci_error_sig_out <= 1'b0 ;
                        error_source_out <= 1'b0 ;
                        error_source_out <= 1'b0 ;
                        retried_d <= 1'b0 ;
                        retried_d <= 1'b0 ;
                        last_data_transferred <= 1'b0 ;
                        last_data_transferred <= 1'b0 ;
                        wb_read_done <= 1'b0 ;
                        wb_read_done <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
                        write_rty_cnt_exp_out <= 1'b0 ;
                        read_rty_cnt_exp_out <= 1'b0 ;
                        read_rty_cnt_exp_out <= 1'b0 ;
                        wait_for_wb_response <= 1'b0 ;
                        wait_for_wb_response <= 1'b0 ;
                        n_state <= S_IDLE ;
                        n_state <= S_IDLE ;
                        wb_stb_o <= 1'b0 ;
                        wb_stb_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_we_o <= 1'b0 ;
                        wb_cyc_o <= 1'b0 ;
                        wb_cyc_o <= 1'b0 ;
                end
                end
        endcase
        endcase
end
end
 
 
// Signal for retry monitor in state machine when there is read and first (or single) data access
// Signal for retry monitor in state machine when there is read and first (or single) data access
wire ack_rty_response = ACK_I || RTY_I ;
wire ack_rty_response = ACK_I || RTY_I ;
 
 
// Signal first_wb_data_access is set when no WB cycle present till end of first data access of WB cycle on WB bus
// Signal first_wb_data_access is set when no WB cycle present till end of first data access of WB cycle on WB bus
always@(posedge wb_clock_in or posedge reset_in)
always@(posedge wb_clock_in or posedge reset_in)
begin
begin
        if (reset_in)
        if (reset_in)
                first_wb_data_access = 1'b1 ;
                first_wb_data_access = 1'b1 ;
        else
        else
        begin
        begin
                if (~wb_cyc_o)
                if (~wb_cyc_o)
                        first_wb_data_access = 1'b1 ;
                        first_wb_data_access = 1'b1 ;
                else if (ack_rty_response)
                else if (ack_rty_response)
                        first_wb_data_access = 1'b0 ;
                        first_wb_data_access = 1'b0 ;
        end
        end
end
end
 
 
reg             [3:0]    wb_sel_o;
reg             [3:0]    wb_sel_o;
always@(pciw_fifo_cbe_in or pci_tar_be or wb_we_o or burst_transfer or pci_tar_read_request)
always@(pciw_fifo_cbe_in or pci_tar_be or wb_we_o or burst_transfer or pci_tar_read_request)
begin
begin
        case ({wb_we_o, burst_transfer, pci_tar_read_request})
        case ({wb_we_o, burst_transfer, pci_tar_read_request})
        3'b100,
        3'b100,
        3'b101,
        3'b101,
        3'b110,
        3'b110,
        3'b111:
        3'b111:
                wb_sel_o = ~pciw_fifo_cbe_in ;
                wb_sel_o = ~pciw_fifo_cbe_in ;
        3'b011:
        3'b011:
                wb_sel_o = 4'hf ;
                wb_sel_o = 4'hf ;
        default:
        default:
                wb_sel_o = ~pci_tar_be ;
                wb_sel_o = ~pci_tar_be ;
        endcase
        endcase
end
end
 
 
// Signals to FIFO
// Signals to FIFO
assign  pcir_fifo_be_out = 4'hf ; // pci_tar_be ;
assign  pcir_fifo_be_out = 4'hf ; // pci_tar_be ;
 
 
// OUTPUT signals
// OUTPUT signals
assign  pci_error_bc = bc_register ;
assign  pci_error_bc = bc_register ;
 
 
assign  ADR_O = addr_cnt_out ;
assign  ADR_O = addr_cnt_out ;
 
 
`ifdef REGISTER_WBM_OUTPUTS
`ifdef REGISTER_WBM_OUTPUTS
 
 
        reg             wb_cyc_reg ;
        reg             wb_cyc_reg ;
        always@(posedge wb_clock_in or posedge reset_in)
        always@(posedge wb_clock_in or posedge reset_in)
        begin
        begin
                if (reset_in)
                if (reset_in)
                begin
                begin
                        CYC_O   <= 1'h0 ;
                        CYC_O   <= 1'h0 ;
                        STB_O   <= 1'h0 ;
                        STB_O   <= 1'h0 ;
                        WE_O    <= 1'h0 ;
                        WE_O    <= 1'h0 ;
                        CAB_O   <= 1'h0 ;
                        CAB_O   <= 1'h0 ;
                        MDATA_O <= 32'h0 ;
                        MDATA_O <= 32'h0 ;
                        SEL_O   <= 4'h0 ;
                        SEL_O   <= 4'h0 ;
                        wb_cyc_reg <= 1'h0 ;
                        wb_cyc_reg <= 1'h0 ;
                        wb_read_done_out <= 1'b0 ;
                        wb_read_done_out <= 1'b0 ;
                        pcir_fifo_data_out <= 32'h0 ;
                        pcir_fifo_data_out <= 32'h0 ;
                        pcir_fifo_wenable_out <= 1'b0 ;
                        pcir_fifo_wenable_out <= 1'b0 ;
                        pcir_fifo_control_out <= 1'b0 ;
                        pcir_fifo_control_out <= 1'b0 ;
                end
                end
                else
                else
                begin
                begin
                        if (wb_cyc_o)
                        if (wb_cyc_o)
                        begin
                        begin
                                CYC_O   <= ~((ACK_I || RTY_I || ERR_I) && last_data_transferred) ;
                                CYC_O   <= ~((ACK_I || RTY_I || ERR_I) && (last_data_transferred || retried_d)) ;
                                CAB_O   <= ~((ACK_I || RTY_I || ERR_I) && last_data_transferred) && burst_transfer ;
                                CAB_O   <= ~((ACK_I || RTY_I || ERR_I) && (last_data_transferred || retried_d)) && burst_transfer ;
                                STB_O   <= ~((ACK_I || RTY_I || ERR_I) && last_data_transferred) ;
                                STB_O   <= ~((ACK_I || RTY_I || ERR_I) && (last_data_transferred || retried_d)) ;
                        end
                        end
                        WE_O    <= wb_we_o ;
                        WE_O    <= wb_we_o ;
                        if (((wb_cyc_o && ~wb_cyc_reg) || ACK_I) && wb_we_o)
                        if (((wb_cyc_o && ~wb_cyc_reg && !retried_write) || ACK_I) && wb_we_o)
                                MDATA_O <= pciw_fifo_addr_data_in ;
                                MDATA_O <= pciw_fifo_addr_data_in ;
                        if ((wb_cyc_o && ~wb_cyc_reg) || ACK_I)
                        if ((wb_cyc_o && ~wb_cyc_reg) || ACK_I)
                                SEL_O   <= wb_sel_o ;
                                SEL_O   <= wb_sel_o ;
                        wb_cyc_reg <= wb_cyc_o ;
                        wb_cyc_reg <= wb_cyc_o ;
                        wb_read_done_out <= wb_read_done ;
                        wb_read_done_out <= wb_read_done ;
                        pcir_fifo_data_out <= MDATA_I ;
                        pcir_fifo_data_out <= MDATA_I ;
                        pcir_fifo_wenable_out <= pcir_fifo_wenable ;
                        pcir_fifo_wenable_out <= pcir_fifo_wenable ;
                        pcir_fifo_control_out <= pcir_fifo_control ;
                        pcir_fifo_control_out <= pcir_fifo_control ;
                end
                end
        end
        end
        always@(pciw_fifo_renable or last_data_from_pciw_fifo_reg or wb_cyc_o or wb_cyc_reg or wb_we_o or
        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
                        pciw_fifo_control_in or pciw_fifo_empty_in)
                        pciw_fifo_control_in or pciw_fifo_empty_in)
        begin
        begin
                pciw_fifo_renable_out <=        (pciw_fifo_renable && ~wb_cyc_o) ||
                pciw_fifo_renable_out <=        (pciw_fifo_renable && ~wb_cyc_o) ||
                                                                        (pciw_fifo_renable && ~last_data_from_pciw_fifo_reg) ||
                                                                        (pciw_fifo_renable && ~last_data_from_pciw_fifo_reg) ||
                                                                        (wb_cyc_o && ~wb_cyc_reg && wb_we_o) ;
                                                                        (wb_cyc_o && ~wb_cyc_reg && wb_we_o && !retried_write) ;
                last_data_from_pciw_fifo_reg <= pciw_fifo_control_in[`ADDR_CTRL_BIT] || pciw_fifo_empty_in ;
                last_data_from_pciw_fifo_reg <= pciw_fifo_control_in[`ADDR_CTRL_BIT] || pciw_fifo_empty_in ;
        end
        end
`else
`else
        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
        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
                        wb_read_done or MDATA_I or pcir_fifo_wenable or pcir_fifo_control)
                        wb_read_done or MDATA_I or pcir_fifo_wenable or pcir_fifo_control)
        begin
        begin
                CYC_O   <= wb_cyc_o ;
                CYC_O   <= wb_cyc_o ;
                STB_O   <= wb_stb_o ;
                STB_O   <= wb_stb_o ;
                WE_O    <= wb_we_o ;
                WE_O    <= wb_we_o ;
                CAB_O   <= wb_cyc_o & burst_transfer ;
                CAB_O   <= wb_cyc_o & burst_transfer ;
                MDATA_O <= pciw_fifo_addr_data_in ;
                MDATA_O <= pciw_fifo_addr_data_in ;
                SEL_O   <= wb_sel_o ;
                SEL_O   <= wb_sel_o ;
                wb_read_done_out <= wb_read_done ;
                wb_read_done_out <= wb_read_done ;
                pcir_fifo_data_out <= MDATA_I ;
                pcir_fifo_data_out <= MDATA_I ;
                pcir_fifo_wenable_out <= pcir_fifo_wenable ;
                pcir_fifo_wenable_out <= pcir_fifo_wenable ;
                pcir_fifo_control_out <= pcir_fifo_control ;
                pcir_fifo_control_out <= pcir_fifo_control ;
        end
        end
        always@(pciw_fifo_renable or last_data_from_pciw_fifo)
        always@(pciw_fifo_renable or last_data_from_pciw_fifo)
        begin
        begin
                pciw_fifo_renable_out <= pciw_fifo_renable ;
                pciw_fifo_renable_out <= pciw_fifo_renable ;
                last_data_from_pciw_fifo_reg <= last_data_from_pciw_fifo ;
                last_data_from_pciw_fifo_reg <= last_data_from_pciw_fifo ;
        end
        end
`endif
`endif
 
 
 
 
endmodule
endmodule
 
 
 
 

powered by: WebSVN 2.1.0

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