//--------------------------------------------------------------------------- // // ASSERT_HANDSHAKE // //--------------------------------------------------------------------------- // NAME // ASSERT_HANDSHAKE - Validate proper handshaking behavior of // req / ack type of signals // //--------------------------------------------------------------------------- module assert_handshake (clk, reset_n, req, ack); // synopsys template parameter severity_level=0; parameter min_ack_cycle=0; // default don't check parameter max_ack_cycle=0; // default don't check parameter req_drop=0; // default don't check parameter deassert_count=0; // default don't check parameter max_ack_length=0; // default don't check `ifdef ASSERT_V1_0_1 // Previous version of the library `else // New version to allow for future options parameter options = 0; `endif parameter msg="VIOLATION"; input clk; input reset_n; input req; input ack; //synopsys translate_off `ifdef ASSERT_ON parameter REQ_ACK_START = 2'b00; parameter REQ_ACK_WAIT = 2'b01; parameter REQ_ACK_ERR = 2'b10; parameter REQ_ACK_DEASSERT = 2'b11; reg [1:0] r_state; reg [1:0] r_r_state; reg r_req; reg r_ack; integer i; integer j; parameter assert_name = "ASSERT_EVENT_HANDSHAKE"; integer error_count; initial error_count = 0; `include "ovl_task.h" `ifdef ASSERT_INIT_MSG initial ovl_init_msg; // Call the User Defined Init Message Routine `endif initial begin r_state=REQ_ACK_START; r_r_state=REQ_ACK_START; r_req=0; r_ack=0; i = 0; j = 0; end always @(posedge clk) begin `ifdef ASSERT_GLOBAL_RESET if (`ASSERT_GLOBAL_RESET != 1'b0) begin `else if (reset_n != 0) begin // active low reset `endif case (r_state) REQ_ACK_START: begin if ((max_ack_length != 0) && ack == 1'b1 && r_ack == 1'b1) begin j <= j+1; if (j >= max_ack_length) begin r_state <= REQ_ACK_ERR; ovl_error("ack max length violation"); end end if (req == 1'b1) begin if (r_ack == 1'b1 && ack == 1'b1 && r_req == 1'b0) begin r_state <= REQ_ACK_ERR; ovl_error("multiple req violation"); end else if (deassert_count != 0 && r_req == 1'b1 && req == 1'b1 && ack == 1'b0) begin r_state <= REQ_ACK_DEASSERT; i <= deassert_count; end else if ((min_ack_cycle != 0) && ack && r_ack == 1'b0) begin ovl_error("ack min cycle violation"); end else if (ack == 1'b0) begin r_state <= REQ_ACK_WAIT; i <= 1; j <= 0; end end else begin if (ack == 1'b1 && r_ack == 1'b0) begin r_state <= REQ_ACK_ERR; ovl_error("ack without req violation"); end end end REQ_ACK_WAIT: begin i <= i + 1; if (ack) begin r_state <= REQ_ACK_START; j <= 1; end if ((min_ack_cycle != 0) && (i < min_ack_cycle) && ack == 1'b1) begin r_state <= REQ_ACK_ERR; ovl_error("ack min cycle violation"); end else if ((!ack) && (max_ack_cycle != 0) && i >= max_ack_cycle) begin r_state <= REQ_ACK_ERR; ovl_error("ack max cycle violation"); end else if (req_drop == 1'b1 && req == 1'b0) begin r_state <= REQ_ACK_ERR; ovl_error("req drop violation"); end else if (req == 1'b1 && r_req == 1'b0) begin r_state <= REQ_ACK_ERR; ovl_error("multiple req violation"); end end REQ_ACK_ERR: begin if (req == 1'b1 && ack == 1'b0 && r_req == 1'b0) begin r_state <= REQ_ACK_WAIT; i <= 0; j <= 0; end else if (ack == 1'b0 && r_ack == 1'b1) begin r_state <= REQ_ACK_START; i <= 0; j <= 0; end end REQ_ACK_DEASSERT: begin i <= i-1; if (i == 1) begin if (req == 1'b1) begin r_state <= REQ_ACK_ERR; ovl_error("req deassert violation"); end else r_state <= REQ_ACK_START; end end endcase r_r_state <= r_state; r_ack <= ack; r_req <= req; end else begin r_state <= REQ_ACK_START; r_r_state <= REQ_ACK_START; r_ack <= 0; r_req <= 0; i <= 0; j <= 0; end end // always `endif //synopsys translate_on endmodule