runtime_limit_hard_stop_formal.v 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // Runtime limit hard-stop BMC against REAL door_motor_engine + top-style
  2. // external STEP truncate gate (mirrors prod2u_p4_normal_v3_top.v).
  3. //
  4. // ACTUAL RTL stop semantics (encode as truncate, not finish-high):
  5. // truncate_current_high_pulse_immediately_after_synchronized_limit
  6. // Engine clears STEP on the stop_mask sampling edge; top combinationally
  7. // gates engine_step with the direction-selected synchronized limit so the
  8. // pin cannot stay high after the target-side limit syncs.
  9. //
  10. // Mux shell asserts are retained for static contract string checks.
  11. module runtime_limit_hard_stop_formal (
  12. input wire clk,
  13. input wire rst_n,
  14. input wire startup_done,
  15. input wire start,
  16. input wire [2:0] active_mask,
  17. input wire [2:0] motor_dir_mask,
  18. input wire tick_500us,
  19. input wire abort,
  20. input wire [2:0] limit_ls_sync,
  21. input wire [2:0] limit_hs_sync
  22. );
  23. localparam integer FORMAL_MAX_STEPS = 4;
  24. localparam integer FORMAL_DIR_SETUP_TICKS = 1;
  25. localparam integer AXIS_COUNT = 3;
  26. wire [2:0] runtime_limit_stop_mask;
  27. reg [2:0] reset_cycles;
  28. reg [2:0] prev_gated_step;
  29. reg past_valid;
  30. genvar gi;
  31. generate
  32. for (gi = 0; gi < AXIS_COUNT; gi = gi + 1) begin : gen_runtime_limit_stop
  33. assign runtime_limit_stop_mask[gi] =
  34. motor_dir_mask[gi] ? limit_ls_sync[gi] : limit_hs_sync[gi];
  35. end
  36. endgenerate
  37. wire [2:0] motor_stop_mask = startup_done ? runtime_limit_stop_mask : 3'b000;
  38. wire busy;
  39. wire done;
  40. wire [2:0] engine_step;
  41. wire [2:0] engine_dir;
  42. door_motor_engine #(
  43. .AXIS_COUNT(AXIS_COUNT),
  44. .MAX_STEPS(FORMAL_MAX_STEPS),
  45. .DIR_SETUP_TICKS(FORMAL_DIR_SETUP_TICKS)
  46. ) u_motor (
  47. .clk(clk),
  48. .rst_n(rst_n),
  49. .start(start && startup_done),
  50. .active_mask(active_mask),
  51. .dir_mask(motor_dir_mask),
  52. .step_count(FORMAL_MAX_STEPS[2:0]),
  53. .tick_500us(tick_500us),
  54. .abort(abort),
  55. .stop_mask(motor_stop_mask),
  56. .busy(busy),
  57. .done(done),
  58. .step(engine_step),
  59. .dir(engine_dir)
  60. );
  61. // Top pin gate: immediate truncate of external STEP on target-side sync.
  62. wire [2:0] gated_step;
  63. assign gated_step[0] = engine_step[0] &
  64. ~(engine_dir[0] ? limit_ls_sync[0] : limit_hs_sync[0]);
  65. assign gated_step[1] = engine_step[1] &
  66. ~(engine_dir[1] ? limit_ls_sync[1] : limit_hs_sync[1]);
  67. assign gated_step[2] = engine_step[2] &
  68. ~(engine_dir[2] ? limit_ls_sync[2] : limit_hs_sync[2]);
  69. // Top permanent enable (FPGA ball constant 1 / permanent_high).
  70. wire motor_en_n = 1'b1;
  71. wire [2:0] target_limit_for_engine_dir;
  72. assign target_limit_for_engine_dir[0] =
  73. engine_dir[0] ? limit_ls_sync[0] : limit_hs_sync[0];
  74. assign target_limit_for_engine_dir[1] =
  75. engine_dir[1] ? limit_ls_sync[1] : limit_hs_sync[1];
  76. assign target_limit_for_engine_dir[2] =
  77. engine_dir[2] ? limit_ls_sync[2] : limit_hs_sync[2];
  78. initial begin
  79. reset_cycles = 3'd0;
  80. prev_gated_step = 3'b000;
  81. past_valid = 1'b0;
  82. end
  83. always @(posedge clk) begin
  84. assume (rst_n == 1'b0 || rst_n == 1'b1);
  85. assume (startup_done == 1'b0 || startup_done == 1'b1);
  86. assume (start == 1'b0 || start == 1'b1);
  87. assume (tick_500us == 1'b0 || tick_500us == 1'b1);
  88. assume (abort == 1'b0 || abort == 1'b1);
  89. assume ((^motor_dir_mask) == 1'b0 || (^motor_dir_mask) == 1'b1);
  90. assume ((^active_mask) == 1'b0 || (^active_mask) == 1'b1);
  91. assume ((^limit_ls_sync) == 1'b0 || (^limit_ls_sync) == 1'b1);
  92. assume ((^limit_hs_sync) == 1'b0 || (^limit_hs_sync) == 1'b1);
  93. // Host contract: no new start while busy; dir stable for a run.
  94. assume (!busy || !start);
  95. if (busy)
  96. assume (motor_dir_mask == engine_dir);
  97. if (!$initstate && $past(rst_n) && $past(startup_done))
  98. assume (startup_done);
  99. if ($initstate || reset_cycles < 2) begin
  100. assume (!rst_n);
  101. reset_cycles <= reset_cycles + 1'b1;
  102. past_valid <= 1'b0;
  103. prev_gated_step <= 3'b000;
  104. end else begin
  105. assume (rst_n);
  106. past_valid <= 1'b1;
  107. end
  108. // Mux shell (startup gating of runtime stop mask).
  109. if (rst_n && startup_done) begin
  110. assert (motor_stop_mask == runtime_limit_stop_mask);
  111. end
  112. if (rst_n && !startup_done) begin
  113. assert (motor_stop_mask == 3'b000);
  114. end
  115. if (rst_n) begin
  116. // Permanent EN never drops on watchdog / limit paths.
  117. assert (motor_en_n == 1'b1);
  118. if (startup_done) begin
  119. // Target-side synchronized limit => external STEP immediately 0
  120. // (combinational top gate + engine truncate on stop_mask).
  121. if (target_limit_for_engine_dir[0])
  122. assert (gated_step[0] == 1'b0);
  123. if (target_limit_for_engine_dir[1])
  124. assert (gated_step[1] == 1'b0);
  125. if (target_limit_for_engine_dir[2])
  126. assert (gated_step[2] == 1'b0);
  127. // Wrong-side limit does not assert stop_mask (leave allowed).
  128. if (motor_dir_mask[0] && !limit_ls_sync[0])
  129. assert (motor_stop_mask[0] == 1'b0);
  130. if (!motor_dir_mask[0] && !limit_hs_sync[0])
  131. assert (motor_stop_mask[0] == 1'b0);
  132. if (motor_dir_mask[1] && !limit_ls_sync[1])
  133. assert (motor_stop_mask[1] == 1'b0);
  134. if (!motor_dir_mask[1] && !limit_hs_sync[1])
  135. assert (motor_stop_mask[1] == 1'b0);
  136. if (motor_dir_mask[2] && !limit_ls_sync[2])
  137. assert (motor_stop_mask[2] == 1'b0);
  138. if (!motor_dir_mask[2] && !limit_hs_sync[2])
  139. assert (motor_stop_mask[2] == 1'b0);
  140. // Axis independence of stop_mask construction.
  141. if (!limit_ls_sync[0] && !limit_hs_sync[0])
  142. assert (motor_stop_mask[0] == 1'b0);
  143. if (!limit_ls_sync[1] && !limit_hs_sync[1])
  144. assert (motor_stop_mask[1] == 1'b0);
  145. if (!limit_ls_sync[2] && !limit_hs_sync[2])
  146. assert (motor_stop_mask[2] == 1'b0);
  147. end
  148. if (past_valid) begin
  149. // Engine truncate: after stop_mask sampled high, registered STEP is 0.
  150. if (startup_done && $past(motor_stop_mask[0]) && $past(rst_n))
  151. assert (engine_step[0] == 1'b0);
  152. if (startup_done && $past(motor_stop_mask[1]) && $past(rst_n))
  153. assert (engine_step[1] == 1'b0);
  154. if (startup_done && $past(motor_stop_mask[2]) && $past(rst_n))
  155. assert (engine_step[2] == 1'b0);
  156. // No new rising edge on an axis whose target limit was already high.
  157. if (startup_done && $past(target_limit_for_engine_dir[0]))
  158. assert (!( !prev_gated_step[0] && gated_step[0] ));
  159. if (startup_done && $past(target_limit_for_engine_dir[1]))
  160. assert (!( !prev_gated_step[1] && gated_step[1] ));
  161. if (startup_done && $past(target_limit_for_engine_dir[2]))
  162. assert (!( !prev_gated_step[2] && gated_step[2] ));
  163. // Watchdog abort: next cycle external STEP low; EN still high.
  164. if ($past(abort) && $past(rst_n)) begin
  165. assert (engine_step == 3'b000);
  166. assert (gated_step == 3'b000);
  167. assert (motor_en_n == 1'b1);
  168. end
  169. end
  170. prev_gated_step <= gated_step;
  171. end
  172. end
  173. always @(posedge clk) begin
  174. cover (rst_n && startup_done && limit_ls_sync == 3'b001);
  175. cover (rst_n && startup_done && limit_hs_sync == 3'b001 && motor_dir_mask == 3'b000);
  176. cover (rst_n && startup_done && busy && motor_stop_mask[0] && !gated_step[0]);
  177. cover (rst_n && startup_done && abort);
  178. cover (rst_n && startup_done && engine_step[1] && motor_stop_mask[0] && !motor_stop_mask[1]);
  179. end
  180. endmodule