door_axis_cal_formal.v 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // DUT-connected calibration BMC on door_axis_controller (scaled MAX_CAL_STEPS).
  2. // Proves: success/fault mutex; per-phase gated-rise budgets; Nth-rise+limit
  3. // prefers limit success over timeout; tiny-travel fault; legal travel success.
  4. // Bounded BMC — not an unbounded proof. Vacuous assume(terminal==...) forbidden.
  5. module door_axis_cal_formal (
  6. input wire clk,
  7. input wire rst_n,
  8. input wire tick_500us,
  9. input wire open_limit,
  10. input wire close_limit,
  11. input wire force_rise
  12. );
  13. localparam integer MAX_CAL = 6;
  14. localparam [2:0] ST_CAL_SEEK_CLOSE = 3'd0;
  15. localparam [2:0] ST_CAL_MEASURE_OPEN = 3'd1;
  16. localparam [2:0] ST_IDLE = 3'd2;
  17. localparam [2:0] ST_FAULT = 3'd6;
  18. localparam [2:0] FC_TINY_TRAVEL = 3'd4;
  19. localparam [2:0] FC_CAL_CLOSE_TIMEOUT = 3'd2;
  20. localparam [2:0] FC_CAL_OPEN_TIMEOUT = 3'd3;
  21. wire dut_rst_n = rst_n;
  22. wire planner_req;
  23. wire [7:0] planner_percent;
  24. wire [12:0] planner_travel;
  25. wire step;
  26. wire dir_close;
  27. wire [2:0] status_state;
  28. wire [7:0] status_flags;
  29. wire [7:0] status_requested_percent;
  30. wire [12:0] status_current;
  31. wire [12:0] status_target;
  32. wire [12:0] status_travel;
  33. wire [7:0] status_fault_code;
  34. wire calibrated;
  35. wire faulted;
  36. wire terminal;
  37. wire gated_step = step;
  38. reg prev_gated;
  39. wire gated_step_rise = force_rise & gated_step & ~prev_gated;
  40. reg [1:0] reset_cycles;
  41. reg [3:0] rise_seek;
  42. reg [3:0] rise_measure;
  43. reg [3:0] rise_total;
  44. door_axis_controller #(
  45. .AXIS_ID(0),
  46. .MAX_CAL_STEPS(MAX_CAL),
  47. .MIN_TRAVEL(2),
  48. .ENDPOINT_GUARD_EXTRA(2),
  49. .DIR_SETUP_TICKS(1),
  50. .PERCENT_MAX(100)
  51. ) dut (
  52. .clk(clk), .rst_n(dut_rst_n),
  53. .open_limit(open_limit), .close_limit(close_limit),
  54. .limit_sync_valid(1'b1),
  55. .cal_enable(1'b1),
  56. .gated_step(gated_step), .gated_step_rise(gated_step_rise),
  57. .tick_500us(tick_500us),
  58. .step_toggle_pulse(tick_500us),
  59. .rate_quantum_in(21'd0),
  60. .rate_quantum_valid(1'b0),
  61. .request_valid(1'b0),
  62. .requested_percent_in(8'd0),
  63. .watchdog_stop(1'b0),
  64. .planner_req(planner_req),
  65. .planner_percent(planner_percent),
  66. .planner_travel(planner_travel),
  67. .planner_done(1'b0),
  68. .planner_done_axis(2'd0),
  69. .planner_done_percent(8'd0),
  70. .planner_result(13'd0),
  71. .step(step), .dir_close(dir_close),
  72. .status_state(status_state), .status_flags(status_flags),
  73. .status_requested_percent(status_requested_percent),
  74. .status_current(status_current), .status_target(status_target),
  75. .status_travel(status_travel), .status_fault_code(status_fault_code),
  76. .calibrated(calibrated), .faulted(faulted), .terminal(terminal),
  77. .axis_moving(), .axis_allow_rise(), .axis_in_calibration(), .axis_endpoint_crawl(),
  78. .axis_dda_run(),
  79. .profile_level(), .profile_distance(), .profile_done_steps(), .profile_ramp_unit(),
  80. .rate_quantum()
  81. );
  82. initial begin
  83. reset_cycles = 2'd0;
  84. prev_gated = 1'b0;
  85. rise_seek = 4'd0;
  86. rise_measure = 4'd0;
  87. rise_total = 4'd0;
  88. end
  89. always @(posedge clk) begin
  90. assume (rst_n == 1'b0 || rst_n == 1'b1);
  91. assume (tick_500us == 1'b0 || tick_500us == 1'b1);
  92. assume (open_limit == 1'b0 || open_limit == 1'b1);
  93. assume (close_limit == 1'b0 || close_limit == 1'b1);
  94. assume (force_rise == 1'b0 || force_rise == 1'b1);
  95. assume (!(tick_500us && $past(tick_500us)));
  96. // both-limits path covered by cover only; keep main BMC free of both.
  97. assume (!(open_limit && close_limit));
  98. if ($initstate || reset_cycles < 2) begin
  99. assume (!dut_rst_n);
  100. reset_cycles <= reset_cycles + 1'b1;
  101. end else begin
  102. assume (dut_rst_n);
  103. end
  104. if (!dut_rst_n) begin
  105. prev_gated <= 1'b0;
  106. rise_seek <= 4'd0;
  107. rise_measure <= 4'd0;
  108. rise_total <= 4'd0;
  109. end else begin
  110. prev_gated <= gated_step;
  111. if (gated_step_rise) begin
  112. rise_total <= rise_total + 1'b1;
  113. if (status_state == ST_CAL_SEEK_CLOSE)
  114. rise_seek <= rise_seek + 1'b1;
  115. if (status_state == ST_CAL_MEASURE_OPEN)
  116. rise_measure <= rise_measure + 1'b1;
  117. end
  118. assert (!(calibrated && faulted));
  119. if (terminal)
  120. assert (faulted || calibrated);
  121. // Per-phase budgets: never emit the (MAX+1)-th rise in a phase.
  122. assert (rise_seek <= MAX_CAL[3:0]);
  123. assert (rise_measure <= MAX_CAL[3:0]);
  124. assert (rise_total <= (MAX_CAL * 2));
  125. // Nth rise + target limit same edge → limit success, not timeout fault.
  126. if (status_state == ST_CAL_SEEK_CLOSE && gated_step_rise &&
  127. close_limit && !open_limit && (rise_seek + 1'b1 == MAX_CAL[3:0])) begin
  128. assert (status_fault_code[2:0] != FC_CAL_CLOSE_TIMEOUT);
  129. end
  130. if (status_state == ST_CAL_MEASURE_OPEN && gated_step_rise &&
  131. open_limit && !close_limit && (rise_measure + 1'b1 == MAX_CAL[3:0])) begin
  132. assert (status_fault_code[2:0] != FC_CAL_OPEN_TIMEOUT);
  133. end
  134. // Tiny travel: open_limit completing measure with travel < MIN → fault.
  135. if (faulted && (status_fault_code[2:0] == FC_TINY_TRAVEL))
  136. assert (!calibrated);
  137. // Legal success: calibrated idle with travel in [MIN, MAX].
  138. if (calibrated && !faulted && (status_state == ST_IDLE) && terminal) begin
  139. assert (status_travel >= 13'd2);
  140. assert (status_travel <= MAX_CAL[12:0]);
  141. end
  142. cover (calibrated && terminal && !faulted);
  143. cover (faulted && terminal);
  144. cover (gated_step_rise);
  145. cover (faulted && (status_fault_code[2:0] == FC_TINY_TRAVEL));
  146. cover (status_state == ST_CAL_MEASURE_OPEN && gated_step_rise &&
  147. open_limit && (rise_measure + 1'b1 == MAX_CAL[3:0]));
  148. end
  149. end
  150. endmodule