// DUT-connected calibration BMC on door_axis_controller (scaled MAX_CAL_STEPS). // Proves: success/fault mutex; per-phase gated-rise budgets; Nth-rise+limit // prefers limit success over timeout; tiny-travel fault; legal travel success. // Bounded BMC — not an unbounded proof. Vacuous assume(terminal==...) forbidden. module door_axis_cal_formal ( input wire clk, input wire rst_n, input wire tick_500us, input wire open_limit, input wire close_limit, input wire force_rise ); localparam integer MAX_CAL = 6; localparam [2:0] ST_CAL_SEEK_CLOSE = 3'd0; localparam [2:0] ST_CAL_MEASURE_OPEN = 3'd1; localparam [2:0] ST_IDLE = 3'd2; localparam [2:0] ST_FAULT = 3'd6; localparam [2:0] FC_TINY_TRAVEL = 3'd4; localparam [2:0] FC_CAL_CLOSE_TIMEOUT = 3'd2; localparam [2:0] FC_CAL_OPEN_TIMEOUT = 3'd3; wire dut_rst_n = rst_n; wire planner_req; wire [7:0] planner_percent; wire [12:0] planner_travel; wire step; wire dir_close; wire [2:0] status_state; wire [7:0] status_flags; wire [7:0] status_requested_percent; wire [12:0] status_current; wire [12:0] status_target; wire [12:0] status_travel; wire [7:0] status_fault_code; wire calibrated; wire faulted; wire terminal; wire gated_step = step; reg prev_gated; wire gated_step_rise = force_rise & gated_step & ~prev_gated; reg [1:0] reset_cycles; reg [3:0] rise_seek; reg [3:0] rise_measure; reg [3:0] rise_total; door_axis_controller #( .AXIS_ID(0), .MAX_CAL_STEPS(MAX_CAL), .MIN_TRAVEL(2), .ENDPOINT_GUARD_EXTRA(2), .DIR_SETUP_TICKS(1), .PERCENT_MAX(100) ) dut ( .clk(clk), .rst_n(dut_rst_n), .open_limit(open_limit), .close_limit(close_limit), .limit_sync_valid(1'b1), .cal_enable(1'b1), .gated_step(gated_step), .gated_step_rise(gated_step_rise), .tick_500us(tick_500us), .step_toggle_pulse(tick_500us), .rate_quantum_in(21'd0), .rate_quantum_valid(1'b0), .request_valid(1'b0), .requested_percent_in(8'd0), .watchdog_stop(1'b0), .planner_req(planner_req), .planner_percent(planner_percent), .planner_travel(planner_travel), .planner_done(1'b0), .planner_done_axis(2'd0), .planner_done_percent(8'd0), .planner_result(13'd0), .step(step), .dir_close(dir_close), .status_state(status_state), .status_flags(status_flags), .status_requested_percent(status_requested_percent), .status_current(status_current), .status_target(status_target), .status_travel(status_travel), .status_fault_code(status_fault_code), .calibrated(calibrated), .faulted(faulted), .terminal(terminal), .axis_moving(), .axis_allow_rise(), .axis_in_calibration(), .axis_endpoint_crawl(), .axis_dda_run(), .profile_level(), .profile_distance(), .profile_done_steps(), .profile_ramp_unit(), .rate_quantum() ); initial begin reset_cycles = 2'd0; prev_gated = 1'b0; rise_seek = 4'd0; rise_measure = 4'd0; rise_total = 4'd0; end always @(posedge clk) begin assume (rst_n == 1'b0 || rst_n == 1'b1); assume (tick_500us == 1'b0 || tick_500us == 1'b1); assume (open_limit == 1'b0 || open_limit == 1'b1); assume (close_limit == 1'b0 || close_limit == 1'b1); assume (force_rise == 1'b0 || force_rise == 1'b1); assume (!(tick_500us && $past(tick_500us))); // both-limits path covered by cover only; keep main BMC free of both. assume (!(open_limit && close_limit)); if ($initstate || reset_cycles < 2) begin assume (!dut_rst_n); reset_cycles <= reset_cycles + 1'b1; end else begin assume (dut_rst_n); end if (!dut_rst_n) begin prev_gated <= 1'b0; rise_seek <= 4'd0; rise_measure <= 4'd0; rise_total <= 4'd0; end else begin prev_gated <= gated_step; if (gated_step_rise) begin rise_total <= rise_total + 1'b1; if (status_state == ST_CAL_SEEK_CLOSE) rise_seek <= rise_seek + 1'b1; if (status_state == ST_CAL_MEASURE_OPEN) rise_measure <= rise_measure + 1'b1; end assert (!(calibrated && faulted)); if (terminal) assert (faulted || calibrated); // Per-phase budgets: never emit the (MAX+1)-th rise in a phase. assert (rise_seek <= MAX_CAL[3:0]); assert (rise_measure <= MAX_CAL[3:0]); assert (rise_total <= (MAX_CAL * 2)); // Nth rise + target limit same edge → limit success, not timeout fault. if (status_state == ST_CAL_SEEK_CLOSE && gated_step_rise && close_limit && !open_limit && (rise_seek + 1'b1 == MAX_CAL[3:0])) begin assert (status_fault_code[2:0] != FC_CAL_CLOSE_TIMEOUT); end if (status_state == ST_CAL_MEASURE_OPEN && gated_step_rise && open_limit && !close_limit && (rise_measure + 1'b1 == MAX_CAL[3:0])) begin assert (status_fault_code[2:0] != FC_CAL_OPEN_TIMEOUT); end // Tiny travel: open_limit completing measure with travel < MIN → fault. if (faulted && (status_fault_code[2:0] == FC_TINY_TRAVEL)) assert (!calibrated); // Legal success: calibrated idle with travel in [MIN, MAX]. if (calibrated && !faulted && (status_state == ST_IDLE) && terminal) begin assert (status_travel >= 13'd2); assert (status_travel <= MAX_CAL[12:0]); end cover (calibrated && terminal && !faulted); cover (faulted && terminal); cover (gated_step_rise); cover (faulted && (status_fault_code[2:0] == FC_TINY_TRAVEL)); cover (status_state == ST_CAL_MEASURE_OPEN && gated_step_rise && open_limit && (rise_measure + 1'b1 == MAX_CAL[3:0])); end end endmodule