door_axis_watchdog_drain_formal.v 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // DUT-connected: door_axis_controller watchdog high-pulse drain.
  2. // Bounded BMC (scaled params). Not an unbounded proof.
  3. module door_axis_watchdog_drain_formal (
  4. input wire clk,
  5. input wire rst_n,
  6. input wire tick_500us,
  7. input wire request_valid,
  8. input wire [7:0] requested_percent_in,
  9. input wire watchdog_stop,
  10. input wire open_limit,
  11. input wire close_limit
  12. );
  13. localparam integer MAX_CAL = 8;
  14. localparam [2:0] ST_IDLE = 3'd2;
  15. localparam [2:0] ST_WAIT_REPLAN = 3'd5;
  16. wire dut_rst_n = rst_n;
  17. wire planner_req;
  18. wire [7:0] planner_percent;
  19. wire [12:0] planner_travel;
  20. reg planner_done;
  21. reg [1:0] planner_done_axis;
  22. reg [7:0] planner_done_percent;
  23. reg [12:0] planner_result;
  24. wire step;
  25. wire dir_close;
  26. wire [2:0] status_state;
  27. wire [7:0] status_flags;
  28. wire [7:0] status_requested_percent;
  29. wire [12:0] status_current;
  30. wire [12:0] status_target;
  31. wire [12:0] status_travel;
  32. wire [7:0] status_fault_code;
  33. wire calibrated;
  34. wire faulted;
  35. wire terminal;
  36. // Environment: gated STEP mirrors internal STEP when limits clear (no hard gate).
  37. wire gated_step = step & ~(open_limit | close_limit);
  38. reg prev_gated;
  39. wire gated_step_rise = gated_step & ~prev_gated;
  40. reg [1:0] reset_cycles;
  41. reg saw_wd_accept;
  42. reg [3:0] ticks_since_wd;
  43. reg step_was_high_at_wd;
  44. reg prev_step;
  45. door_axis_controller #(
  46. .AXIS_ID(0),
  47. .MAX_CAL_STEPS(MAX_CAL),
  48. .MIN_TRAVEL(2),
  49. .ENDPOINT_GUARD_EXTRA(4),
  50. .DIR_SETUP_TICKS(1),
  51. .PERCENT_MAX(100)
  52. ) dut (
  53. .clk(clk), .rst_n(dut_rst_n),
  54. .open_limit(open_limit), .close_limit(close_limit),
  55. .limit_sync_valid(1'b1),
  56. .cal_enable(1'b1),
  57. .gated_step(gated_step), .gated_step_rise(gated_step_rise),
  58. .tick_500us(tick_500us),
  59. .step_toggle_pulse(tick_500us),
  60. .rate_quantum_in(21'd0),
  61. .rate_quantum_valid(1'b0),
  62. .request_valid(request_valid),
  63. .requested_percent_in(requested_percent_in),
  64. .watchdog_stop(watchdog_stop),
  65. .planner_req(planner_req),
  66. .planner_percent(planner_percent),
  67. .planner_travel(planner_travel),
  68. .planner_done(planner_done),
  69. .planner_done_axis(planner_done_axis),
  70. .planner_done_percent(planner_done_percent),
  71. .planner_result(planner_result),
  72. .step(step), .dir_close(dir_close),
  73. .status_state(status_state), .status_flags(status_flags),
  74. .status_requested_percent(status_requested_percent),
  75. .status_current(status_current), .status_target(status_target),
  76. .status_travel(status_travel), .status_fault_code(status_fault_code),
  77. .calibrated(calibrated), .faulted(faulted), .terminal(terminal),
  78. .axis_moving(), .axis_allow_rise(), .axis_in_calibration(), .axis_endpoint_crawl(),
  79. .axis_dda_run(),
  80. .profile_level(), .profile_distance(), .profile_done_steps(), .profile_ramp_unit(),
  81. .rate_quantum()
  82. );
  83. initial begin
  84. reset_cycles = 2'd0;
  85. prev_gated = 1'b0;
  86. planner_done = 1'b0;
  87. planner_done_axis = 2'd0;
  88. planner_done_percent = 8'd0;
  89. planner_result = 13'd0;
  90. saw_wd_accept = 1'b0;
  91. ticks_since_wd = 4'd0;
  92. step_was_high_at_wd = 1'b0;
  93. prev_step = 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 (request_valid == 1'b0 || request_valid == 1'b1);
  99. assume (watchdog_stop == 1'b0 || watchdog_stop == 1'b1);
  100. assume (open_limit == 1'b0 || open_limit == 1'b1);
  101. assume (close_limit == 1'b0 || close_limit == 1'b1);
  102. assume (requested_percent_in <= 8'd100);
  103. assume (!(tick_500us && $past(tick_500us)));
  104. assume (!(open_limit && close_limit));
  105. assume (!(request_valid && watchdog_stop));
  106. if ($initstate || reset_cycles < 2) begin
  107. assume (!dut_rst_n);
  108. reset_cycles <= reset_cycles + 1'b1;
  109. end else begin
  110. assume (dut_rst_n);
  111. end
  112. planner_done <= 1'b0;
  113. if (planner_req) begin
  114. planner_done <= 1'b1;
  115. planner_done_axis <= 2'd0;
  116. planner_done_percent <= planner_percent;
  117. planner_result <= 13'd2;
  118. end
  119. if (!dut_rst_n) begin
  120. prev_gated <= 1'b0;
  121. saw_wd_accept <= 1'b0;
  122. ticks_since_wd <= 4'd0;
  123. step_was_high_at_wd <= 1'b0;
  124. prev_step <= 1'b0;
  125. end else begin
  126. prev_gated <= gated_step;
  127. prev_step <= step;
  128. // Capture first accepted watchdog while calibrated/runtime.
  129. if (watchdog_stop && calibrated && !faulted && !request_valid && !saw_wd_accept) begin
  130. saw_wd_accept <= 1'b1;
  131. step_was_high_at_wd <= step;
  132. ticks_since_wd <= 4'd0;
  133. end else if (saw_wd_accept && tick_500us && ticks_since_wd != 4'hF) begin
  134. ticks_since_wd <= ticks_since_wd + 1'b1;
  135. end
  136. // End window on stop release or new request (latest-wins).
  137. if (saw_wd_accept && (!watchdog_stop || request_valid)) begin
  138. saw_wd_accept <= 1'b0;
  139. ticks_since_wd <= 4'd0;
  140. step_was_high_at_wd <= 1'b0;
  141. end else if (saw_wd_accept && watchdog_stop && !request_valid) begin
  142. // No new STEP rising edge while stop held.
  143. assert (!(step && !prev_step));
  144. // If STEP was high at accept, it must fall within a few half-ticks.
  145. if (step_was_high_at_wd && (ticks_since_wd >= 4'd2))
  146. assert (step == 1'b0);
  147. // Eventually idle / wd-stopped after drain window.
  148. if (ticks_since_wd >= 4'd3)
  149. assert ((status_state == ST_IDLE) || (status_state == ST_WAIT_REPLAN) || (step == 1'b0));
  150. end
  151. cover (saw_wd_accept && step_was_high_at_wd && (step == 1'b0));
  152. cover (saw_wd_accept && !step_was_high_at_wd);
  153. end
  154. end
  155. endmodule