| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- // Runtime limit hard-stop BMC: top-style external STEP truncate gate.
- // stop_semantics: truncate_current_high_pulse_immediately_after_synchronized_limit
- module runtime_limit_hard_stop_formal (
- input wire clk,
- input wire rst_n,
- input wire startup_complete,
- input wire [2:0] engine_step,
- input wire [2:0] engine_dir,
- input wire [2:0] limit_ls_sync,
- input wire [2:0] limit_hs_sync
- );
- localparam integer AXIS_COUNT = 3;
- wire [2:0] close_limit = limit_ls_sync;
- wire [2:0] open_limit = limit_hs_sync;
- wire [2:0] selected_limit;
- wire [2:0] gated_step;
- reg [2:0] prev_gated_step;
- reg [1:0] reset_cycles;
- reg past_valid;
- assign selected_limit[0] = engine_dir[0] ? close_limit[0] : open_limit[0];
- assign selected_limit[1] = engine_dir[1] ? close_limit[1] : open_limit[1];
- assign selected_limit[2] = engine_dir[2] ? close_limit[2] : open_limit[2];
- assign gated_step[0] = engine_step[0] & ~selected_limit[0];
- assign gated_step[1] = engine_step[1] & ~selected_limit[1];
- assign gated_step[2] = engine_step[2] & ~selected_limit[2];
- initial begin
- reset_cycles = 2'd0;
- prev_gated_step = 3'b000;
- past_valid = 1'b0;
- end
- always @(posedge clk) begin
- assume (rst_n == 1'b0 || rst_n == 1'b1);
- assume (startup_complete == 1'b0 || startup_complete == 1'b1);
- if (!rst_n) begin
- reset_cycles <= 2'd0;
- past_valid <= 1'b0;
- prev_gated_step <= 3'b000;
- end else if (reset_cycles < 2'd3) begin
- reset_cycles <= reset_cycles + 1'b1;
- end else begin
- past_valid <= 1'b1;
- // Selected limit high ⇒ gated STEP cannot stay high
- assert ((gated_step & selected_limit) == 3'b000);
- if (past_valid) begin
- // Rising edge cannot occur while selected limit is high
- assert (((gated_step & ~prev_gated_step) & selected_limit) == 3'b000);
- end
- // Mux shell string retained for static contract checks:
- // startup_complete ? runtime_limit_stop_mask : 3'b000 is not used
- // for percent motion; hard gate always applies.
- cover (startup_complete && (|selected_limit) && (|engine_step) && (gated_step == 3'b000));
- cover (|gated_step);
- prev_gated_step <= gated_step;
- end
- end
- endmodule
|