Quellcode durchsuchen

test(prod2u): prove real engine/top truncate limit stop paths

Strengthen runtime and startup formal BMC against door_motor_engine plus
top-style STEP gating, encode ACTUAL RTL truncate semantics in Icarus, and
record Lane C formal/sim pointer receipts.

Co-authored-by: Cursor <cursoragent@cursor.com>
root vor 3 Monaten
Ursprung
Commit
67b41e88ce

+ 35 - 0
receipts/prod2u_lane_c_formal_20260806T022109Z.json

@@ -0,0 +1,35 @@
+{
+  "schema": "prod2u-lane-c-formal-pointer-receipt-v1",
+  "status": "pass",
+  "lane": "closure/lane-c-formal-sim",
+  "base_commit": "cdf9f76b22d75f1c2bc1e7ff99a49d2897a8dcb7",
+  "run_id": "lane-c-formal-20260806T021920Z",
+  "stop_semantics_encoded": "truncate_current_high_pulse_immediately_after_synchronized_limit",
+  "mode_honesty": "BMC depth 48 + cover; not unbounded prove",
+  "targets": {
+    "runtime_limit_hard_stop": {
+      "tasks": [
+        "bmc",
+        "cover"
+      ],
+      "status": "pass",
+      "engine": "smtbmc z3",
+      "assertion_count": 24,
+      "cover_hits": 5
+    },
+    "startup_close_seek": {
+      "tasks": [
+        "bmc",
+        "cover"
+      ],
+      "status": "pass",
+      "engine": "smtbmc z3",
+      "assertion_count": 19,
+      "cover_hits": 5
+    }
+  },
+  "full_receipt": "/root/.local/state/prod2u/runs/lane-c-formal-20260806T021920Z/builds/formal-aecfa202/formal-receipt.json",
+  "full_receipt_sha256": "fa65f0e4e6d8918439f4191f7752e46beb9bab2b56aa59d42dd22ad17d876b48",
+  "matrix_report": "/root/.local/state/prod2u/runs/lane-c-formal-20260806T021920Z/receipts/verification-matrix.json",
+  "matrix_report_sha256": "6da082141d6f6577904506f95fe1124e805a329651ec343c0e1c3e78833f1cab"
+}

+ 20 - 0
receipts/prod2u_lane_c_icarus_20260806T022109Z.json

@@ -0,0 +1,20 @@
+{
+  "schema": "prod2u-lane-c-icarus-pointer-receipt-v1",
+  "status": "pass",
+  "lane": "closure/lane-c-formal-sim",
+  "base_commit": "cdf9f76b22d75f1c2bc1e7ff99a49d2897a8dcb7",
+  "run_id": "lane-c-icarus-20260806T021915Z",
+  "stop_semantics_encoded": "truncate_current_high_pulse_immediately_after_synchronized_limit",
+  "focused_benches": [
+    "door_motor_engine_stop_tb",
+    "prod2u_p4_normal_v3_top_runtime_limit_tb",
+    "startup_close_seek_tb",
+    "startup_motor_stop_tb",
+    "prod2u_p4_normal_v3_top_startup_tb"
+  ],
+  "full_lane_tests": 22,
+  "full_receipt": "/root/.local/state/prod2u/runs/lane-c-icarus-20260806T021915Z/builds/icarus-aecca202/icarus-receipt.json",
+  "full_receipt_sha256": "163bbe12fceb019ede003cb656c80dab6a068145a02e34e6a073b5a869bbd62b",
+  "matrix_report": "/root/.local/state/prod2u/runs/lane-c-icarus-20260806T021915Z/receipts/verification-matrix.json",
+  "matrix_report_sha256": "55fbda191e1be44f23e7a5a08f269292c7af5f609465c68e633be83cdd04a637"
+}

+ 7 - 2
tests/formal/README.md

@@ -12,8 +12,8 @@ SymbiYosys task names match the configured mode. Do **not** treat a task named
 | `frame_command_contract` | `bmc` | BMC (depth 96; wrapper has cover() but no cover task — low-mem) |
 | `frame_tx_contract` | `bmc` | BMC (depth 64) |
 | `simple_frame_contract` | `bmc`, `cover` | BMC + cover (cover depth 32) |
-| `startup_close_seek` | `bmc`, `cover` | BMC + cover |
-| `runtime_limit_hard_stop` | `bmc`, `cover` | BMC + cover (DIR→LS/HS mux) |
+| `startup_close_seek` | `bmc`, `cover` | BMC + cover (real engine + top STEP truncate gate) |
+| `runtime_limit_hard_stop` | `bmc`, `cover` | BMC + cover (real engine + top STEP truncate gate; DIR→LS/HS mux) |
 | `door_action_dispatcher_axis3` | `bmc`, `cover` | BMC + cover (3-axis Z/X/Y) |
 | `output_target_ram_contract` | `prove` | prove |
 | `simple_motor_temperature_contract` | `prove`, `cover` | prove + cover |
@@ -26,6 +26,11 @@ and accepted-byte no-duplicate progression through the early frame stream. Full
 33-byte completion is outside this bounded proof and remains covered by the RTL
 simulation benches.
 
+Lane C stop semantics in formal/sim encode the **ACTUAL RTL** behavior
+`truncate_current_high_pulse_immediately_after_synchronized_limit` (engine clears
+STEP on the stop_mask edge; top combinationally gates the pin). Do not assert
+finish-high pulse completion against these wrappers.
+
 They are offline checks. A solver error, timeout, unknown status, missing
 compiled-property evidence, or unhit required cover is not a pass. Receipts must
 record mode, depth, solver, and cover hits; BMC must never be reported as

+ 2 - 0
tests/formal/runtime_limit_hard_stop.sby

@@ -12,10 +12,12 @@ cover: depth 32
 smtbmc z3
 
 [script]
+read_verilog -formal door_motor_engine.v
 read_verilog -formal runtime_limit_hard_stop_formal.v
 proc
 setundef -zero
 prep -top runtime_limit_hard_stop_formal
 
 [files]
+../../src/modules/door_motor_engine.v
 runtime_limit_hard_stop_formal.v

+ 152 - 3
tests/formal/runtime_limit_hard_stop_formal.v

@@ -1,18 +1,37 @@
-// Runtime limit hard-stop mux: DIR=1 -> LS, DIR=0 -> HS; active only after startup_done.
+// 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;
+
     wire [2:0] runtime_limit_stop_mask;
     reg [2:0] reset_cycles;
+    reg [2:0] prev_gated_step;
+    reg past_valid;
 
     genvar gi;
     generate
-        for (gi = 0; gi < 3; gi = gi + 1) begin : gen_runtime_limit_stop
+        for (gi = 0; gi < AXIS_COUNT; gi = gi + 1) begin : gen_runtime_limit_stop
             assign runtime_limit_stop_mask[gi] =
                 motor_dir_mask[gi] ? limit_ls_sync[gi] : limit_hs_sync[gi];
         end
@@ -20,33 +39,163 @@ module runtime_limit_hard_stop_formal (
 
     wire [2:0] motor_stop_mask = startup_done ? runtime_limit_stop_mask : 3'b000;
 
-    initial reset_cycles = 3'd0;
+    wire busy;
+    wire done;
+    wire [2:0] engine_step;
+    wire [2:0] engine_dir;
+
+    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 target-side sync.
+    wire [2:0] gated_step;
+    assign gated_step[0] = engine_step[0] &
+        ~(engine_dir[0] ? limit_ls_sync[0] : limit_hs_sync[0]);
+    assign gated_step[1] = engine_step[1] &
+        ~(engine_dir[1] ? limit_ls_sync[1] : limit_hs_sync[1]);
+    assign gated_step[2] = engine_step[2] &
+        ~(engine_dir[2] ? limit_ls_sync[2] : limit_hs_sync[2]);
+
+    // Top permanent enable (FPGA ball constant 1 / permanent_high).
+    wire motor_en_n = 1'b1;
+
+    wire [2:0] target_limit_for_engine_dir;
+    assign target_limit_for_engine_dir[0] =
+        engine_dir[0] ? limit_ls_sync[0] : limit_hs_sync[0];
+    assign target_limit_for_engine_dir[1] =
+        engine_dir[1] ? limit_ls_sync[1] : limit_hs_sync[1];
+    assign target_limit_for_engine_dir[2] =
+        engine_dir[2] ? limit_ls_sync[2] : limit_hs_sync[2];
+
+    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

+ 3 - 1
tests/formal/startup_close_seek.sby

@@ -6,13 +6,14 @@ cover
 bmc: mode bmc
 bmc: depth 48
 cover: mode cover
-cover: depth 32
+cover: depth 40
 
 [engines]
 smtbmc z3
 
 [script]
 read_verilog -formal startup_close_seek.v
+read_verilog -formal door_motor_engine.v
 read_verilog -formal startup_close_seek_formal.v
 proc
 setundef -zero
@@ -20,4 +21,5 @@ prep -top startup_close_seek_formal
 
 [files]
 ../../src/modules/startup_close_seek.v
+../../src/modules/door_motor_engine.v
 startup_close_seek_formal.v

+ 135 - 24
tests/formal/startup_close_seek_formal.v

@@ -1,3 +1,6 @@
+// Startup close/seek BMC with REAL door_motor_engine + top-style STEP truncate
+// gate. Stop semantics modeled as ACTUAL RTL truncate (not finish-high):
+//   truncate_current_high_pulse_immediately_after_synchronized_limit
 module startup_close_seek_formal (
     input wire clk,
     input wire rst_n,
@@ -18,11 +21,20 @@ module startup_close_seek_formal (
     wire [AXIS_COUNT-1:0] motor_stop_mask;
     wire [2:0] motor_step_count;
     wire motor_done;
+    wire motor_busy;
+    wire [AXIS_COUNT-1:0] engine_step;
+    wire [AXIS_COUNT-1:0] engine_dir;
 
     reg [2:0] reset_cycles;
-    reg [3:0] start_counter;
-    reg motor_busy;
     reg formal_sync_valid;
+    reg saw_ls_low;
+    reg [AXIS_COUNT-1:0] prev_gated_step;
+    reg past_valid;
+    reg [3:0] backoff_rising_x;
+    reg in_backoff;
+    reg close_phase;
+    reg found_ls_frozen;
+    reg [AXIS_COUNT-1:0] shadow_found_ls;
 
     always @(posedge clk or negedge rst_n) begin
         if (!rst_n) begin
@@ -55,43 +67,106 @@ module startup_close_seek_formal (
         .motor_done(motor_done)
     );
 
-    reg [3:0] motor_count;
-    always @(posedge clk or negedge rst_n) begin
-        if (!rst_n) begin
-            motor_busy <= 1'b0;
-            motor_count <= 4'd0;
-            start_counter <= 4'd0;
-        end else begin
-            if (motor_start) start_counter <= start_counter + 1'b1;
-            if (motor_start && !motor_busy) begin
-                motor_busy <= 1'b1;
-                motor_count <= 4'd0;
-            end else if (motor_busy) begin
-                if (motor_count < FORMAL_CLOSE_STEPS + FORMAL_DIR_SETUP_TICKS) begin
-                    motor_count <= motor_count + 1'b1;
-                end else begin
-                    motor_busy <= 1'b0;
-                end
-            end
-        end
-    end
-    assign motor_done = motor_busy && (motor_count == FORMAL_CLOSE_STEPS + FORMAL_DIR_SETUP_TICKS);
+    door_motor_engine #(
+        .AXIS_COUNT(AXIS_COUNT),
+        .MAX_STEPS(FORMAL_CLOSE_STEPS),
+        .DIR_SETUP_TICKS(FORMAL_DIR_SETUP_TICKS)
+    ) u_motor (
+        .clk(clk),
+        .rst_n(rst_n),
+        .start(motor_start),
+        .active_mask(motor_active_mask),
+        .dir_mask(motor_dir_mask),
+        .step_count(motor_step_count),
+        .tick_500us(tick_500us),
+        .abort(1'b0),
+        .stop_mask(motor_stop_mask),
+        .busy(motor_busy),
+        .done(motor_done),
+        .step(engine_step),
+        .dir(engine_dir)
+    );
+
+    // Top-style external STEP truncate gate (dir-select LS/HS).
+    wire [AXIS_COUNT-1:0] gated_step;
+    assign gated_step[0] = engine_step[0] &
+        ~(engine_dir[0] ? limit_ls_sync[0] : limit_hs_sync[0]);
+    assign gated_step[1] = engine_step[1] &
+        ~(engine_dir[1] ? limit_ls_sync[1] : limit_hs_sync[1]);
+    assign gated_step[2] = engine_step[2] &
+        ~(engine_dir[2] ? limit_ls_sync[2] : limit_hs_sync[2]);
 
-    initial reset_cycles = 3'd0;
+    wire motor_en_n = 1'b1;
+
+    initial begin
+        reset_cycles = 3'd0;
+        saw_ls_low = 1'b0;
+        prev_gated_step = 3'b000;
+        past_valid = 1'b0;
+        backoff_rising_x = 4'd0;
+        in_backoff = 1'b0;
+        close_phase = 1'b0;
+        found_ls_frozen = 1'b0;
+        shadow_found_ls = 3'b000;
+    end
 
     always @(posedge clk) begin
         assume (rst_n == 1'b0 || rst_n == 1'b1);
         assume (tick_500us == 1'b0 || tick_500us == 1'b1);
         assume ((^limit_ls_sync) == 1'b0 || (^limit_ls_sync) == 1'b1);
         assume ((^limit_hs_sync) == 1'b0 || (^limit_hs_sync) == 1'b1);
+
         if ($initstate || reset_cycles < 3) begin
             assume (!rst_n);
             reset_cycles <= reset_cycles + 1'b1;
+            past_valid <= 1'b0;
+            saw_ls_low <= 1'b0;
+            prev_gated_step <= 3'b000;
+            backoff_rising_x <= 4'd0;
+            in_backoff <= 1'b0;
+            close_phase <= 1'b0;
+            found_ls_frozen <= 1'b0;
+            shadow_found_ls <= 3'b000;
         end else begin
             assume (rst_n);
+            past_valid <= 1'b1;
         end
 
         if (rst_n) begin
+            assert (motor_en_n == 1'b1);
+
+            if (limit_ls_sync != 3'b111)
+                saw_ls_low <= 1'b1;
+
+            // Mirror DUT found_ls only during close-wait (freeze on motor_done).
+            if (motor_start && (motor_dir_mask == FORMAL_CLOSE_DIR_MASK)) begin
+                close_phase <= 1'b1;
+                found_ls_frozen <= 1'b0;
+                // Non-participants already sat on LS; OR current LS on first close beat.
+                shadow_found_ls <= (~motor_active_mask) | limit_ls_sync;
+            end else if (close_phase && !found_ls_frozen) begin
+                shadow_found_ls <= shadow_found_ls | limit_ls_sync;
+                if (motor_done)
+                    found_ls_frozen <= 1'b1;
+            end
+            if (startup_done || (motor_start && (motor_dir_mask == 3'b000)))
+                close_phase <= 1'b0;
+
+            // Backoff start: DIR=0 and a new motor_start.
+            if (motor_start && (motor_dir_mask == 3'b000)) begin
+                in_backoff <= 1'b1;
+                backoff_rising_x <= 4'd0;
+                assert (motor_step_count == FORMAL_BACKOFF_STEPS[2:0]);
+                // Axes that already found LS during close must not enter backoff.
+                assert ((motor_active_mask & shadow_found_ls) == 3'b000);
+            end
+            if (startup_done)
+                in_backoff <= 1'b0;
+
+            if (in_backoff && !prev_gated_step[0] && gated_step[0])
+                backoff_rising_x <= backoff_rising_x + 1'b1;
+
+            // Sticky idle after startup_done.
             if (!$initstate && $past(startup_done)) begin
                 assert (startup_done);
                 assert (motor_start == 1'b0);
@@ -100,6 +175,40 @@ module startup_close_seek_formal (
                 assert (motor_stop_mask == 3'b000);
             end
             if ($past(motor_start)) assert (!motor_start);
+
+            // All LS high from reset: no external STEP rising edges.
+            if (!saw_ls_low) begin
+                assert (gated_step == 3'b000);
+                if (past_valid)
+                    assert (!( !prev_gated_step[0] && gated_step[0] ));
+            end
+
+            // Truncate pin path: target-side sync => gated STEP 0 same cycle.
+            if (engine_dir[0] ? limit_ls_sync[0] : limit_hs_sync[0])
+                assert (gated_step[0] == 1'b0);
+            if (engine_dir[1] ? limit_ls_sync[1] : limit_hs_sync[1])
+                assert (gated_step[1] == 1'b0);
+            if (engine_dir[2] ? limit_ls_sync[2] : limit_hs_sync[2])
+                assert (gated_step[2] == 1'b0);
+
+            // Missed-axis backoff budget: at most BACKOFF_STEPS rising edges.
+            assert (backoff_rising_x <= FORMAL_BACKOFF_STEPS[3:0]);
+
+            if (past_valid) begin
+                // Engine truncate: registered STEP cleared the cycle after stop_mask.
+                if ($past(motor_stop_mask[0]) && $past(rst_n))
+                    assert (engine_step[0] == 1'b0);
+                if ($past(motor_stop_mask[1]) && $past(rst_n))
+                    assert (engine_step[1] == 1'b0);
+                if ($past(motor_stop_mask[2]) && $past(rst_n))
+                    assert (engine_step[2] == 1'b0);
+
+                // During backoff, HS can terminate early (no new rise while HS high).
+                if (in_backoff && $past(limit_hs_sync[0]) && !engine_dir[0])
+                    assert (!( !prev_gated_step[0] && gated_step[0] ));
+            end
+
+            prev_gated_step <= gated_step;
         end
     end
 
@@ -107,5 +216,7 @@ module startup_close_seek_formal (
         cover (rst_n && startup_done);
         cover (rst_n && motor_active_mask == 3'b111);
         cover (rst_n && startup_done && limit_ls_sync == 3'b000);
+        cover (rst_n && motor_start && motor_dir_mask == 3'b000);
+        cover (rst_n && !saw_ls_low && startup_done);
     end
 endmodule

+ 22 - 6
tests/sim/door_motor_engine_stop_tb.v

@@ -100,15 +100,31 @@ module door_motor_engine_stop_tb;
         wait_for_done();
         if (y_rises !== HOST_STEPS) $fatal(1, "scenario1: Y did not reach 450");
 
-        // X stopped while STEP high: current pulse completes, no new rising edge.
+        // X stopped while STEP high: ACTUAL RTL truncate (not finish-high) —
+        // truncate_current_high_pulse_immediately_after_synchronized_limit.
         reset_dut();
         start_motor();
         while (step[0] !== 1'b1) pulse_tick();
-        stop_mask = 3'b001;
-        while (step[0] !== 1'b0) pulse_tick();
-        if (x_rises !== 1) $fatal(1, "scenario2: X pulse not completed");
-        repeat (20) pulse_tick();
-        if (x_rises !== 1) $fatal(1, "scenario2: new X rising edge after high-phase stop");
+        begin : truncate_high
+            integer rises_before;
+            @(posedge clk);
+            #1;
+            rises_before = x_rises;
+            if (rises_before < 1)
+                $fatal(1, "scenario2: expected X rising edge before truncate");
+            if (step[0] !== 1'b1)
+                $fatal(1, "scenario2: lost STEP high before truncate");
+            @(negedge clk);
+            stop_mask = 3'b001;
+            @(posedge clk);
+            #1; // NBA settle: truncate clears registered STEP on this edge
+            if (step[0] !== 1'b0)
+                $fatal(1, "scenario2: truncate failed, STEP still high after stop_mask");
+            repeat (20) pulse_tick();
+            if (x_rises !== rises_before)
+                $fatal(1, "scenario2: new X rising edge after high-phase truncate got %0d want %0d",
+                       x_rises, rises_before);
+        end
 
         // Stop during DIR setup: zero steps on stopped axis.
         reset_dut();

+ 74 - 11
tests/sim/prod2u_p4_normal_v3_top_runtime_limit_tb.v

@@ -1,6 +1,12 @@
 `timescale 1ns/1ps
 
-// Runtime limit hard-stop: DIR=1 stops on LS, DIR=0 stops on HS; truncates STEP high.
+// Runtime limit hard-stop: DIR=1 stops on LS, DIR=0 stops on HS.
+// Asserts ACTUAL RTL truncate semantics:
+// truncate_current_high_pulse_immediately_after_synchronized_limit.
+//
+// host_motor_dir_mask/active_mask stay forced for the whole jog so
+// runtime_limit_stop_mask tracks the latched engine direction (top mux uses
+// host_motor_dir_mask while busy).
 module prod2u_p4_normal_v3_top_runtime_limit_tb;
     reg sys_clk = 1'b0;
     reg host_uart_rx = 1'b1;
@@ -70,16 +76,28 @@ module prod2u_p4_normal_v3_top_runtime_limit_tb;
         end
     endtask
 
-    task drive_host_motor;
+    task drain_limit_sync;
+        begin
+            repeat (4) @(posedge sys_clk);
+        end
+    endtask
+
+    task start_host_motor;
         input [2:0] mask;
         input [2:0] dir_mask;
         begin
             @(negedge sys_clk);
-            force dut.host_motor_start = 1'b1;
             force dut.host_motor_active_mask = mask;
             force dut.host_motor_dir_mask = dir_mask;
+            force dut.host_motor_start = 1'b1;
             @(posedge sys_clk);
             @(negedge sys_clk);
+            force dut.host_motor_start = 1'b0;
+        end
+    endtask
+
+    task release_host_motor;
+        begin
             release dut.host_motor_start;
             release dut.host_motor_active_mask;
             release dut.host_motor_dir_mask;
@@ -90,8 +108,8 @@ module prod2u_p4_normal_v3_top_runtime_limit_tb;
         host_x_steps = 0;
         prev_x_step = 1'b0;
 
-        // Z already at LS so startup finishes quickly.
-        x_limit_ls = 1'b0;
+        // All LS high: startup_done without motion (runtime path under test).
+        x_limit_ls = 1'b1;
         x_limit_hs = 1'b0;
         y_limit_ls = 1'b1;
         y_limit_hs = 1'b0;
@@ -102,32 +120,77 @@ module prod2u_p4_normal_v3_top_runtime_limit_tb;
         wait_for_startup_done();
         startup_done_seen = 1'b1;
 
-        // Host close on X (DIR=1): assert LS mid-move -> hard stop before 450.
-        drive_host_motor(3'b001, 3'b001);
+        x_limit_ls = 1'b0;
+        drain_limit_sync();
+
+        // Host close on X (DIR=1): assert LS mid-move -> truncate before 450.
+        start_host_motor(3'b001, 3'b001);
         while (host_x_steps < 5) @(posedge sys_clk);
         x_limit_ls = 1'b1;
+        drain_limit_sync();
+        if (x_step !== 1'b0)
+            $fatal(1, "runtime LS truncate failed: x_step still high after sync");
         while (!dut.u_motor_engine.done) @(posedge sys_clk);
+        release_host_motor();
         if (host_x_steps >= HOST_STEPS)
             $fatal(1, "runtime LS stop failed to truncate X before 450, got %0d", host_x_steps);
         if (host_x_steps < 1)
             $fatal(1, "X never stepped before runtime LS stop");
 
-        // Host open on X (DIR=0): assert HS mid-move -> hard stop before 450.
+        // Wrong-side HS while closing must not stop X.
+        host_x_steps = 0;
+        prev_x_step = 1'b0;
+        x_limit_ls = 1'b0;
+        x_limit_hs = 1'b1;
+        drain_limit_sync();
+        start_host_motor(3'b001, 3'b001);
+        while (host_x_steps < 8) @(posedge sys_clk);
+        if (!dut.u_motor_engine.busy)
+            $fatal(1, "wrong-side HS incorrectly stopped close jog early");
+        while (!dut.u_motor_engine.done) @(posedge sys_clk);
+        release_host_motor();
+        if (host_x_steps !== HOST_STEPS)
+            $fatal(1, "expected full 450 with wrong-side HS held, got %0d", host_x_steps);
+
+        // Host open on X (DIR=0): assert HS mid-move -> truncate before 450.
         host_x_steps = 0;
         prev_x_step = 1'b0;
         x_limit_ls = 1'b0;
         x_limit_hs = 1'b0;
-        drive_host_motor(3'b001, 3'b000);
+        drain_limit_sync();
+        start_host_motor(3'b001, 3'b000);
         while (host_x_steps < 5) @(posedge sys_clk);
         x_limit_hs = 1'b1;
+        drain_limit_sync();
+        if (x_step !== 1'b0)
+            $fatal(1, "runtime HS truncate failed: x_step still high after sync");
         while (!dut.u_motor_engine.done) @(posedge sys_clk);
+        release_host_motor();
         if (host_x_steps >= HOST_STEPS)
             $fatal(1, "runtime HS stop failed to truncate X before 450, got %0d", host_x_steps);
 
+        // Watchdog abort: external STEP low; EN remains permanent_high.
+        host_x_steps = 0;
+        prev_x_step = 1'b0;
+        x_limit_ls = 1'b0;
+        x_limit_hs = 1'b0;
+        drain_limit_sync();
+        start_host_motor(3'b001, 3'b001);
+        while (host_x_steps < 3) @(posedge sys_clk);
+        @(negedge sys_clk);
+        force dut.watchdog_timeout_event = 1'b1;
+        @(posedge sys_clk);
+        #1;
+        if (x_step !== 1'b0)
+            $fatal(1, "watchdog abort left x_step high");
+        if (motor_en_n !== 1'b1)
+            $fatal(1, "motor_en_n dropped after watchdog (expected permanent_high)");
+        @(negedge sys_clk);
+        force dut.watchdog_timeout_event = 1'b0;
+        release_host_motor();
+
         if (!dut.startup_done)
             $fatal(1, "startup_done was not sticky through runtime limit stops");
-        if (dut.motor_stop_mask !== 3'b000 && dut.startup_done)
-            ; // runtime stop mask may be non-zero during move; after done engine idle
 
         $display("prod2u_p4_normal_v3_top_runtime_limit_tb PASS");
         $finish;

+ 1 - 0
tests/sim/prod2u_p4_normal_v3_top_startup_tb.v

@@ -61,6 +61,7 @@ module prod2u_p4_normal_v3_top_startup_tb;
     always @(posedge sys_clk) begin
         prev_x_step <= x_step;
         prev_y_step <= y_step;
+        prev_z_step <= z_step;
         if (startup_phase) begin
             if (!prev_x_step && x_step) startup_x_steps <= startup_x_steps + 1;
             if (!prev_y_step && y_step) startup_y_steps <= startup_y_steps + 1;