door_axis_watchdog_formal.v 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // DUT-connected watchdog drain BMC on real door_axis_controller.
  2. // After watchdog_stop is accepted with STEP high, STEP returns low within
  3. // one half-tick window and no new STEP rise occurs while stop remains.
  4. // Bounded BMC — not an unbounded mathematical proof.
  5. module door_axis_watchdog_formal (
  6. input wire clk,
  7. input wire rst_n,
  8. input wire tick_500us,
  9. input wire watchdog_stop,
  10. input wire request_valid,
  11. input wire [7:0] requested_percent_in,
  12. input wire open_limit,
  13. input wire close_limit
  14. );
  15. wire dut_rst_n = rst_n;
  16. wire step;
  17. wire dir_close;
  18. wire [2:0] status_state;
  19. wire [7:0] status_flags;
  20. wire [7:0] status_requested_percent;
  21. wire [12:0] status_current;
  22. wire [12:0] status_target;
  23. wire [12:0] status_travel;
  24. wire [7:0] status_fault_code;
  25. wire calibrated;
  26. wire faulted;
  27. wire terminal;
  28. wire planner_req;
  29. wire [7:0] planner_percent;
  30. wire [12:0] planner_travel;
  31. reg [1:0] reset_cycles;
  32. reg step_q;
  33. reg wd_seen;
  34. reg wd_seen_while_high;
  35. reg [3:0] ticks_since_wd_high;
  36. reg dir_at_wd;
  37. wire gated_step = step;
  38. wire gated_step_rise = step && !step_q;
  39. door_axis_controller #(
  40. .AXIS_ID(0),
  41. .MAX_CAL_STEPS(8),
  42. .MIN_TRAVEL(2),
  43. .ENDPOINT_GUARD_EXTRA(2),
  44. .DIR_SETUP_TICKS(1),
  45. .PERCENT_MAX(100)
  46. ) dut (
  47. .clk(clk),
  48. .rst_n(dut_rst_n),
  49. .open_limit(open_limit),
  50. .close_limit(close_limit),
  51. .limit_sync_valid(1'b1),
  52. .cal_enable(1'b1),
  53. .gated_step(gated_step),
  54. .gated_step_rise(gated_step_rise),
  55. .tick_500us(tick_500us),
  56. .step_toggle_pulse(tick_500us),
  57. .rate_quantum_in(21'd0),
  58. .rate_quantum_valid(1'b0),
  59. .request_valid(request_valid),
  60. .requested_percent_in(requested_percent_in),
  61. .watchdog_stop(watchdog_stop),
  62. .planner_req(planner_req),
  63. .planner_percent(planner_percent),
  64. .planner_travel(planner_travel),
  65. // Instant planner reply for mid targets (combinational-style next-cycle).
  66. .planner_done(planner_req),
  67. .planner_done_axis(2'd0),
  68. .planner_done_percent(planner_percent),
  69. .planner_result(13'd2),
  70. .step(step),
  71. .dir_close(dir_close),
  72. .status_state(status_state),
  73. .status_flags(status_flags),
  74. .status_requested_percent(status_requested_percent),
  75. .status_current(status_current),
  76. .status_target(status_target),
  77. .status_travel(status_travel),
  78. .status_fault_code(status_fault_code),
  79. .calibrated(calibrated),
  80. .faulted(faulted),
  81. .terminal(terminal),
  82. .axis_moving(), .axis_allow_rise(), .axis_in_calibration(), .axis_endpoint_crawl(),
  83. .axis_dda_run(),
  84. .profile_level(), .profile_distance(), .profile_done_steps(), .profile_ramp_unit(),
  85. .rate_quantum()
  86. );
  87. initial begin
  88. reset_cycles = 2'd0;
  89. step_q = 1'b0;
  90. wd_seen = 1'b0;
  91. wd_seen_while_high = 1'b0;
  92. ticks_since_wd_high = 4'd0;
  93. dir_at_wd = 1'b0;
  94. end
  95. always @(posedge clk) begin
  96. assume (rst_n == 1'b0 || rst_n == 1'b1);
  97. assume (tick_500us == 1'b0 || tick_500us == 1'b1);
  98. assume (watchdog_stop == 1'b0 || watchdog_stop == 1'b1);
  99. assume (request_valid == 1'b0 || request_valid == 1'b1);
  100. assume (requested_percent_in <= 8'd100);
  101. assume (open_limit == 1'b0 || open_limit == 1'b1);
  102. assume (close_limit == 1'b0 || close_limit == 1'b1);
  103. assume (!(open_limit && close_limit));
  104. assume (!(tick_500us && $past(tick_500us)));
  105. if ($initstate || reset_cycles < 2) begin
  106. assume (!dut_rst_n);
  107. reset_cycles <= reset_cycles + 1'b1;
  108. end else begin
  109. assume (dut_rst_n);
  110. end
  111. if (!dut_rst_n) begin
  112. step_q <= 1'b0;
  113. wd_seen <= 1'b0;
  114. wd_seen_while_high <= 1'b0;
  115. ticks_since_wd_high <= 4'd0;
  116. end else begin
  117. step_q <= step;
  118. // Same-cycle request vs watchdog: request/feed wins (env constraint).
  119. assume (!(request_valid && watchdog_stop));
  120. // Only latch when DUT can accept watchdog (post-cal runtime).
  121. if (watchdog_stop && calibrated && !faulted && !wd_seen) begin
  122. wd_seen <= 1'b1;
  123. if (step) begin
  124. wd_seen_while_high <= 1'b1;
  125. ticks_since_wd_high <= 4'd0;
  126. dir_at_wd <= dir_close;
  127. end
  128. end
  129. // Property window: only while stop stays held after first accept.
  130. // Release or a later request ends the window (latest-wins restart).
  131. if (wd_seen && (!watchdog_stop || request_valid)) begin
  132. wd_seen <= 1'b0;
  133. wd_seen_while_high <= 1'b0;
  134. ticks_since_wd_high <= 4'd0;
  135. end else if (wd_seen_while_high && watchdog_stop) begin
  136. if (tick_500us && ticks_since_wd_high < 4'd15)
  137. ticks_since_wd_high <= ticks_since_wd_high + 4'd1;
  138. // DIR stable while draining high pulse.
  139. if (step)
  140. assert (dir_close == dir_at_wd);
  141. // After at most one half-tick following accept, STEP must be low.
  142. if (ticks_since_wd_high >= 4'd1)
  143. assert (step == 1'b0);
  144. end
  145. // Once stop accepted and STEP low, no new rises while stop held.
  146. if (wd_seen && watchdog_stop && !request_valid && !step_q)
  147. assert (!(step && !step_q));
  148. cover (wd_seen_while_high && (step == 1'b0) && watchdog_stop);
  149. cover (calibrated);
  150. end
  151. end
  152. endmodule