door_axis_motion_contract_formal.v 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // DUT-connected motion safety: DIR stable while STEP high.
  2. // stop_latched is cover-only (drain behavior proved in door_axis_watchdog_drain).
  3. // Bounded BMC with scaled params. Not an unbounded proof.
  4. module door_axis_motion_contract_formal (
  5. input wire clk,
  6. input wire rst_n,
  7. input wire tick_500us,
  8. input wire request_valid,
  9. input wire [7:0] requested_percent_in,
  10. input wire watchdog_stop,
  11. input wire open_limit,
  12. input wire close_limit
  13. );
  14. wire dut_rst_n = rst_n;
  15. wire planner_req;
  16. wire [7:0] planner_percent;
  17. wire [12:0] planner_travel;
  18. reg planner_done;
  19. reg [1:0] planner_done_axis;
  20. reg [7:0] planner_done_percent;
  21. reg [12:0] planner_result;
  22. wire step;
  23. wire dir_close;
  24. wire [2:0] status_state;
  25. wire [7:0] status_flags;
  26. wire [7:0] status_requested_percent;
  27. wire [12:0] status_current;
  28. wire [12:0] status_target;
  29. wire [12:0] status_travel;
  30. wire [7:0] status_fault_code;
  31. wire calibrated;
  32. wire faulted;
  33. wire terminal;
  34. wire gated_step = step & ~((dir_close ? close_limit : open_limit));
  35. reg prev_gated;
  36. wire gated_step_rise = gated_step & ~prev_gated;
  37. reg [1:0] reset_cycles;
  38. reg prev_dir;
  39. reg prev_step;
  40. reg stop_latched;
  41. door_axis_controller #(
  42. .AXIS_ID(0),
  43. .MAX_CAL_STEPS(8),
  44. .MIN_TRAVEL(2),
  45. .ENDPOINT_GUARD_EXTRA(4),
  46. .DIR_SETUP_TICKS(2),
  47. .PERCENT_MAX(100)
  48. ) dut (
  49. .clk(clk), .rst_n(dut_rst_n),
  50. .open_limit(open_limit), .close_limit(close_limit),
  51. .limit_sync_valid(1'b1),
  52. .cal_enable(1'b1),
  53. .gated_step(gated_step), .gated_step_rise(gated_step_rise),
  54. .tick_500us(tick_500us),
  55. .step_toggle_pulse(tick_500us),
  56. .rate_quantum_in(21'd0),
  57. .rate_quantum_valid(1'b0),
  58. .request_valid(request_valid),
  59. .requested_percent_in(requested_percent_in),
  60. .watchdog_stop(watchdog_stop),
  61. .planner_req(planner_req),
  62. .planner_percent(planner_percent),
  63. .planner_travel(planner_travel),
  64. .planner_done(planner_done),
  65. .planner_done_axis(planner_done_axis),
  66. .planner_done_percent(planner_done_percent),
  67. .planner_result(planner_result),
  68. .step(step), .dir_close(dir_close),
  69. .status_state(status_state), .status_flags(status_flags),
  70. .status_requested_percent(status_requested_percent),
  71. .status_current(status_current), .status_target(status_target),
  72. .status_travel(status_travel), .status_fault_code(status_fault_code),
  73. .calibrated(calibrated), .faulted(faulted), .terminal(terminal),
  74. .axis_moving(), .axis_allow_rise(), .axis_in_calibration(), .axis_endpoint_crawl(),
  75. .axis_dda_run(),
  76. .profile_level(), .profile_distance(), .profile_done_steps(), .profile_ramp_unit(),
  77. .rate_quantum()
  78. );
  79. initial begin
  80. reset_cycles = 2'd0;
  81. prev_gated = 1'b0;
  82. prev_dir = 1'b0;
  83. prev_step = 1'b0;
  84. stop_latched = 1'b0;
  85. planner_done = 1'b0;
  86. planner_done_axis = 2'd0;
  87. planner_done_percent = 8'd0;
  88. planner_result = 13'd0;
  89. end
  90. always @(posedge clk) begin
  91. assume (rst_n == 1'b0 || rst_n == 1'b1);
  92. assume (tick_500us == 1'b0 || tick_500us == 1'b1);
  93. assume (request_valid == 1'b0 || request_valid == 1'b1);
  94. assume (watchdog_stop == 1'b0 || watchdog_stop == 1'b1);
  95. assume (open_limit == 1'b0 || open_limit == 1'b1);
  96. assume (close_limit == 1'b0 || close_limit == 1'b1);
  97. assume (requested_percent_in <= 8'd100);
  98. assume (!(tick_500us && $past(tick_500us)));
  99. assume (!(open_limit && close_limit));
  100. if ($initstate || reset_cycles < 2) begin
  101. assume (!dut_rst_n);
  102. reset_cycles <= reset_cycles + 1'b1;
  103. end else begin
  104. assume (dut_rst_n);
  105. end
  106. planner_done <= 1'b0;
  107. if (planner_req) begin
  108. planner_done <= 1'b1;
  109. planner_done_axis <= 2'd0;
  110. planner_done_percent <= planner_percent;
  111. planner_result <= 13'd2;
  112. end
  113. if (!dut_rst_n) begin
  114. prev_gated <= 1'b0;
  115. prev_dir <= 1'b0;
  116. prev_step <= 1'b0;
  117. stop_latched <= 1'b0;
  118. end else begin
  119. prev_gated <= gated_step;
  120. // Only latch stop when DUT can accept watchdog.
  121. if (watchdog_stop && !request_valid && calibrated && !faulted)
  122. stop_latched <= 1'b1;
  123. if (request_valid)
  124. stop_latched <= 1'b0;
  125. // DIR must not toggle while STEP is high (runtime / cal moving).
  126. // Exclude the first cycle after reset release.
  127. if (prev_step && calibrated)
  128. assert (dir_close == prev_dir);
  129. cover (prev_step && (dir_close == prev_dir) && calibrated);
  130. cover (stop_latched && (step == 1'b0) && watchdog_stop);
  131. prev_dir <= dir_close;
  132. prev_step <= step;
  133. end
  134. end
  135. endmodule