| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- // DUT-connected watchdog drain BMC on real door_axis_controller.
- // After watchdog_stop is accepted with STEP high, STEP returns low within
- // one half-tick window and no new STEP rise occurs while stop remains.
- // Bounded BMC — not an unbounded mathematical proof.
- module door_axis_watchdog_formal (
- input wire clk,
- input wire rst_n,
- input wire tick_500us,
- input wire watchdog_stop,
- input wire request_valid,
- input wire [7:0] requested_percent_in,
- input wire open_limit,
- input wire close_limit
- );
- wire dut_rst_n = rst_n;
- 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 planner_req;
- wire [7:0] planner_percent;
- wire [12:0] planner_travel;
- reg [1:0] reset_cycles;
- reg step_q;
- reg wd_seen;
- reg wd_seen_while_high;
- reg [3:0] ticks_since_wd_high;
- reg dir_at_wd;
- wire gated_step = step;
- wire gated_step_rise = step && !step_q;
- door_axis_controller #(
- .AXIS_ID(0),
- .MAX_CAL_STEPS(8),
- .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(request_valid),
- .requested_percent_in(requested_percent_in),
- .watchdog_stop(watchdog_stop),
- .planner_req(planner_req),
- .planner_percent(planner_percent),
- .planner_travel(planner_travel),
- // Instant planner reply for mid targets (combinational-style next-cycle).
- .planner_done(planner_req),
- .planner_done_axis(2'd0),
- .planner_done_percent(planner_percent),
- .planner_result(13'd2),
- .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;
- step_q = 1'b0;
- wd_seen = 1'b0;
- wd_seen_while_high = 1'b0;
- ticks_since_wd_high = 4'd0;
- dir_at_wd = 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 (watchdog_stop == 1'b0 || watchdog_stop == 1'b1);
- assume (request_valid == 1'b0 || request_valid == 1'b1);
- assume (requested_percent_in <= 8'd100);
- assume (open_limit == 1'b0 || open_limit == 1'b1);
- assume (close_limit == 1'b0 || close_limit == 1'b1);
- assume (!(open_limit && close_limit));
- assume (!(tick_500us && $past(tick_500us)));
- 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
- step_q <= 1'b0;
- wd_seen <= 1'b0;
- wd_seen_while_high <= 1'b0;
- ticks_since_wd_high <= 4'd0;
- end else begin
- step_q <= step;
- // Same-cycle request vs watchdog: request/feed wins (env constraint).
- assume (!(request_valid && watchdog_stop));
- // Only latch when DUT can accept watchdog (post-cal runtime).
- if (watchdog_stop && calibrated && !faulted && !wd_seen) begin
- wd_seen <= 1'b1;
- if (step) begin
- wd_seen_while_high <= 1'b1;
- ticks_since_wd_high <= 4'd0;
- dir_at_wd <= dir_close;
- end
- end
- // Property window: only while stop stays held after first accept.
- // Release or a later request ends the window (latest-wins restart).
- if (wd_seen && (!watchdog_stop || request_valid)) begin
- wd_seen <= 1'b0;
- wd_seen_while_high <= 1'b0;
- ticks_since_wd_high <= 4'd0;
- end else if (wd_seen_while_high && watchdog_stop) begin
- if (tick_500us && ticks_since_wd_high < 4'd15)
- ticks_since_wd_high <= ticks_since_wd_high + 4'd1;
- // DIR stable while draining high pulse.
- if (step)
- assert (dir_close == dir_at_wd);
- // After at most one half-tick following accept, STEP must be low.
- if (ticks_since_wd_high >= 4'd1)
- assert (step == 1'b0);
- end
- // Once stop accepted and STEP low, no new rises while stop held.
- if (wd_seen && watchdog_stop && !request_valid && !step_q)
- assert (!(step && !step_q));
- cover (wd_seen_while_high && (step == 1'b0) && watchdog_stop);
- cover (calibrated);
- end
- end
- endmodule
|