|
|
@@ -1,14 +1,12 @@
|
|
|
`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).
|
|
|
-
|
|
|
+// 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.
|
|
|
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,
|
|
|
@@ -28,113 +26,66 @@ 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;
|
|
|
- reg service_pending;
|
|
|
- reg overrun_r;
|
|
|
-
|
|
|
- assign service_overrun = overrun_r;
|
|
|
+ assign service_overrun = 1'b0;
|
|
|
+ wire _unused_allow = |allow_toggle;
|
|
|
|
|
|
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
|
|
|
- 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]);
|
|
|
+ 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}};
|
|
|
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]);
|
|
|
+ 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}};
|
|
|
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]);
|
|
|
+ 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}};
|
|
|
end
|
|
|
- busy <= 1'b0;
|
|
|
- state <= ST_IDLE;
|
|
|
end
|
|
|
- endcase
|
|
|
+ end
|
|
|
end
|
|
|
end
|
|
|
endmodule
|