Просмотр исходного кода

fix(mse): restore A2 drain semantics and serial-cal TBs

Keep DDA wrap independent of allow_toggle so STEP high can drain, and
update grant/status payload benches for serial X→Y→Z calibration plus
resource_policy/snapshot unit honesty.

Co-authored-by: Cursor <cursoragent@cursor.com>
root 3 месяцев назад
Родитель
Сommit
a0e12e3fc4

+ 6 - 4
src/modules/door_shared_dda_scheduler.v

@@ -2,7 +2,8 @@
 
 
 // Scheme A2: three parallel narrow DDA datapaths (one add/compare/sub each).
 // Scheme A2: three parallel narrow DDA datapaths (one add/compare/sub each).
 // On each motion_service_ce, all active axes update in one clock.
 // On each motion_service_ce, all active axes update in one clock.
-// allow_toggle gates wrap/fire (same semantics as reconstructed A1).
+// Rise permission is enforced in the axis STEP toggle helper; this datapath
+// always wraps when active so high pulses can still drain (!allow_rise).
 // busy is always 0 after the single service cycle (1-cycle datapath).
 // busy is always 0 after the single service cycle (1-cycle datapath).
 // service_overrun stays 0: next service cannot overlap a multi-cycle busy.
 // service_overrun stays 0: next service cannot overlap a multi-cycle busy.
 module door_shared_dda_scheduler #(
 module door_shared_dda_scheduler #(
@@ -27,6 +28,7 @@ module door_shared_dda_scheduler #(
 );
 );
     reg [PHASE_WIDTH-1:0] phase0, phase1, phase2;
     reg [PHASE_WIDTH-1:0] phase0, phase1, phase2;
     assign service_overrun = 1'b0;
     assign service_overrun = 1'b0;
+    wire _unused_allow = |allow_toggle;
 
 
     wire [PHASE_WIDTH-1:0] thr_run =
     wire [PHASE_WIDTH-1:0] thr_run =
         {{(PHASE_WIDTH-THRESH_WIDTH){1'b0}}, phase_threshold};
         {{(PHASE_WIDTH-THRESH_WIDTH){1'b0}}, phase_threshold};
@@ -51,7 +53,7 @@ module door_shared_dda_scheduler #(
                     t2 = cal_mode[2] ? thr_cal : thr_run;
                     t2 = cal_mode[2] ? thr_cal : thr_run;
                     if (active[0]) begin
                     if (active[0]) begin
                         s0 = phase0 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate0};
                         s0 = phase0 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate0};
-                        if (allow_toggle[0] && (s0 >= t0)) begin
+                        if (s0 >= t0) begin
                             toggle_pulse[0] <= 1'b1;
                             toggle_pulse[0] <= 1'b1;
                             phase0 <= s0 - t0;
                             phase0 <= s0 - t0;
                         end else begin
                         end else begin
@@ -62,7 +64,7 @@ module door_shared_dda_scheduler #(
                     end
                     end
                     if (active[1]) begin
                     if (active[1]) begin
                         s1 = phase1 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate1};
                         s1 = phase1 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate1};
-                        if (allow_toggle[1] && (s1 >= t1)) begin
+                        if (s1 >= t1) begin
                             toggle_pulse[1] <= 1'b1;
                             toggle_pulse[1] <= 1'b1;
                             phase1 <= s1 - t1;
                             phase1 <= s1 - t1;
                         end else begin
                         end else begin
@@ -73,7 +75,7 @@ module door_shared_dda_scheduler #(
                     end
                     end
                     if (active[2]) begin
                     if (active[2]) begin
                         s2 = phase2 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate2};
                         s2 = phase2 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate2};
-                        if (allow_toggle[2] && (s2 >= t2)) begin
+                        if (s2 >= t2) begin
                             toggle_pulse[2] <= 1'b1;
                             toggle_pulse[2] <= 1'b1;
                             phase2 <= s2 - t2;
                             phase2 <= s2 - t2;
                         end else begin
                         end else begin

+ 60 - 20
tests/sim/door_motion_status_payload_tb.v

@@ -41,7 +41,10 @@ module door_motion_status_payload_tb;
         .MIN_TRAVEL(2),
         .MIN_TRAVEL(2),
         .ENDPOINT_GUARD_EXTRA(8),
         .ENDPOINT_GUARD_EXTRA(8),
         .DIR_SETUP_TICKS(1),
         .DIR_SETUP_TICKS(1),
-        .PERCENT_MAX(100)
+        .PERCENT_MAX(100),
+        .MOTION_SERVICE_CLKS(4),
+        .PHASE_FACTOR(64),
+        .CAL_RAMP_UNIT(2)
     ) dut (
     ) dut (
         .clk(clk), .rst_n(rst_n),
         .clk(clk), .rst_n(rst_n),
         .tick_500us(tick_500us),
         .tick_500us(tick_500us),
@@ -80,15 +83,57 @@ module door_motion_status_payload_tb;
         end
         end
     endtask
     endtask
 
 
-    task force_rise;
-        input [2:0] mask;
+    task force_rise_ax;
+        input integer ax;
+        reg [2:0] m;
         begin
         begin
+            m = 3'b001 << ax;
             @(negedge clk);
             @(negedge clk);
-            gated_step = mask;
-            gated_step_rise = mask;
+            gated_step = gated_step | m;
+            gated_step_rise = m;
             @(negedge clk);
             @(negedge clk);
             gated_step_rise = 3'b000;
             gated_step_rise = 3'b000;
-            gated_step = 3'b000;
+            gated_step = gated_step & ~m;
+        end
+    endtask
+
+    task wait_step_ax;
+        input integer ax;
+        input want;
+        integer t;
+        begin
+            for (t = 0; t < 20000; t = t + 1) begin
+                if (step[ax] === want) disable wait_step_ax;
+                @(negedge clk);
+            end
+            $fatal(1, "timeout step[%0d]==%0d", ax, want);
+        end
+    endtask
+
+    task cal_axis;
+        input integer ax;
+        input integer travel;
+        integer r;
+        begin
+            close_limit[ax] = 1'b1;
+            open_limit[ax] = 1'b0;
+            repeat (6) pulse_tick();
+            for (r = 0; r < travel; r = r + 1) begin
+                wait_step_ax(ax, 1);
+                force_rise_ax(ax);
+                wait_step_ax(ax, 0);
+            end
+            @(negedge clk);
+            open_limit[ax] = 1'b1;
+            close_limit[ax] = 1'b0;
+            begin : w
+                integer t;
+                for (t = 0; t < 8000; t = t + 1) begin
+                    if (calibrated_mask[ax]) disable w;
+                    @(negedge clk);
+                end
+            end
+            if (!calibrated_mask[ax]) $fatal(1, "cal fail ax=%0d", ax);
         end
         end
     endtask
     endtask
 
 
@@ -99,28 +144,23 @@ module door_motion_status_payload_tb;
     integer hdr_count;
     integer hdr_count;
 
 
     initial begin
     initial begin
-        #500000 $fatal(1, "door_motion_status_payload_tb timeout");
+        #5_000_000 $fatal(1, "door_motion_status_payload_tb timeout");
     end
     end
 
 
     initial begin
     initial begin
+        open_limit = 3'b000;
+        close_limit = 3'b000;
         repeat (2) @(posedge clk);
         repeat (2) @(posedge clk);
         rst_n = 1'b1;
         rst_n = 1'b1;
         @(negedge clk);
         @(negedge clk);
         limit_sync_valid = 1'b1;
         limit_sync_valid = 1'b1;
-        repeat (4) pulse_tick();
-        for (i = 0; i < 3; i = i + 1) begin
-            force_rise(3'b111);
-            pulse_tick();
+        cal_axis(0, 4);
+        cal_axis(1, 4);
+        cal_axis(2, 4);
+        begin : ws
+            integer t;
+            for (t = 0; t < 8000 && !startup_complete; t = t + 1) @(negedge clk);
         end
         end
-        @(negedge clk);
-        open_limit = 3'b111;
-        close_limit = 3'b000;
-        gated_step = 3'b111;
-        gated_step_rise = 3'b111;
-        @(negedge clk);
-        gated_step = 3'b000;
-        gated_step_rise = 3'b000;
-        repeat (8) @(negedge clk);
         if (!startup_complete)
         if (!startup_complete)
             $fatal(1, "startup_complete missing");
             $fatal(1, "startup_complete missing");
 
 

+ 57 - 16
tests/sim/door_planner_grant_once_tb.v

@@ -29,7 +29,8 @@ module door_planner_grant_once_tb;
 
 
     door_motion_controller #(
     door_motion_controller #(
         .MAX_CAL_STEPS(32), .MIN_TRAVEL(2),
         .MAX_CAL_STEPS(32), .MIN_TRAVEL(2),
-        .ENDPOINT_GUARD_EXTRA(8), .DIR_SETUP_TICKS(1), .PERCENT_MAX(100)
+        .ENDPOINT_GUARD_EXTRA(8), .DIR_SETUP_TICKS(1), .PERCENT_MAX(100),
+        .MOTION_SERVICE_CLKS(4), .PHASE_FACTOR(64), .CAL_RAMP_UNIT(2)
     ) dut (
     ) dut (
         .clk(clk), .rst_n(rst_n),
         .clk(clk), .rst_n(rst_n),
         .tick_500us(tick_500us),
         .tick_500us(tick_500us),
@@ -62,39 +63,79 @@ module door_planner_grant_once_tb;
         end
         end
     endtask
     endtask
 
 
-    task force_rise;
-        input [2:0] mask;
+    task force_rise_ax;
+        input integer ax;
+        reg [2:0] m;
         begin
         begin
+            m = 3'b001 << ax;
             @(negedge clk);
             @(negedge clk);
-            gated_step = mask; gated_step_rise = mask;
+            gated_step = gated_step | m; gated_step_rise = m;
             @(negedge clk);
             @(negedge clk);
-            gated_step_rise = 3'b000; gated_step = 3'b000;
+            gated_step_rise = 3'b000; gated_step = gated_step & ~m;
+        end
+    endtask
+
+    task wait_step_ax;
+        input integer ax;
+        input want;
+        integer t;
+        begin
+            for (t = 0; t < 20000; t = t + 1) begin
+                if (step[ax] === want) disable wait_step_ax;
+                @(negedge clk);
+            end
+            $fatal(1, "timeout step[%0d]==%0d", ax, want);
+        end
+    endtask
+
+    task cal_axis;
+        input integer ax;
+        input integer travel;
+        integer r;
+        begin
+            close_limit[ax] = 1'b1;
+            open_limit[ax] = 1'b0;
+            repeat (6) pulse_tick();
+            for (r = 0; r < travel; r = r + 1) begin
+                wait_step_ax(ax, 1);
+                force_rise_ax(ax);
+                wait_step_ax(ax, 0);
+            end
+            @(negedge clk);
+            open_limit[ax] = 1'b1;
+            close_limit[ax] = 1'b0;
+            begin : w
+                integer t;
+                for (t = 0; t < 8000; t = t + 1) begin
+                    if (calibrated_mask[ax]) disable w;
+                    @(negedge clk);
+                end
+            end
+            if (!calibrated_mask[ax]) $fatal(1, "cal fail ax=%0d", ax);
         end
         end
     endtask
     endtask
 
 
     integer i;
     integer i;
 
 
     initial begin
     initial begin
-        #500000 $fatal(1, "door_planner_grant_once_tb timeout");
+        #5_000_000 $fatal(1, "door_planner_grant_once_tb timeout");
     end
     end
 
 
     initial begin
     initial begin
         starts_x = 0; starts_y = 0; starts_z = 0;
         starts_x = 0; starts_y = 0; starts_z = 0;
+        open_limit = 3'b000;
+        close_limit = 3'b000;
         repeat (2) @(posedge clk);
         repeat (2) @(posedge clk);
         rst_n = 1'b1;
         rst_n = 1'b1;
         @(negedge clk);
         @(negedge clk);
         limit_sync_valid = 1'b1;
         limit_sync_valid = 1'b1;
-        repeat (4) pulse_tick();
-        for (i = 0; i < 3; i = i + 1) begin
-            force_rise(3'b111);
-            pulse_tick();
+        cal_axis(0, 4);
+        cal_axis(1, 4);
+        cal_axis(2, 4);
+        begin : ws
+            integer t;
+            for (t = 0; t < 8000 && !startup_complete; t = t + 1) @(negedge clk);
         end
         end
-        @(negedge clk);
-        open_limit = 3'b111; close_limit = 3'b000;
-        gated_step = 3'b111; gated_step_rise = 3'b111;
-        @(negedge clk);
-        gated_step = 3'b000; gated_step_rise = 3'b000;
-        repeat (8) @(negedge clk);
         if (!startup_complete) $fatal(1, "no startup");
         if (!startup_complete) $fatal(1, "no startup");
 
 
         open_limit = 3'b000;
         open_limit = 3'b000;

+ 3 - 2
tests/unit/test_project_config.py

@@ -61,19 +61,20 @@ class ProjectConfigTests(unittest.TestCase):
                 "target_ram",
                 "target_ram",
                 "request_ram",
                 "request_ram",
                 "temperature_ram",
                 "temperature_ram",
+                "bram",
                 "dsp",
                 "dsp",
                 "shared_pwm_comparators",
                 "shared_pwm_comparators",
                 "shared_percent_planner",
                 "shared_percent_planner",
                 "shared_i2c_readers",
                 "shared_i2c_readers",
             },
             },
         )
         )
-        for key in ("target_ram", "request_ram", "temperature_ram"):
+        for key in ("target_ram", "request_ram", "temperature_ram", "dsp", "bram"):
             self.assertIn(project["resource_policy"][key], {"optional", "required", "forbidden"})
             self.assertIn(project["resource_policy"][key], {"optional", "required", "forbidden"})
         self.assertTrue(
         self.assertTrue(
             all(
             all(
                 isinstance(project["resource_policy"][key], int)
                 isinstance(project["resource_policy"][key], int)
                 and project["resource_policy"][key] >= 0
                 and project["resource_policy"][key] >= 0
-                for key in ("dsp", "shared_pwm_comparators", "shared_percent_planner", "shared_i2c_readers")
+                for key in ("shared_pwm_comparators", "shared_percent_planner", "shared_i2c_readers")
             )
             )
         )
         )
 
 

+ 14 - 1
tests/unit/test_three_axis_door_contract.py

@@ -47,7 +47,20 @@ class ThreeAxisDoorContractTests(unittest.TestCase):
         source = MOTION_PATH.read_text(encoding="utf-8")
         source = MOTION_PATH.read_text(encoding="utf-8")
         self.assertIn("snap[0]", source)
         self.assertIn("snap[0]", source)
         self.assertIn("calibrated_mask", source)
         self.assertIn("calibrated_mask", source)
-        self.assertIn("// X @1, Y @11, Z @21", source)
+        # Direct payload layout (31 bytes): header @0, X @1..10, Y @11..20, Z @21..30.
+        for idx, tag in (
+            (1, "st_state_x"),
+            (11, "st_state_y"),
+            (21, "st_state_z"),
+            (10, "st_fault_x"),
+            (20, "st_fault_y"),
+            (30, "st_fault_z"),
+        ):
+            self.assertRegex(
+                source,
+                rf"snap\[{idx}\]\s*<=\s*.*{tag}",
+                msg=f"snapshot byte {idx} must bind {tag}",
+            )
         self.assertNotIn("intake_door_cmd", source)
         self.assertNotIn("intake_door_cmd", source)
 
 
     def test_controller_and_adapter_use_door_percent(self):
     def test_controller_and_adapter_use_door_percent(self):