// SPDX-License-Identifier: MIT
// Illustrative integration snippets, NOT compiled or simulator-qualified here.
// Selected AXI4-Lite write-response rules only; not a full protocol checker.
// Counts must not wrap within a run; reset must be observed before transactions.
module header7f_axi_lite_write_response_assertions (
  input logic ACLK, ARESETn,
  input logic AWVALID, AWREADY, WVALID, WREADY,
  input logic BVALID, BREADY,
  input logic [1:0] BRESP
);
  logic [31:0] aw_accepted, w_accepted, b_accepted;
  always_ff @(posedge ACLK or negedge ARESETn) begin
    if (!ARESETn) begin
      aw_accepted <= 32'd0;
      w_accepted <= 32'd0;
      b_accepted <= 32'd0;
    end else begin
      if (AWVALID && AWREADY) aw_accepted <= aw_accepted + 32'd1;
      if (WVALID && WREADY) w_accepted <= w_accepted + 32'd1;
      if (BVALID && BREADY) b_accepted <= b_accepted + 32'd1;
    end
  end

  // The response must remain available through the next accepting edge.
  ap_bvalid_hold: assert property (
    @(posedge ACLK) disable iff (!ARESETn)
    (BVALID && !BREADY) |=> BVALID
  );
  ap_bresp_hold: assert property (
    @(posedge ACLK) disable iff (!ARESETn)
    (BVALID && !BREADY) |=> $stable(BRESP)
  );

  // Sampled counters contain handshakes from EARLIER edges; AW and W may
  // arrive in either order. The current edge cannot retroactively authorize B.
  ap_b_after_aw_and_w: assert property (
    @(posedge ACLK) disable iff (!ARESETn)
    BVALID |-> ((aw_accepted > b_accepted) && (w_accepted > b_accepted))
  );
endmodule
