| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- // DUT-connected: door_axis_controller watchdog high-pulse drain.
- // Bounded BMC (scaled params). Not an unbounded proof.
- module door_axis_watchdog_drain_formal (
- input wire clk,
- input wire rst_n,
- input wire tick_500us,
- input wire request_valid,
- input wire [7:0] requested_percent_in,
- input wire watchdog_stop,
- input wire open_limit,
- input wire close_limit
- );
- localparam integer MAX_CAL = 8;
- localparam [2:0] ST_IDLE = 3'd2;
- localparam [2:0] ST_WAIT_REPLAN = 3'd5;
- wire dut_rst_n = rst_n;
- wire planner_req;
- wire [7:0] planner_percent;
- wire [12:0] planner_travel;
- reg planner_done;
- reg [1:0] planner_done_axis;
- reg [7:0] planner_done_percent;
- reg [12:0] planner_result;
- 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;
- // Environment: gated STEP mirrors internal STEP when limits clear (no hard gate).
- wire gated_step = step & ~(open_limit | close_limit);
- reg prev_gated;
- wire gated_step_rise = gated_step & ~prev_gated;
- reg [1:0] reset_cycles;
- reg saw_wd_accept;
- reg [3:0] ticks_since_wd;
- reg step_was_high_at_wd;
- reg prev_step;
- door_axis_controller #(
- .AXIS_ID(0),
- .MAX_CAL_STEPS(MAX_CAL),
- .MIN_TRAVEL(2),
- .ENDPOINT_GUARD_EXTRA(4),
- .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(request_valid),
- .requested_percent_in(requested_percent_in),
- .watchdog_stop(watchdog_stop),
- .planner_req(planner_req),
- .planner_percent(planner_percent),
- .planner_travel(planner_travel),
- .planner_done(planner_done),
- .planner_done_axis(planner_done_axis),
- .planner_done_percent(planner_done_percent),
- .planner_result(planner_result),
- .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;
- planner_done = 1'b0;
- planner_done_axis = 2'd0;
- planner_done_percent = 8'd0;
- planner_result = 13'd0;
- saw_wd_accept = 1'b0;
- ticks_since_wd = 4'd0;
- step_was_high_at_wd = 1'b0;
- prev_step = 1'b0;
- end
- always @(posedge clk) begin
- assume (rst_n == 1'b0 || rst_n == 1'b1);
- assume (tick_500us == 1'b0 || tick_500us == 1'b1);
- assume (request_valid == 1'b0 || request_valid == 1'b1);
- assume (watchdog_stop == 1'b0 || watchdog_stop == 1'b1);
- assume (open_limit == 1'b0 || open_limit == 1'b1);
- assume (close_limit == 1'b0 || close_limit == 1'b1);
- assume (requested_percent_in <= 8'd100);
- assume (!(tick_500us && $past(tick_500us)));
- assume (!(open_limit && close_limit));
- assume (!(request_valid && watchdog_stop));
- if ($initstate || reset_cycles < 2) begin
- assume (!dut_rst_n);
- reset_cycles <= reset_cycles + 1'b1;
- end else begin
- assume (dut_rst_n);
- end
- planner_done <= 1'b0;
- if (planner_req) begin
- planner_done <= 1'b1;
- planner_done_axis <= 2'd0;
- planner_done_percent <= planner_percent;
- planner_result <= 13'd2;
- end
- if (!dut_rst_n) begin
- prev_gated <= 1'b0;
- saw_wd_accept <= 1'b0;
- ticks_since_wd <= 4'd0;
- step_was_high_at_wd <= 1'b0;
- prev_step <= 1'b0;
- end else begin
- prev_gated <= gated_step;
- prev_step <= step;
- // Capture first accepted watchdog while calibrated/runtime.
- if (watchdog_stop && calibrated && !faulted && !request_valid && !saw_wd_accept) begin
- saw_wd_accept <= 1'b1;
- step_was_high_at_wd <= step;
- ticks_since_wd <= 4'd0;
- end else if (saw_wd_accept && tick_500us && ticks_since_wd != 4'hF) begin
- ticks_since_wd <= ticks_since_wd + 1'b1;
- end
- // End window on stop release or new request (latest-wins).
- if (saw_wd_accept && (!watchdog_stop || request_valid)) begin
- saw_wd_accept <= 1'b0;
- ticks_since_wd <= 4'd0;
- step_was_high_at_wd <= 1'b0;
- end else if (saw_wd_accept && watchdog_stop && !request_valid) begin
- // No new STEP rising edge while stop held.
- assert (!(step && !prev_step));
- // If STEP was high at accept, it must fall within a few half-ticks.
- if (step_was_high_at_wd && (ticks_since_wd >= 4'd2))
- assert (step == 1'b0);
- // Eventually idle / wd-stopped after drain window.
- if (ticks_since_wd >= 4'd3)
- assert ((status_state == ST_IDLE) || (status_state == ST_WAIT_REPLAN) || (step == 1'b0));
- end
- cover (saw_wd_accept && step_was_high_at_wd && (step == 1'b0));
- cover (saw_wd_accept && !step_was_high_at_wd);
- end
- end
- endmodule
|