| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- `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
|