runtime_limit_hard_stop_formal.v 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. // Default compile-time polarity: close_limit=LS, open_limit=HS (active-high).
  27. wire [2:0] close_limit = limit_ls_sync;
  28. wire [2:0] open_limit = limit_hs_sync;
  29. wire [2:0] runtime_limit_stop_mask;
  30. wire [2:0] selected_limit;
  31. wire [2:0] gated_step;
  32. wire busy;
  33. wire done;
  34. wire [2:0] engine_step;
  35. wire [2:0] engine_dir;
  36. reg [2:0] reset_cycles;
  37. reg [2:0] prev_gated_step;
  38. reg past_valid;
  39. genvar gi;
  40. generate
  41. for (gi = 0; gi < AXIS_COUNT; gi = gi + 1) begin : gen_runtime_limit_stop
  42. // motor_dir_mask / engine_dir are logical: 1=close, 0=open.
  43. assign runtime_limit_stop_mask[gi] =
  44. motor_dir_mask[gi] ? close_limit[gi] : open_limit[gi];
  45. assign selected_limit[gi] =
  46. engine_dir[gi] ? close_limit[gi] : open_limit[gi];
  47. end
  48. endgenerate
  49. wire [2:0] motor_stop_mask = startup_done ? runtime_limit_stop_mask : 3'b000;
  50. door_motor_engine #(
  51. .AXIS_COUNT(AXIS_COUNT),
  52. .MAX_STEPS(FORMAL_MAX_STEPS),
  53. .DIR_SETUP_TICKS(FORMAL_DIR_SETUP_TICKS)
  54. ) u_motor (
  55. .clk(clk),
  56. .rst_n(rst_n),
  57. .start(start && startup_done),
  58. .active_mask(active_mask),
  59. .dir_mask(motor_dir_mask),
  60. .step_count(FORMAL_MAX_STEPS[2:0]),
  61. .tick_500us(tick_500us),
  62. .abort(abort),
  63. .stop_mask(motor_stop_mask),
  64. .busy(busy),
  65. .done(done),
  66. .step(engine_step),
  67. .dir(engine_dir)
  68. );
  69. // Top pin gate: immediate truncate of external STEP on selected logical limit.
  70. assign gated_step[0] = engine_step[0] & ~selected_limit[0];
  71. assign gated_step[1] = engine_step[1] & ~selected_limit[1];
  72. assign gated_step[2] = engine_step[2] & ~selected_limit[2];
  73. // Top permanent enable (FPGA ball constant 1 / permanent_high).
  74. wire motor_en_n = 1'b1;
  75. wire [2:0] target_limit_for_engine_dir = selected_limit;
  76. initial begin
  77. reset_cycles = 3'd0;
  78. prev_gated_step = 3'b000;
  79. past_valid = 1'b0;
  80. end
  81. always @(posedge clk) begin
  82. assume (rst_n == 1'b0 || rst_n == 1'b1);
  83. assume (startup_done == 1'b0 || startup_done == 1'b1);
  84. assume (start == 1'b0 || start == 1'b1);
  85. assume (tick_500us == 1'b0 || tick_500us == 1'b1);
  86. assume (abort == 1'b0 || abort == 1'b1);
  87. assume ((^motor_dir_mask) == 1'b0 || (^motor_dir_mask) == 1'b1);
  88. assume ((^active_mask) == 1'b0 || (^active_mask) == 1'b1);
  89. assume ((^limit_ls_sync) == 1'b0 || (^limit_ls_sync) == 1'b1);
  90. assume ((^limit_hs_sync) == 1'b0 || (^limit_hs_sync) == 1'b1);
  91. // Host contract: no new start while busy; dir stable for a run.
  92. assume (!busy || !start);
  93. if (busy)
  94. assume (motor_dir_mask == engine_dir);
  95. if (!$initstate && $past(rst_n) && $past(startup_done))
  96. assume (startup_done);
  97. if ($initstate || reset_cycles < 2) begin
  98. assume (!rst_n);
  99. reset_cycles <= reset_cycles + 1'b1;
  100. past_valid <= 1'b0;
  101. prev_gated_step <= 3'b000;
  102. end else begin
  103. assume (rst_n);
  104. past_valid <= 1'b1;
  105. end
  106. // Mux shell (startup gating of runtime stop mask).
  107. if (rst_n && startup_done) begin
  108. assert (motor_stop_mask == runtime_limit_stop_mask);
  109. end
  110. if (rst_n && !startup_done) begin
  111. assert (motor_stop_mask == 3'b000);
  112. end
  113. if (rst_n) begin
  114. // Permanent EN never drops on watchdog / limit paths.
  115. assert (motor_en_n == 1'b1);
  116. if (startup_done) begin
  117. // Target-side synchronized limit => external STEP immediately 0
  118. // (combinational top gate + engine truncate on stop_mask).
  119. if (target_limit_for_engine_dir[0])
  120. assert (gated_step[0] == 1'b0);
  121. if (target_limit_for_engine_dir[1])
  122. assert (gated_step[1] == 1'b0);
  123. if (target_limit_for_engine_dir[2])
  124. assert (gated_step[2] == 1'b0);
  125. // Wrong-side limit does not assert stop_mask (leave allowed).
  126. if (motor_dir_mask[0] && !limit_ls_sync[0])
  127. assert (motor_stop_mask[0] == 1'b0);
  128. if (!motor_dir_mask[0] && !limit_hs_sync[0])
  129. assert (motor_stop_mask[0] == 1'b0);
  130. if (motor_dir_mask[1] && !limit_ls_sync[1])
  131. assert (motor_stop_mask[1] == 1'b0);
  132. if (!motor_dir_mask[1] && !limit_hs_sync[1])
  133. assert (motor_stop_mask[1] == 1'b0);
  134. if (motor_dir_mask[2] && !limit_ls_sync[2])
  135. assert (motor_stop_mask[2] == 1'b0);
  136. if (!motor_dir_mask[2] && !limit_hs_sync[2])
  137. assert (motor_stop_mask[2] == 1'b0);
  138. // Axis independence of stop_mask construction.
  139. if (!limit_ls_sync[0] && !limit_hs_sync[0])
  140. assert (motor_stop_mask[0] == 1'b0);
  141. if (!limit_ls_sync[1] && !limit_hs_sync[1])
  142. assert (motor_stop_mask[1] == 1'b0);
  143. if (!limit_ls_sync[2] && !limit_hs_sync[2])
  144. assert (motor_stop_mask[2] == 1'b0);
  145. end
  146. if (past_valid) begin
  147. // Engine truncate: after stop_mask sampled high, registered STEP is 0.
  148. if (startup_done && $past(motor_stop_mask[0]) && $past(rst_n))
  149. assert (engine_step[0] == 1'b0);
  150. if (startup_done && $past(motor_stop_mask[1]) && $past(rst_n))
  151. assert (engine_step[1] == 1'b0);
  152. if (startup_done && $past(motor_stop_mask[2]) && $past(rst_n))
  153. assert (engine_step[2] == 1'b0);
  154. // No new rising edge on an axis whose target limit was already high.
  155. if (startup_done && $past(target_limit_for_engine_dir[0]))
  156. assert (!( !prev_gated_step[0] && gated_step[0] ));
  157. if (startup_done && $past(target_limit_for_engine_dir[1]))
  158. assert (!( !prev_gated_step[1] && gated_step[1] ));
  159. if (startup_done && $past(target_limit_for_engine_dir[2]))
  160. assert (!( !prev_gated_step[2] && gated_step[2] ));
  161. // Watchdog abort: next cycle external STEP low; EN still high.
  162. if ($past(abort) && $past(rst_n)) begin
  163. assert (engine_step == 3'b000);
  164. assert (gated_step == 3'b000);
  165. assert (motor_en_n == 1'b1);
  166. end
  167. end
  168. prev_gated_step <= gated_step;
  169. end
  170. end
  171. always @(posedge clk) begin
  172. cover (rst_n && startup_done && limit_ls_sync == 3'b001);
  173. cover (rst_n && startup_done && limit_hs_sync == 3'b001 && motor_dir_mask == 3'b000);
  174. cover (rst_n && startup_done && busy && motor_stop_mask[0] && !gated_step[0]);
  175. cover (rst_n && startup_done && abort);
  176. cover (rst_n && startup_done && engine_step[1] && motor_stop_mask[0] && !motor_stop_mask[1]);
  177. end
  178. endmodule