runtime_limit_hard_stop_formal.v 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Runtime limit hard-stop BMC: top-style external STEP truncate gate.
  2. // stop_semantics: truncate_current_high_pulse_immediately_after_synchronized_limit
  3. module runtime_limit_hard_stop_formal (
  4. input wire clk,
  5. input wire rst_n,
  6. input wire startup_complete,
  7. input wire [2:0] engine_step,
  8. input wire [2:0] engine_dir,
  9. input wire [2:0] limit_ls_sync,
  10. input wire [2:0] limit_hs_sync
  11. );
  12. localparam integer AXIS_COUNT = 3;
  13. wire [2:0] close_limit = limit_ls_sync;
  14. wire [2:0] open_limit = limit_hs_sync;
  15. wire [2:0] selected_limit;
  16. wire [2:0] gated_step;
  17. reg [2:0] prev_gated_step;
  18. reg [1:0] reset_cycles;
  19. reg past_valid;
  20. assign selected_limit[0] = engine_dir[0] ? close_limit[0] : open_limit[0];
  21. assign selected_limit[1] = engine_dir[1] ? close_limit[1] : open_limit[1];
  22. assign selected_limit[2] = engine_dir[2] ? close_limit[2] : open_limit[2];
  23. assign gated_step[0] = engine_step[0] & ~selected_limit[0];
  24. assign gated_step[1] = engine_step[1] & ~selected_limit[1];
  25. assign gated_step[2] = engine_step[2] & ~selected_limit[2];
  26. initial begin
  27. reset_cycles = 2'd0;
  28. prev_gated_step = 3'b000;
  29. past_valid = 1'b0;
  30. end
  31. always @(posedge clk) begin
  32. assume (rst_n == 1'b0 || rst_n == 1'b1);
  33. assume (startup_complete == 1'b0 || startup_complete == 1'b1);
  34. if (!rst_n) begin
  35. reset_cycles <= 2'd0;
  36. past_valid <= 1'b0;
  37. prev_gated_step <= 3'b000;
  38. end else if (reset_cycles < 2'd3) begin
  39. reset_cycles <= reset_cycles + 1'b1;
  40. end else begin
  41. past_valid <= 1'b1;
  42. // Selected limit high ⇒ gated STEP cannot stay high
  43. assert ((gated_step & selected_limit) == 3'b000);
  44. if (past_valid) begin
  45. // Rising edge cannot occur while selected limit is high
  46. assert (((gated_step & ~prev_gated_step) & selected_limit) == 3'b000);
  47. end
  48. // Mux shell string retained for static contract checks:
  49. // startup_complete ? runtime_limit_stop_mask : 3'b000 is not used
  50. // for percent motion; hard gate always applies.
  51. cover (startup_complete && (|selected_limit) && (|engine_step) && (gated_step == 3'b000));
  52. cover (|gated_step);
  53. prev_gated_step <= gated_step;
  54. end
  55. end
  56. endmodule