Преглед изворни кода

fix(mse): install reconstructed A1 DDA for fair TD

Archive A2 at a978ff6 after DSP packing FIT but route congestion fail,
and switch production scheduler to reconstructed A1 (drain-parity) for
feature-parity full-chip comparison.

Co-authored-by: Cursor <cursoragent@cursor.com>
root пре 3 месеци
родитељ
комит
805b40dcc7

+ 31 - 0
receipts/mse-td-a2-dsp-a978ff6.json

@@ -0,0 +1,31 @@
+{
+  "schema": "prod2u-mse-a2-dsp-td-phy-v1",
+  "generated_utc": "2026-08-11T21:58:00Z",
+  "status": "fail_route",
+  "note": "DSP rate builder inferred (1 DSP). Packing FIT MSLICE 1082/1120 but PHY-8155 route congestion fail.",
+  "commit": "a978ff6230e55990c91475fc111c1348c2abe322",
+  "run_id": "20260811T213507Z-ad8fd263",
+  "gate_total_luts": 3262,
+  "gate_lut_util": 4160,
+  "reg": 1598,
+  "bram": 0,
+  "dsp": 1,
+  "motor_lut": 2611,
+  "dda_lut": 202,
+  "rate_builder_lut": 3,
+  "packing": {
+    "mslice": 1082,
+    "lslice": 1081,
+    "mslice_limit": 1120,
+    "fit": true
+  },
+  "route": {
+    "status": "fail",
+    "error": "PHY-8155",
+    "violation": "x14y15_local4 nets profile/done_n1 vs axis_z/mux"
+  },
+  "fmax_mhz": null,
+  "swns_ns": null,
+  "hardware_validation": "NOT RUN",
+  "dev_lock": "d4f3df2549efeb1e9227f62d1d71c6179c9f9160"
+}

+ 140 - 0
receipts/scheme-a-a2-attempt/door_shared_dda_scheduler_a2_active_a978ff6.v

@@ -0,0 +1,140 @@
+`timescale 1ns/1ps
+
+// Scheme A1 (RECONSTRUCTED candidate for fair full-chip TD) sequential shared DDA (not exact byte-archive).
+// Provenance: recovered from agent transcript 7c830c69 (Round-2 A1 implementation)
+// matching yosys-a1-dda.stat signals (state/service_pending/f_fire/f_next).
+// Label: reconstructed — must pass same functional tests as A2 before fair TD.
+// Drain semantics (Round-3): phase always wraps when active && sum>=thr;
+// allow_toggle only gates the STEP toggle pulse (high-pulse drain).
+
+module door_shared_dda_scheduler #(
+    parameter integer TRAVEL_WIDTH = 13,
+    parameter integer PHASE_WIDTH  = 26,
+    parameter integer RATE_WIDTH   = 21,
+    parameter integer THRESH_WIDTH = 25,
+    parameter integer CAL_PHASE_THRESHOLD = 5120
+) (
+    input  wire                         clk,
+    input  wire                         rst_n,
+    input  wire                         service_ce,
+    input  wire [2:0]                   active,
+    input  wire [2:0]                   allow_toggle,
+    input  wire [2:0]                   cal_mode,
+    input  wire [RATE_WIDTH-1:0]        rate0,
+    input  wire [RATE_WIDTH-1:0]        rate1,
+    input  wire [RATE_WIDTH-1:0]        rate2,
+    input  wire [THRESH_WIDTH-1:0]      phase_threshold,
+    output reg  [2:0]                   toggle_pulse,
+    output reg                          busy,
+    output wire                         service_overrun
+);
+    localparam [1:0] ST_IDLE = 2'd0,
+                     ST_X    = 2'd1,
+                     ST_Y    = 2'd2,
+                     ST_Z    = 2'd3;
+
+    reg [1:0] state;
+    reg [PHASE_WIDTH-1:0] phase0, phase1, phase2;
+    reg service_pending;
+    reg overrun_r;
+
+    assign service_overrun = overrun_r;
+
+    wire [PHASE_WIDTH-1:0] thr_run =
+        {{(PHASE_WIDTH-THRESH_WIDTH){1'b0}}, phase_threshold};
+    wire [PHASE_WIDTH-1:0] thr_cal = CAL_PHASE_THRESHOLD[PHASE_WIDTH-1:0];
+
+    // Phase always advances/wraps when enabled; allow only gates fire.
+    function automatic [PHASE_WIDTH-1:0] f_next;
+        input [PHASE_WIDTH-1:0] ph;
+        input [RATE_WIDTH-1:0]  rate;
+        input [PHASE_WIDTH-1:0] thr;
+        input                   en;
+        reg   [PHASE_WIDTH-1:0] sum;
+        begin
+            if (!en) begin
+                f_next = {PHASE_WIDTH{1'b0}};
+            end else begin
+                sum = ph + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate};
+                if (sum >= thr)
+                    f_next = sum - thr;
+                else
+                    f_next = sum;
+            end
+        end
+    endfunction
+
+    function automatic f_fire;
+        input [PHASE_WIDTH-1:0] ph;
+        input [RATE_WIDTH-1:0]  rate;
+        input [PHASE_WIDTH-1:0] thr;
+        input                   en;
+        input                   allow;
+        reg   [PHASE_WIDTH-1:0] sum;
+        begin
+            sum = ph + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate};
+            f_fire = en && allow && (sum >= thr);
+        end
+    endfunction
+
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin
+            state <= ST_IDLE;
+            phase0 <= {PHASE_WIDTH{1'b0}};
+            phase1 <= {PHASE_WIDTH{1'b0}};
+            phase2 <= {PHASE_WIDTH{1'b0}};
+            toggle_pulse <= 3'b000;
+            busy <= 1'b0;
+            service_pending <= 1'b0;
+            overrun_r <= 1'b0;
+        end else begin
+            toggle_pulse <= 3'b000;
+
+            if (service_ce) begin
+                if (busy)
+                    overrun_r <= 1'b1;
+                else
+                    service_pending <= 1'b1;
+            end
+
+            case (state)
+                ST_IDLE: begin
+                    busy <= 1'b0;
+                    if (service_pending) begin
+                        service_pending <= 1'b0;
+                        busy <= 1'b1;
+                        state <= ST_X;
+                    end
+                end
+                ST_X: begin
+                    begin : ax0
+                        reg [PHASE_WIDTH-1:0] thr;
+                        thr = cal_mode[0] ? thr_cal : thr_run;
+                        toggle_pulse[0] <= f_fire(phase0, rate0, thr, active[0], allow_toggle[0]);
+                        phase0 <= f_next(phase0, rate0, thr, active[0]);
+                    end
+                    state <= ST_Y;
+                end
+                ST_Y: begin
+                    begin : ax1
+                        reg [PHASE_WIDTH-1:0] thr;
+                        thr = cal_mode[1] ? thr_cal : thr_run;
+                        toggle_pulse[1] <= f_fire(phase1, rate1, thr, active[1], allow_toggle[1]);
+                        phase1 <= f_next(phase1, rate1, thr, active[1]);
+                    end
+                    state <= ST_Z;
+                end
+                default: begin
+                    begin : ax2
+                        reg [PHASE_WIDTH-1:0] thr;
+                        thr = cal_mode[2] ? thr_cal : thr_run;
+                        toggle_pulse[2] <= f_fire(phase2, rate2, thr, active[2], allow_toggle[2]);
+                        phase2 <= f_next(phase2, rate2, thr, active[2]);
+                    end
+                    busy <= 1'b0;
+                    state <= ST_IDLE;
+                end
+            endcase
+        end
+    end
+endmodule

+ 95 - 46
src/modules/door_shared_dda_scheduler.v

@@ -1,12 +1,14 @@
 `timescale 1ns/1ps
 
-// Scheme A2: three parallel narrow DDA datapaths (one add/compare/sub each).
-// On each motion_service_ce, all active axes update in one clock.
-// 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).
-// service_overrun stays 0: next service cannot overlap a multi-cycle busy.
+// Scheme A1 (RECONSTRUCTED candidate for fair full-chip TD) sequential shared DDA (not exact byte-archive).
+// Provenance: recovered from agent transcript 7c830c69 (Round-2 A1 implementation)
+// matching yosys-a1-dda.stat signals (state/service_pending/f_fire/f_next).
+// Label: reconstructed — must pass same functional tests as A2 before fair TD.
+// Drain semantics (Round-3): phase always wraps when active && sum>=thr;
+// allow_toggle only gates the STEP toggle pulse (high-pulse drain).
+
 module door_shared_dda_scheduler #(
+    parameter integer TRAVEL_WIDTH = 13,
     parameter integer PHASE_WIDTH  = 26,
     parameter integer RATE_WIDTH   = 21,
     parameter integer THRESH_WIDTH = 25,
@@ -26,66 +28,113 @@ module door_shared_dda_scheduler #(
     output reg                          busy,
     output wire                         service_overrun
 );
+    localparam [1:0] ST_IDLE = 2'd0,
+                     ST_X    = 2'd1,
+                     ST_Y    = 2'd2,
+                     ST_Z    = 2'd3;
+
+    reg [1:0] state;
     reg [PHASE_WIDTH-1:0] phase0, phase1, phase2;
-    assign service_overrun = 1'b0;
-    wire _unused_allow = |allow_toggle;
+    reg service_pending;
+    reg overrun_r;
+
+    assign service_overrun = overrun_r;
 
     wire [PHASE_WIDTH-1:0] thr_run =
         {{(PHASE_WIDTH-THRESH_WIDTH){1'b0}}, phase_threshold};
     wire [PHASE_WIDTH-1:0] thr_cal = CAL_PHASE_THRESHOLD[PHASE_WIDTH-1:0];
 
+    // Phase always advances/wraps when enabled; allow only gates fire.
+    function automatic [PHASE_WIDTH-1:0] f_next;
+        input [PHASE_WIDTH-1:0] ph;
+        input [RATE_WIDTH-1:0]  rate;
+        input [PHASE_WIDTH-1:0] thr;
+        input                   en;
+        reg   [PHASE_WIDTH-1:0] sum;
+        begin
+            if (!en) begin
+                f_next = {PHASE_WIDTH{1'b0}};
+            end else begin
+                sum = ph + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate};
+                if (sum >= thr)
+                    f_next = sum - thr;
+                else
+                    f_next = sum;
+            end
+        end
+    endfunction
+
+    function automatic f_fire;
+        input [PHASE_WIDTH-1:0] ph;
+        input [RATE_WIDTH-1:0]  rate;
+        input [PHASE_WIDTH-1:0] thr;
+        input                   en;
+        input                   allow;
+        reg   [PHASE_WIDTH-1:0] sum;
+        begin
+            sum = ph + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate};
+            f_fire = en && allow && (sum >= thr);
+        end
+    endfunction
+
     always @(posedge clk or negedge rst_n) begin
         if (!rst_n) begin
+            state <= ST_IDLE;
             phase0 <= {PHASE_WIDTH{1'b0}};
             phase1 <= {PHASE_WIDTH{1'b0}};
             phase2 <= {PHASE_WIDTH{1'b0}};
             toggle_pulse <= 3'b000;
             busy <= 1'b0;
+            service_pending <= 1'b0;
+            overrun_r <= 1'b0;
         end else begin
             toggle_pulse <= 3'b000;
-            busy <= 1'b0;
+
             if (service_ce) begin
-                begin : par
-                    reg [PHASE_WIDTH-1:0] t0, t1, t2;
-                    reg [PHASE_WIDTH-1:0] s0, s1, s2;
-                    t0 = cal_mode[0] ? thr_cal : thr_run;
-                    t1 = cal_mode[1] ? thr_cal : thr_run;
-                    t2 = cal_mode[2] ? thr_cal : thr_run;
-                    if (active[0]) begin
-                        s0 = phase0 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate0};
-                        if (s0 >= t0) begin
-                            toggle_pulse[0] <= 1'b1;
-                            phase0 <= s0 - t0;
-                        end else begin
-                            phase0 <= s0;
-                        end
-                    end else begin
-                        phase0 <= {PHASE_WIDTH{1'b0}};
+                if (busy)
+                    overrun_r <= 1'b1;
+                else
+                    service_pending <= 1'b1;
+            end
+
+            case (state)
+                ST_IDLE: begin
+                    busy <= 1'b0;
+                    if (service_pending) begin
+                        service_pending <= 1'b0;
+                        busy <= 1'b1;
+                        state <= ST_X;
+                    end
+                end
+                ST_X: begin
+                    begin : ax0
+                        reg [PHASE_WIDTH-1:0] thr;
+                        thr = cal_mode[0] ? thr_cal : thr_run;
+                        toggle_pulse[0] <= f_fire(phase0, rate0, thr, active[0], allow_toggle[0]);
+                        phase0 <= f_next(phase0, rate0, thr, active[0]);
                     end
-                    if (active[1]) begin
-                        s1 = phase1 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate1};
-                        if (s1 >= t1) begin
-                            toggle_pulse[1] <= 1'b1;
-                            phase1 <= s1 - t1;
-                        end else begin
-                            phase1 <= s1;
-                        end
-                    end else begin
-                        phase1 <= {PHASE_WIDTH{1'b0}};
+                    state <= ST_Y;
+                end
+                ST_Y: begin
+                    begin : ax1
+                        reg [PHASE_WIDTH-1:0] thr;
+                        thr = cal_mode[1] ? thr_cal : thr_run;
+                        toggle_pulse[1] <= f_fire(phase1, rate1, thr, active[1], allow_toggle[1]);
+                        phase1 <= f_next(phase1, rate1, thr, active[1]);
                     end
-                    if (active[2]) begin
-                        s2 = phase2 + {{(PHASE_WIDTH-RATE_WIDTH){1'b0}}, rate2};
-                        if (s2 >= t2) begin
-                            toggle_pulse[2] <= 1'b1;
-                            phase2 <= s2 - t2;
-                        end else begin
-                            phase2 <= s2;
-                        end
-                    end else begin
-                        phase2 <= {PHASE_WIDTH{1'b0}};
+                    state <= ST_Z;
+                end
+                default: begin
+                    begin : ax2
+                        reg [PHASE_WIDTH-1:0] thr;
+                        thr = cal_mode[2] ? thr_cal : thr_run;
+                        toggle_pulse[2] <= f_fire(phase2, rate2, thr, active[2], allow_toggle[2]);
+                        phase2 <= f_next(phase2, rate2, thr, active[2]);
                     end
+                    busy <= 1'b0;
+                    state <= ST_IDLE;
                 end
-            end
+            endcase
         end
     end
 endmodule