| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- // Runtime limit hard-stop BMC against REAL door_motor_engine + top-style
- // external STEP truncate gate (mirrors prod2u_p4_normal_v3_top.v).
- //
- // ACTUAL RTL stop semantics (encode as truncate, not finish-high):
- // truncate_current_high_pulse_immediately_after_synchronized_limit
- // Engine clears STEP on the stop_mask sampling edge; top combinationally
- // gates engine_step with the direction-selected synchronized limit so the
- // pin cannot stay high after the target-side limit syncs.
- //
- // Mux shell asserts are retained for static contract string checks.
- module runtime_limit_hard_stop_formal (
- input wire clk,
- input wire rst_n,
- input wire startup_done,
- input wire start,
- input wire [2:0] active_mask,
- input wire [2:0] motor_dir_mask,
- input wire tick_500us,
- input wire abort,
- input wire [2:0] limit_ls_sync,
- input wire [2:0] limit_hs_sync
- );
- localparam integer FORMAL_MAX_STEPS = 4;
- localparam integer FORMAL_DIR_SETUP_TICKS = 1;
- localparam integer AXIS_COUNT = 3;
- // Default compile-time polarity: close_limit=LS, open_limit=HS (active-high).
- wire [2:0] close_limit = limit_ls_sync;
- wire [2:0] open_limit = limit_hs_sync;
- wire [2:0] runtime_limit_stop_mask;
- wire [2:0] selected_limit;
- wire [2:0] gated_step;
- wire busy;
- wire done;
- wire [2:0] engine_step;
- wire [2:0] engine_dir;
- reg [2:0] reset_cycles;
- reg [2:0] prev_gated_step;
- reg past_valid;
- genvar gi;
- generate
- for (gi = 0; gi < AXIS_COUNT; gi = gi + 1) begin : gen_runtime_limit_stop
- // motor_dir_mask / engine_dir are logical: 1=close, 0=open.
- assign runtime_limit_stop_mask[gi] =
- motor_dir_mask[gi] ? close_limit[gi] : open_limit[gi];
- assign selected_limit[gi] =
- engine_dir[gi] ? close_limit[gi] : open_limit[gi];
- end
- endgenerate
- wire [2:0] motor_stop_mask = startup_done ? runtime_limit_stop_mask : 3'b000;
- door_motor_engine #(
- .AXIS_COUNT(AXIS_COUNT),
- .MAX_STEPS(FORMAL_MAX_STEPS),
- .DIR_SETUP_TICKS(FORMAL_DIR_SETUP_TICKS)
- ) u_motor (
- .clk(clk),
- .rst_n(rst_n),
- .start(start && startup_done),
- .active_mask(active_mask),
- .dir_mask(motor_dir_mask),
- .step_count(FORMAL_MAX_STEPS[2:0]),
- .tick_500us(tick_500us),
- .abort(abort),
- .stop_mask(motor_stop_mask),
- .busy(busy),
- .done(done),
- .step(engine_step),
- .dir(engine_dir)
- );
- // Top pin gate: immediate truncate of external STEP on selected logical limit.
- 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];
- // Top permanent enable (FPGA ball constant 1 / permanent_high).
- wire motor_en_n = 1'b1;
- wire [2:0] target_limit_for_engine_dir = selected_limit;
- initial begin
- reset_cycles = 3'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_done == 1'b0 || startup_done == 1'b1);
- assume (start == 1'b0 || start == 1'b1);
- assume (tick_500us == 1'b0 || tick_500us == 1'b1);
- assume (abort == 1'b0 || abort == 1'b1);
- assume ((^motor_dir_mask) == 1'b0 || (^motor_dir_mask) == 1'b1);
- assume ((^active_mask) == 1'b0 || (^active_mask) == 1'b1);
- assume ((^limit_ls_sync) == 1'b0 || (^limit_ls_sync) == 1'b1);
- assume ((^limit_hs_sync) == 1'b0 || (^limit_hs_sync) == 1'b1);
- // Host contract: no new start while busy; dir stable for a run.
- assume (!busy || !start);
- if (busy)
- assume (motor_dir_mask == engine_dir);
- if (!$initstate && $past(rst_n) && $past(startup_done))
- assume (startup_done);
- if ($initstate || reset_cycles < 2) begin
- assume (!rst_n);
- reset_cycles <= reset_cycles + 1'b1;
- past_valid <= 1'b0;
- prev_gated_step <= 3'b000;
- end else begin
- assume (rst_n);
- past_valid <= 1'b1;
- end
- // Mux shell (startup gating of runtime stop mask).
- if (rst_n && startup_done) begin
- assert (motor_stop_mask == runtime_limit_stop_mask);
- end
- if (rst_n && !startup_done) begin
- assert (motor_stop_mask == 3'b000);
- end
- if (rst_n) begin
- // Permanent EN never drops on watchdog / limit paths.
- assert (motor_en_n == 1'b1);
- if (startup_done) begin
- // Target-side synchronized limit => external STEP immediately 0
- // (combinational top gate + engine truncate on stop_mask).
- if (target_limit_for_engine_dir[0])
- assert (gated_step[0] == 1'b0);
- if (target_limit_for_engine_dir[1])
- assert (gated_step[1] == 1'b0);
- if (target_limit_for_engine_dir[2])
- assert (gated_step[2] == 1'b0);
- // Wrong-side limit does not assert stop_mask (leave allowed).
- if (motor_dir_mask[0] && !limit_ls_sync[0])
- assert (motor_stop_mask[0] == 1'b0);
- if (!motor_dir_mask[0] && !limit_hs_sync[0])
- assert (motor_stop_mask[0] == 1'b0);
- if (motor_dir_mask[1] && !limit_ls_sync[1])
- assert (motor_stop_mask[1] == 1'b0);
- if (!motor_dir_mask[1] && !limit_hs_sync[1])
- assert (motor_stop_mask[1] == 1'b0);
- if (motor_dir_mask[2] && !limit_ls_sync[2])
- assert (motor_stop_mask[2] == 1'b0);
- if (!motor_dir_mask[2] && !limit_hs_sync[2])
- assert (motor_stop_mask[2] == 1'b0);
- // Axis independence of stop_mask construction.
- if (!limit_ls_sync[0] && !limit_hs_sync[0])
- assert (motor_stop_mask[0] == 1'b0);
- if (!limit_ls_sync[1] && !limit_hs_sync[1])
- assert (motor_stop_mask[1] == 1'b0);
- if (!limit_ls_sync[2] && !limit_hs_sync[2])
- assert (motor_stop_mask[2] == 1'b0);
- end
- if (past_valid) begin
- // Engine truncate: after stop_mask sampled high, registered STEP is 0.
- if (startup_done && $past(motor_stop_mask[0]) && $past(rst_n))
- assert (engine_step[0] == 1'b0);
- if (startup_done && $past(motor_stop_mask[1]) && $past(rst_n))
- assert (engine_step[1] == 1'b0);
- if (startup_done && $past(motor_stop_mask[2]) && $past(rst_n))
- assert (engine_step[2] == 1'b0);
- // No new rising edge on an axis whose target limit was already high.
- if (startup_done && $past(target_limit_for_engine_dir[0]))
- assert (!( !prev_gated_step[0] && gated_step[0] ));
- if (startup_done && $past(target_limit_for_engine_dir[1]))
- assert (!( !prev_gated_step[1] && gated_step[1] ));
- if (startup_done && $past(target_limit_for_engine_dir[2]))
- assert (!( !prev_gated_step[2] && gated_step[2] ));
- // Watchdog abort: next cycle external STEP low; EN still high.
- if ($past(abort) && $past(rst_n)) begin
- assert (engine_step == 3'b000);
- assert (gated_step == 3'b000);
- assert (motor_en_n == 1'b1);
- end
- end
- prev_gated_step <= gated_step;
- end
- end
- always @(posedge clk) begin
- cover (rst_n && startup_done && limit_ls_sync == 3'b001);
- cover (rst_n && startup_done && limit_hs_sync == 3'b001 && motor_dir_mask == 3'b000);
- cover (rst_n && startup_done && busy && motor_stop_mask[0] && !gated_step[0]);
- cover (rst_n && startup_done && abort);
- cover (rst_n && startup_done && engine_step[1] && motor_stop_mask[0] && !motor_stop_mask[1]);
- end
- endmodule
|