// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: niu_pio_rw_sm.v
// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// For the avoidance of doubt, and except that if any non-GPL license
// choice is available it will apply instead, Sun elects to use only
// the General Public License version 2 (GPLv2) at this time for any
// software where a choice of GPL license versions is made
// available with the language indicating that GPLv2 or any later version
// may be used, or where a choice of which version of the GPL is applied is
// otherwise unspecified.
// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
// CA 95054 USA or visit www.sun.com if you need additional information or
// ========== Copyright Header End ============================================
/*************************************************************************
* File Name : niu_pio_rw_sm.v
* Description : It contains niu pio interface, interrupt controller,
* Date Created : 3/08/2004
* Copyright (c) 2020, Sun Microsystems, Inc.
* Sun Proprietary and Confidential
*************************************************************************/
module niu_pio_rw_sm (/*AUTOARG*/
input [9:0] ack_TO_value;
output [2:0] pio_rw_state;
reg [2:0] nx_pio_rw_state;
parameter R_NACK = 3'd3; // ucb err
parameter R_ACK = 3'd4; // ucb
parameter R_NACK_noerr = 3'd5; // ucb
wire detect_rnack_state ;
wire assert_pio_peu_32b_int ;
assign detect_rnack_state = ( pio_rw_state[2] &
assign assert_pio_peu_32b_int = (detect_rnack_state & pio_clients_32b) ;
assign pio_peu_32b_int = (pio_peu_32b_int_mod || assert_pio_peu_32b_int) ;
assign pio_peu_32b_int = pio_peu_32b_int_mod ;
always @ (/*AUTOSENSE*/TO or empty or pio_ack or pio_err
or pio_rw_state or rd or sel1 or ucb_rack_busy
case (pio_rw_state) // synopsys full_case parallel_case
nx_pio_rw_state = pio_rw_state;
nx_pio_rw_state = CHK_SEL;
CHK_SEL:casex({sel1,rd}) // synopsys full_case parallel_case
2'b00: nx_pio_rw_state = IDLE; // no sel1 and write
nx_pio_rw_state = R_NACK_noerr; // no sel1 and write
nx_pio_rw_state = R_NACK; // no sel1 and write
2'b1x: nx_pio_rw_state = CHK_TO; // sel1 and write
default:nx_pio_rw_state = IDLE;
CHK_TO: casex({pio_err,rd,TO,pio_ack}) // synopsys full_case parallel_case
4'bxx00:nx_pio_rw_state = pio_rw_state; //~TO &~pio_ack
4'bx0x1:nx_pio_rw_state = IDLE; // pio_ack & wr
4'b01x1:nx_pio_rw_state = R_ACK; // pio_ack & rd & ~err
4'b11x1:nx_pio_rw_state = R_NACK; // pio_ack & rd & err
4'bx010:nx_pio_rw_state = IDLE; // TO &~pio_ack & wr
4'bx110:nx_pio_rw_state = R_NACK; // TO &~pio_ack & rd & err
default:nx_pio_rw_state = IDLE;
R_NACK: if (ucb_rack_busy)
nx_pio_rw_state = pio_rw_state;
R_ACK: if (ucb_rack_busy)
nx_pio_rw_state = pio_rw_state;
R_NACK_noerr: if (ucb_rack_busy)
nx_pio_rw_state = pio_rw_state;
default: nx_pio_rw_state = IDLE;
dffr #(3) pio_rw_state_dffr(.d(nx_pio_rw_state[2:0]),.reset(reset),.clk(clk),.q(pio_rw_state[2:0]));
assign pio_sel_state =(pio_rw_state == CHK_SEL) | (pio_rw_state == CHK_TO);
assign TO_cnt_state = pio_rw_state == CHK_TO;
assign TO =(ack_TO_cnt == ack_TO_value) & ack_TO_en;
assign goto_idle = nx_pio_rw_state == IDLE;
always @ (/*AUTOSENSE*/TO or TO_cnt_state or ack_TO_cnt or ack_TO_en
or ack_TO_value or fifo_rd_en or goto_idle)
if (goto_idle | fifo_rd_en)
else if ((ack_TO_cnt != ack_TO_value) & TO_cnt_state & ack_TO_en)
nx_ack_TO_cnt = ack_TO_cnt + 10'b1;
nx_ack_TO_cnt = ack_TO_cnt; // hold
else nx_ack_TO_cnt = ack_TO_cnt; // hold
dffr # (10) ack_TO_cnt_dffre(.reset(reset),.clk(clk),.d(nx_ack_TO_cnt[9:0]),.q(ack_TO_cnt[9:0]));
endmodule // niu_pio_rw_sm