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

feat(rtl): move 6400 state banks into EF2 block RAM

root 3 месяцев назад
Родитель
Сommit
0f0fef8c67

+ 2 - 0
products/6400-control/source-closure.json

@@ -7,6 +7,7 @@
     "src/common/uart_rx_byte.v",
     "src/common/uart_rx_byte.v",
     "src/common/uart_tx_byte.v",
     "src/common/uart_tx_byte.v",
     "src/common/crc16_serial.v",
     "src/common/crc16_serial.v",
+    "src/common/ef2_bram_dp.v",
     "src/common/frame_rx.v",
     "src/common/frame_rx.v",
     "src/common/frame_tx.v",
     "src/common/frame_tx.v",
     "src/common/payload_ram.v",
     "src/common/payload_ram.v",
@@ -19,6 +20,7 @@
     "src/acquisition/bmc_poll_engine.v",
     "src/acquisition/bmc_poll_engine.v",
     "src/acquisition/bmc_ascii_snapshot.v",
     "src/acquisition/bmc_ascii_snapshot.v",
     "src/acquisition/ct7428_snapshot.v",
     "src/acquisition/ct7428_snapshot.v",
+    "src/control/thermal_output_banks.v",
     "src/control/thermal_control_core.v",
     "src/control/thermal_control_core.v",
     "src/actuator/pwm_bitmap_engine.v",
     "src/actuator/pwm_bitmap_engine.v",
     "src/telemetry/thermal_snapshot_mux.v",
     "src/telemetry/thermal_snapshot_mux.v",

+ 82 - 52
src/acquisition/bmc_ascii_snapshot.v

@@ -31,8 +31,6 @@ module bmc_ascii_snapshot #(
     output reg [15:0]  snapshot_raw,
     output reg [15:0]  snapshot_raw,
     output reg         snapshot_valid
     output reg         snapshot_valid
 );
 );
-    reg [7:0] bank0 [0:47];
-    reg [7:0] bank1 [0:47];
     reg [23:0] valid0;
     reg [23:0] valid0;
     reg [23:0] valid1;
     reg [23:0] valid1;
     reg [5:0] byte_count;
     reg [5:0] byte_count;
@@ -46,7 +44,12 @@ module bmc_ascii_snapshot #(
     localparam integer GAP_BITS = (INTER_BYTE_TIMEOUT_CLKS <= 1) ? 1 :
     localparam integer GAP_BITS = (INTER_BYTE_TIMEOUT_CLKS <= 1) ? 1 :
         $clog2(INTER_BYTE_TIMEOUT_CLKS + 1);
         $clog2(INTER_BYTE_TIMEOUT_CLKS + 1);
     reg [GAP_BITS-1:0] gap_counter;
     reg [GAP_BITS-1:0] gap_counter;
-    integer i;
+    reg init_active;
+    reg [4:0] init_index;
+    reg ram_write_en;
+    reg ram_write_bank;
+    reg [4:0] ram_write_addr;
+    reg [15:0] ram_write_data;
     wire inactive_bank = ~active_bank;
     wire inactive_bank = ~active_bank;
     wire write_blocked = snapshot_lock && (inactive_bank == snapshot_lock_bank);
     wire write_blocked = snapshot_lock && (inactive_bank == snapshot_lock_bank);
     /* verilator lint_off WIDTH */
     /* verilator lint_off WIDTH */
@@ -90,22 +93,36 @@ module bmc_ascii_snapshot #(
 
 
     assign stale = (age_seconds >= STALE_SECONDS[15:0]);
     assign stale = (age_seconds >= STALE_SECONDS[15:0]);
     assign active_valid_mask = active_bank ? valid1 : valid0;
     assign active_valid_mask = active_bank ? valid1 : valid0;
+    wire bank0_write = init_active || (ram_write_en && !ram_write_bank);
+    wire bank1_write = init_active || (ram_write_en && ram_write_bank);
+    wire [4:0] bank0_b_addr = init_active ? init_index :
+        ((ram_write_en && !ram_write_bank) ? ram_write_addr : snapshot_index);
+    wire [4:0] bank1_b_addr = init_active ? init_index :
+        ((ram_write_en && ram_write_bank) ? ram_write_addr : snapshot_index);
+    wire [15:0] bank_write_data = init_active ? 16'd0 : ram_write_data;
+    wire [15:0] bank0_control_raw;
+    wire [15:0] bank1_control_raw;
+    wire [15:0] bank0_snapshot_raw;
+    wire [15:0] bank1_snapshot_raw;
+
+    ef2_bram_dp #(.DATA_WIDTH(16), .ADDR_WIDTH(5), .DATA_DEPTH(24)) u_bank0 (
+        .clk(clk), .a_en(1'b1), .a_we(1'b0), .a_addr(control_index),
+        .a_wdata(16'd0), .a_rdata(bank0_control_raw),
+        .b_en(1'b1), .b_we(bank0_write), .b_addr(bank0_b_addr),
+        .b_wdata(bank_write_data), .b_rdata(bank0_snapshot_raw)
+    );
+    ef2_bram_dp #(.DATA_WIDTH(16), .ADDR_WIDTH(5), .DATA_DEPTH(24)) u_bank1 (
+        .clk(clk), .a_en(1'b1), .a_we(1'b0), .a_addr(control_index),
+        .a_wdata(16'd0), .a_rdata(bank1_control_raw),
+        .b_en(1'b1), .b_we(bank1_write), .b_addr(bank1_b_addr),
+        .b_wdata(bank_write_data), .b_rdata(bank1_snapshot_raw)
+    );
 
 
     always @* begin
     always @* begin
-        if (control_bank) begin
-            control_raw = {bank1[{control_index, 1'b0}], bank1[{control_index, 1'b0} + 1'b1]};
-            control_valid = valid1[control_index];
-        end else begin
-            control_raw = {bank0[{control_index, 1'b0}], bank0[{control_index, 1'b0} + 1'b1]};
-            control_valid = valid0[control_index];
-        end
-        if (snapshot_bank) begin
-            snapshot_raw = {bank1[{snapshot_index, 1'b0}], bank1[{snapshot_index, 1'b0} + 1'b1]};
-            snapshot_valid = valid1[snapshot_index];
-        end else begin
-            snapshot_raw = {bank0[{snapshot_index, 1'b0}], bank0[{snapshot_index, 1'b0} + 1'b1]};
-            snapshot_valid = valid0[snapshot_index];
-        end
+        control_raw = control_bank ? bank1_control_raw : bank0_control_raw;
+        control_valid = control_bank ? valid1[control_index] : valid0[control_index];
+        snapshot_raw = snapshot_bank ? bank1_snapshot_raw : bank0_snapshot_raw;
+        snapshot_valid = snapshot_bank ? valid1[snapshot_index] : valid0[snapshot_index];
     end
     end
 
 
     always @(posedge clk or negedge rst_n) begin
     always @(posedge clk or negedge rst_n) begin
@@ -126,21 +143,32 @@ module bmc_ascii_snapshot #(
             integer_byte <= 8'd0;
             integer_byte <= 8'd0;
             echo_match <= 1'b1;
             echo_match <= 1'b1;
             gap_counter <= {GAP_BITS{1'b0}};
             gap_counter <= {GAP_BITS{1'b0}};
-            for (i = 0; i < 48; i = i + 1) begin
-                bank0[i] <= 8'd0;
-                bank1[i] <= 8'd0;
-            end
+            init_active <= 1'b1;
+            init_index <= 5'd0;
+            ram_write_en <= 1'b0;
+            ram_write_bank <= 1'b0;
+            ram_write_addr <= 5'd0;
+            ram_write_data <= 16'd0;
         end else begin
         end else begin
             snapshot_commit <= 1'b0;
             snapshot_commit <= 1'b0;
             parser_error <= 1'b0;
             parser_error <= 1'b0;
-            if (tick_1s && age_seconds != 16'hffff)
-                age_seconds <= age_seconds + 1'b1;
-            if (rx_framing_error) begin
-                line_bad <= 1'b1;
-                line_format_bad <= 1'b1;
-                line_active <= 1'b1;
-            end
-            if (!rx_valid && line_active) begin
+            ram_write_en <= 1'b0;
+            if (init_active) begin
+                if (init_index == 5'd23) begin
+                    init_active <= 1'b0;
+                    init_index <= 5'd0;
+                end else begin
+                    init_index <= init_index + 1'b1;
+                end
+            end else begin
+                if (tick_1s && age_seconds != 16'hffff)
+                    age_seconds <= age_seconds + 1'b1;
+                if (rx_framing_error) begin
+                    line_bad <= 1'b1;
+                    line_format_bad <= 1'b1;
+                    line_active <= 1'b1;
+                end
+                if (!rx_valid && line_active) begin
                 if (INTER_BYTE_TIMEOUT_CLKS <= 1 || gap_expired) begin
                 if (INTER_BYTE_TIMEOUT_CLKS <= 1 || gap_expired) begin
                     byte_count <= 6'd0;
                     byte_count <= 6'd0;
                     have_high <= 1'b0;
                     have_high <= 1'b0;
@@ -155,7 +183,7 @@ module bmc_ascii_snapshot #(
                     gap_counter <= gap_counter + 1'b1;
                     gap_counter <= gap_counter + 1'b1;
                 end
                 end
             end
             end
-            if (rx_valid) begin
+                if (rx_valid) begin
                 gap_counter <= {GAP_BITS{1'b0}};
                 gap_counter <= {GAP_BITS{1'b0}};
                 if (is_hex(rx_data)) begin
                 if (is_hex(rx_data)) begin
                     if (!line_active && !have_high) begin
                     if (!line_active && !have_high) begin
@@ -173,28 +201,30 @@ module bmc_ascii_snapshot #(
                     end else begin
                     end else begin
                         have_high <= 1'b0;
                         have_high <= 1'b0;
                         if (byte_count < 6'd48) begin
                         if (byte_count < 6'd48) begin
-                            if (!write_blocked) begin
-                                if (active_bank)
-                                    bank0[byte_count] <= {high_nibble, hex_value(rx_data)};
-                                else
-                                    bank1[byte_count] <= {high_nibble, hex_value(rx_data)};
-                            end
                             if (byte_count < 6)
                             if (byte_count < 6)
                                 echo_match <= echo_match && ({high_nibble, hex_value(rx_data)} == echo_byte(byte_count[2:0]));
                                 echo_match <= echo_match && ({high_nibble, hex_value(rx_data)} == echo_byte(byte_count[2:0]));
                             if (byte_count[0] == 1'b0) begin
                             if (byte_count[0] == 1'b0) begin
                                 integer_byte <= {high_nibble, hex_value(rx_data)};
                                 integer_byte <= {high_nibble, hex_value(rx_data)};
-                            end else if ((integer_byte == 8'hff) && ({high_nibble, hex_value(rx_data)} == 8'hff)) begin
+                            end else begin
+                                if (!write_blocked) begin
+                                    ram_write_en <= 1'b1;
+                                    ram_write_bank <= inactive_bank;
+                                    ram_write_addr <= byte_count[5:1];
+                                    ram_write_data <= {integer_byte, {high_nibble, hex_value(rx_data)}};
+                                end
+                                if ((integer_byte == 8'hff) && ({high_nibble, hex_value(rx_data)} == 8'hff)) begin
                                 if (active_bank)
                                 if (active_bank)
                                     valid0[byte_count[5:1]] <= 1'b0;
                                     valid0[byte_count[5:1]] <= 1'b0;
                                 else
                                 else
                                     valid1[byte_count[5:1]] <= 1'b0;
                                     valid1[byte_count[5:1]] <= 1'b0;
-                            end else if ((integer_byte == 8'hff) || ({high_nibble, hex_value(rx_data)} >= 8'd100)) begin
-                                line_bad <= 1'b1;
-                            end else begin
-                                if (active_bank)
-                                    valid0[byte_count[5:1]] <= 1'b1;
-                                else
-                                    valid1[byte_count[5:1]] <= 1'b1;
+                                end else if ((integer_byte == 8'hff) || ({high_nibble, hex_value(rx_data)} >= 8'd100)) begin
+                                    line_bad <= 1'b1;
+                                end else begin
+                                    if (active_bank)
+                                        valid0[byte_count[5:1]] <= 1'b1;
+                                    else
+                                        valid1[byte_count[5:1]] <= 1'b1;
+                                end
                             end
                             end
                             byte_count <= byte_count + 1'b1;
                             byte_count <= byte_count + 1'b1;
                         end else begin
                         end else begin
@@ -234,28 +264,28 @@ module bmc_ascii_snapshot #(
                     line_format_bad <= 1'b1;
                     line_format_bad <= 1'b1;
                     have_high <= 1'b0;
                     have_high <= 1'b0;
                 end
                 end
+                end
             end
             end
         end
         end
     end
     end
 
 
 `ifdef FORMAL
 `ifdef FORMAL
     reg formal_past_valid;
     reg formal_past_valid;
-    (* anyconst *) reg [5:0] formal_bank_index;
     initial formal_past_valid = 0;
     initial formal_past_valid = 0;
     always @(posedge clk) begin
     always @(posedge clk) begin
         formal_past_valid <= 1;
         formal_past_valid <= 1;
-        assume(formal_bank_index < 48);
         if (rst_n && formal_past_valid && $past(rst_n)) begin
         if (rst_n && formal_past_valid && $past(rst_n)) begin
-            // P08: writes to the inactive bank cannot alter active-bank bytes.
-            if (active_bank == $past(active_bank)) begin
-                if (active_bank)
-                    assert(bank1[formal_bank_index] == $past(bank1[formal_bank_index]));
-                else
-                    assert(bank0[formal_bank_index] == $past(bank0[formal_bank_index]));
+            // P08: outside deterministic initialization, the write-port
+            // decoder can only select the inactive bank.
+            if (!init_active) begin
+                assert(!(bank0_write && !active_bank));
+                assert(!(bank1_write && active_bank));
+                if (active_bank == $past(active_bank)) begin
                 if (active_bank)
                 if (active_bank)
                     assert(valid1 == $past(valid1));
                     assert(valid1 == $past(valid1));
                 else
                 else
                     assert(valid0 == $past(valid0));
                     assert(valid0 == $past(valid0));
+                end
             end
             end
 
 
             // P09: a bank swap is one pointer flip paired with one epoch step.
             // P09: a bank swap is one pointer flip paired with one epoch step.

+ 45 - 23
src/acquisition/ct7428_snapshot.v

@@ -39,17 +39,39 @@ module ct7428_snapshot #(
     reg [1:0] state;
     reg [1:0] state;
     reg [4:0] index;
     reg [4:0] index;
     reg [31:0] wait_counter;
     reg [31:0] wait_counter;
-    reg [15:0] bank0 [0:26];
-    reg [15:0] bank1 [0:26];
     reg [26:0] valid0;
     reg [26:0] valid0;
     reg [26:0] valid1;
     reg [26:0] valid1;
-    integer i;
+    reg init_active;
+    reg [4:0] init_index;
     wire inactive_bank = ~active_bank;
     wire inactive_bank = ~active_bank;
     wire write_blocked = snapshot_lock && (inactive_bank == snapshot_lock_bank);
     wire write_blocked = snapshot_lock && (inactive_bank == snapshot_lock_bank);
 
 
     assign response_ready = (state == ST_RESPONSE);
     assign response_ready = (state == ST_RESPONSE);
     assign stale = age_seconds >= STALE_SECONDS[15:0];
     assign stale = age_seconds >= STALE_SECONDS[15:0];
     assign active_valid_mask = active_bank ? valid1 : valid0;
     assign active_valid_mask = active_bank ? valid1 : valid0;
+    wire sample_write = !init_active && state == ST_RESPONSE && response_valid;
+    wire bank0_write = init_active || (sample_write && !inactive_bank);
+    wire bank1_write = init_active || (sample_write && inactive_bank);
+    wire [4:0] bank_b_addr = init_active ? init_index :
+        (sample_write ? index : snapshot_index);
+    wire [15:0] bank_write_data = init_active ? 16'd0 : response_data;
+    wire [15:0] bank0_control_raw;
+    wire [15:0] bank1_control_raw;
+    wire [15:0] bank0_snapshot_raw;
+    wire [15:0] bank1_snapshot_raw;
+
+    ef2_bram_dp #(.DATA_WIDTH(16), .ADDR_WIDTH(5), .DATA_DEPTH(27)) u_bank0 (
+        .clk(clk), .a_en(1'b1), .a_we(1'b0), .a_addr(control_index),
+        .a_wdata(16'd0), .a_rdata(bank0_control_raw),
+        .b_en(1'b1), .b_we(bank0_write), .b_addr(bank_b_addr),
+        .b_wdata(bank_write_data), .b_rdata(bank0_snapshot_raw)
+    );
+    ef2_bram_dp #(.DATA_WIDTH(16), .ADDR_WIDTH(5), .DATA_DEPTH(27)) u_bank1 (
+        .clk(clk), .a_en(1'b1), .a_we(1'b0), .a_addr(control_index),
+        .a_wdata(16'd0), .a_rdata(bank1_control_raw),
+        .b_en(1'b1), .b_we(bank1_write), .b_addr(bank_b_addr),
+        .b_wdata(bank_write_data), .b_rdata(bank1_snapshot_raw)
+    );
 
 
     function [6:0] device_for;
     function [6:0] device_for;
         input [4:0] value;
         input [4:0] value;
@@ -70,20 +92,10 @@ module ct7428_snapshot #(
     endfunction
     endfunction
 
 
     always @* begin
     always @* begin
-        if (control_bank) begin
-            control_raw = bank1[control_index];
-            control_valid = valid1[control_index];
-        end else begin
-            control_raw = bank0[control_index];
-            control_valid = valid0[control_index];
-        end
-        if (snapshot_bank) begin
-            snapshot_raw = bank1[snapshot_index];
-            snapshot_valid = valid1[snapshot_index];
-        end else begin
-            snapshot_raw = bank0[snapshot_index];
-            snapshot_valid = valid0[snapshot_index];
-        end
+        control_raw = control_bank ? bank1_control_raw : bank0_control_raw;
+        control_valid = control_bank ? valid1[control_index] : valid0[control_index];
+        snapshot_raw = snapshot_bank ? bank1_snapshot_raw : bank0_snapshot_raw;
+        snapshot_valid = snapshot_bank ? valid1[snapshot_index] : valid0[snapshot_index];
     end
     end
 
 
     always @(posedge clk or negedge rst_n) begin
     always @(posedge clk or negedge rst_n) begin
@@ -100,11 +112,22 @@ module ct7428_snapshot #(
             active_bank <= 0;
             active_bank <= 0;
             valid0 <= 0;
             valid0 <= 0;
             valid1 <= 0;
             valid1 <= 0;
-            for (i = 0; i < 27; i = i + 1) begin bank0[i] <= 0; bank1[i] <= 0; end
+            init_active <= 1'b1;
+            init_index <= 5'd0;
         end else begin
         end else begin
             snapshot_commit <= 0;
             snapshot_commit <= 0;
-            if (tick_1s && age_seconds != 16'hffff) age_seconds <= age_seconds + 1'b1;
-            case (state)
+            if (init_active) begin
+                request_valid <= 1'b0;
+                if (init_index == 5'd26) begin
+                    init_active <= 1'b0;
+                    init_index <= 5'd0;
+                    state <= ST_START;
+                end else begin
+                    init_index <= init_index + 1'b1;
+                end
+            end else begin
+                if (tick_1s && age_seconds != 16'hffff) age_seconds <= age_seconds + 1'b1;
+                case (state)
                 ST_START: begin
                 ST_START: begin
                     index <= 0;
                     index <= 0;
                     if (!write_blocked) begin
                     if (!write_blocked) begin
@@ -123,10 +146,8 @@ module ct7428_snapshot #(
                 end
                 end
                 ST_RESPONSE: if (response_valid) begin
                 ST_RESPONSE: if (response_valid) begin
                     if (active_bank) begin
                     if (active_bank) begin
-                        bank0[index] <= response_data;
                         valid0[index] <= (response_error == 0);
                         valid0[index] <= (response_error == 0);
                     end else begin
                     end else begin
-                        bank1[index] <= response_data;
                         valid1[index] <= (response_error == 0);
                         valid1[index] <= (response_error == 0);
                     end
                     end
                     if (index == 26) begin
                     if (index == 26) begin
@@ -146,7 +167,8 @@ module ct7428_snapshot #(
                     state <= ST_START;
                     state <= ST_START;
                 end else wait_counter <= wait_counter + 1'b1;
                 end else wait_counter <= wait_counter + 1'b1;
                 default: state <= ST_START;
                 default: state <= ST_START;
-            endcase
+                endcase
+            end
         end
         end
     end
     end
 endmodule
 endmodule

+ 61 - 0
src/common/ef2_bram_dp.v

@@ -0,0 +1,61 @@
+`timescale 1ns/1ps
+
+// The only vendor-specific storage boundary in the 6400 RTL.  Normal
+// simulation/formal runs use the cycle-accurate behavioral model.  TD defines
+// PROD2U_TD_VENDOR_RAM and maps this wrapper to one EF2 9K true-dual-port RAM.
+module ef2_bram_dp #(
+    parameter integer DATA_WIDTH = 16,
+    parameter integer ADDR_WIDTH = 5,
+    parameter integer DATA_DEPTH = 32
+) (
+    input  wire                  clk,
+    input  wire                  a_en,
+    input  wire                  a_we,
+    input  wire [ADDR_WIDTH-1:0] a_addr,
+    input  wire [DATA_WIDTH-1:0] a_wdata,
+    output wire [DATA_WIDTH-1:0] a_rdata,
+    input  wire                  b_en,
+    input  wire                  b_we,
+    input  wire [ADDR_WIDTH-1:0] b_addr,
+    input  wire [DATA_WIDTH-1:0] b_wdata,
+    output wire [DATA_WIDTH-1:0] b_rdata
+);
+`ifdef PROD2U_TD_VENDOR_RAM
+    EF2_LOGIC_BRAM #(
+        .DATA_WIDTH_A(DATA_WIDTH), .DATA_WIDTH_B(DATA_WIDTH),
+        .ADDR_WIDTH_A(ADDR_WIDTH), .ADDR_WIDTH_B(ADDR_WIDTH),
+        .DATA_DEPTH_A(DATA_DEPTH), .DATA_DEPTH_B(DATA_DEPTH),
+        .BYTE_ENABLE(0), .BYTE_A(1), .BYTE_B(1),
+        .MODE("DP"), .REGMODE_A("NOREG"), .REGMODE_B("NOREG"),
+        .WRITEMODE_A("NORMAL"), .WRITEMODE_B("NORMAL"),
+        .RESETMODE("ASYNC"), .DEBUGGABLE("NO"), .PACKABLE("NO"),
+        .FORCE_KEEP("OFF"), .INIT_FILE("NONE"), .FILL_ALL("NONE"),
+        .IMPLEMENT("9K")
+    ) u_ram (
+        .dia(a_wdata), .addra(a_addr), .cea(a_en), .ocea(1'b1),
+        .clka(clk), .wea(a_we), .rsta(1'b0), .bea(1'b1),
+        .dib(b_wdata), .addrb(b_addr), .ceb(b_en), .oceb(1'b1),
+        .clkb(clk), .web(b_we), .rstb(1'b0), .beb(1'b1),
+        .doa(a_rdata), .dob(b_rdata)
+    );
+`else
+    reg [DATA_WIDTH-1:0] memory [0:DATA_DEPTH-1];
+    reg [DATA_WIDTH-1:0] a_rdata_reg;
+    reg [DATA_WIDTH-1:0] b_rdata_reg;
+    assign a_rdata = a_rdata_reg;
+    assign b_rdata = b_rdata_reg;
+
+    always @(posedge clk) begin
+        if (a_en) begin
+            a_rdata_reg <= memory[a_addr];
+            if (a_we)
+                memory[a_addr] <= a_wdata;
+        end
+        if (b_en) begin
+            b_rdata_reg <= memory[b_addr];
+            if (b_we)
+                memory[b_addr] <= b_wdata;
+        end
+    end
+`endif
+endmodule

+ 13 - 3
src/common/frame_tx.v

@@ -3,7 +3,9 @@
 module frame_tx #(
 module frame_tx #(
     // Width of payload byte index; 5 bits covers 0..31 (length 31 / temp 27).
     // Width of payload byte index; 5 bits covers 0..31 (length 31 / temp 27).
     parameter integer PAYLOAD_IDX_BITS = 5,
     parameter integer PAYLOAD_IDX_BITS = 5,
-    parameter integer EXTERNAL_CRC = 0
+    parameter integer EXTERNAL_CRC = 0,
+    // Set for payload sources backed by synchronous embedded RAM.
+    parameter integer PAYLOAD_READ_LATENCY = 0
 ) (
 ) (
     input  wire       clk,
     input  wire       clk,
     input  wire       rst_n,
     input  wire       rst_n,
@@ -35,6 +37,7 @@ module frame_tx #(
     localparam [3:0] ST_PAYLOAD_CRC_WAIT = 4'd8;
     localparam [3:0] ST_PAYLOAD_CRC_WAIT = 4'd8;
     localparam [3:0] ST_CRC_LOW = 4'd9;
     localparam [3:0] ST_CRC_LOW = 4'd9;
     localparam [3:0] ST_CRC_HIGH = 4'd10;
     localparam [3:0] ST_CRC_HIGH = 4'd10;
+    localparam [3:0] ST_PAYLOAD_FETCH = 4'd11;
 
 
     reg [3:0] state;
     reg [3:0] state;
     reg [7:0] type_reg;
     reg [7:0] type_reg;
@@ -115,17 +118,24 @@ module frame_tx #(
                     ST_TYPE_CRC_WAIT: state <= ST_LENGTH;
                     ST_TYPE_CRC_WAIT: state <= ST_LENGTH;
                     ST_LENGTH_CRC_WAIT: begin
                     ST_LENGTH_CRC_WAIT: begin
                         payload_index <= {PAYLOAD_IDX_BITS{1'b0}};
                         payload_index <= {PAYLOAD_IDX_BITS{1'b0}};
-                        state <= (length_reg == 0) ? ST_CRC_LOW : ST_PAYLOAD;
+                        state <= (length_reg == 0) ? ST_CRC_LOW :
+                            ((PAYLOAD_READ_LATENCY != 0) ? ST_PAYLOAD_FETCH : ST_PAYLOAD);
                     end
                     end
                     ST_PAYLOAD_CRC_WAIT: begin
                     ST_PAYLOAD_CRC_WAIT: begin
                         if (payload_index + 1 >= length_reg) state <= ST_CRC_LOW;
                         if (payload_index + 1 >= length_reg) state <= ST_CRC_LOW;
                         else begin
                         else begin
                             payload_index <= payload_index + 1'b1;
                             payload_index <= payload_index + 1'b1;
-                            state <= ST_PAYLOAD;
+                            state <= (PAYLOAD_READ_LATENCY != 0) ?
+                                ST_PAYLOAD_FETCH : ST_PAYLOAD;
                         end
                         end
                     end
                     end
                     default: begin end
                     default: begin end
                 endcase
                 endcase
+            end else if (state == ST_PAYLOAD_FETCH) begin
+                // Address has been visible for one full clock; the RAM output
+                // is now valid for the following payload launch cycle.
+                byte_valid <= 1'b0;
+                state <= ST_PAYLOAD;
             end else if ((state == ST_TYPE_CRC_WAIT) ||
             end else if ((state == ST_TYPE_CRC_WAIT) ||
                          (state == ST_LENGTH_CRC_WAIT) ||
                          (state == ST_LENGTH_CRC_WAIT) ||
                          (state == ST_PAYLOAD_CRC_WAIT)) begin
                          (state == ST_PAYLOAD_CRC_WAIT)) begin

+ 208 - 114
src/control/thermal_control_core.v

@@ -29,7 +29,7 @@ module thermal_control_core #(
     input  wire [15:0]  bmc_epoch,
     input  wire [15:0]  bmc_epoch,
     input  wire         bmc_stale,
     input  wire         bmc_stale,
     input  wire [23:0]  bmc_valid_mask,
     input  wire [23:0]  bmc_valid_mask,
-    output reg  [4:0]   bmc_rd_index,
+    output wire [4:0]   bmc_rd_index,
     input  wire [15:0]  bmc_rd_raw,
     input  wire [15:0]  bmc_rd_raw,
     input  wire         bmc_rd_valid,
     input  wire         bmc_rd_valid,
     input  wire [15:0]  ct_epoch,
     input  wire [15:0]  ct_epoch,
@@ -38,11 +38,11 @@ module thermal_control_core #(
     input  wire         snapshot_lock,
     input  wire         snapshot_lock,
     input  wire         snapshot_lock_bank,
     input  wire         snapshot_lock_bank,
     input  wire [4:0]   pwm_rd_addr,
     input  wire [4:0]   pwm_rd_addr,
-    output reg  [7:0]   pwm_rd_data,
+    output wire [7:0]   pwm_rd_data,
     input  wire         snapshot_output_bank,
     input  wire         snapshot_output_bank,
     input  wire [4:0]   snapshot_rd_addr,
     input  wire [4:0]   snapshot_rd_addr,
-    output reg  [7:0]   snapshot_requested_data,
-    output reg  [7:0]   snapshot_applied_data,
+    output wire [7:0]   snapshot_requested_data,
+    output wire [7:0]   snapshot_applied_data,
     output reg          active_output_bank,
     output reg          active_output_bank,
     output reg [2:0]    control_state,
     output reg [2:0]    control_state,
     output reg [7:0]    current_target_celsius,
     output reg [7:0]    current_target_celsius,
@@ -70,6 +70,8 @@ module thermal_control_core #(
     localparam [3:0] W_FANS = 4'd5;
     localparam [3:0] W_FANS = 4'd5;
     localparam [3:0] W_APPLY = 4'd6;
     localparam [3:0] W_APPLY = 4'd6;
     localparam [3:0] W_SAFE_FILL = 4'd7;
     localparam [3:0] W_SAFE_FILL = 4'd7;
+    localparam [3:0] W_APPLY_PREFETCH = 4'd8;
+    localparam [3:0] W_INIT = 4'd9;
 
 
     reg [3:0] work_state;
     reg [3:0] work_state;
     reg [4:0] work_index;
     reg [4:0] work_index;
@@ -82,12 +84,6 @@ module thermal_control_core #(
     reg [2:0] invalid_count2;
     reg [2:0] invalid_count2;
     reg [2:0] invalid_count3;
     reg [2:0] invalid_count3;
     reg [15:0] target_centi;
     reg [15:0] target_centi;
-    reg [7:0] req0 [0:31];
-    reg [7:0] req1 [0:31];
-    reg [7:0] app0 [0:31];
-    reg [7:0] app1 [0:31];
-    reg signed [15:0] previous_error [0:23];
-    reg signed [15:0] previous_output [0:23];
     reg [7:0] stimulus_mem [0:31];
     reg [7:0] stimulus_mem [0:31];
     reg stimulus_running;
     reg stimulus_running;
     reg [7:0] stimulus_remaining;
     reg [7:0] stimulus_remaining;
@@ -105,6 +101,17 @@ module thermal_control_core #(
     reg signed [31:0] ki_product;
     reg signed [31:0] ki_product;
     integer i;
     integer i;
 
 
+`ifdef FORMAL
+    // Proof-only mirrors preserve arbitrary-index invariants without adding
+    // any storage to TD synthesis.
+    reg [7:0] formal_req0 [0:31];
+    reg [7:0] formal_req1 [0:31];
+    reg [7:0] formal_app0 [0:31];
+    reg [7:0] formal_app1 [0:31];
+    reg signed [15:0] formal_previous_error [0:23];
+    reg signed [15:0] formal_previous_output [0:23];
+`endif
+
     wire [15:0] bmc_integer_scaled = ({8'd0, bmc_rd_raw[15:8]} << 6) +
     wire [15:0] bmc_integer_scaled = ({8'd0, bmc_rd_raw[15:8]} << 6) +
         ({8'd0, bmc_rd_raw[15:8]} << 5) + ({8'd0, bmc_rd_raw[15:8]} << 2);
         ({8'd0, bmc_rd_raw[15:8]} << 5) + ({8'd0, bmc_rd_raw[15:8]} << 2);
     wire signed [15:0] bmc_temperature = $signed(bmc_integer_scaled + {8'd0, bmc_rd_raw[7:0]});
     wire signed [15:0] bmc_temperature = $signed(bmc_integer_scaled + {8'd0, bmc_rd_raw[7:0]});
@@ -114,19 +121,36 @@ module thermal_control_core #(
     wire signed [15:0] selected_ki = edge_channel ? EDGE_KI : CENTER_KI;
     wire signed [15:0] selected_ki = edge_channel ? EDGE_KI : CENTER_KI;
     reg signed [15:0] mult_a;
     reg signed [15:0] mult_a;
     reg signed [15:0] mult_b;
     reg signed [15:0] mult_b;
+    wire [31:0] pi_state_read;
+    wire signed [15:0] pi_previous_error_ram = pi_state_read[31:16];
+    wire signed [15:0] pi_previous_output_ram = pi_state_read[15:0];
+    wire [7:0] output_control_requested_ram;
+    wire [7:0] output_pwm_applied;
+    wire [31:0] pi_state_write_port_read_unused;
+`ifdef FORMAL
+    // The proof mirrors are the inductive abstraction of the synchronous RAM
+    // contents.  Simulation and TD use the physical RAM read ports below.
+    wire signed [15:0] pi_previous_error = formal_previous_error[work_index];
+    wire signed [15:0] pi_previous_output = formal_previous_output[work_index];
+    wire [7:0] output_control_requested = active_output_bank ?
+        formal_req0[work_index] : formal_req1[work_index];
+`else
+    wire signed [15:0] pi_previous_error = pi_previous_error_ram;
+    wire signed [15:0] pi_previous_output = pi_previous_output_ram;
+    wire [7:0] output_control_requested = output_control_requested_ram;
+`endif
     wire signed [31:0] mult_result = mult_a * mult_b;
     wire signed [31:0] mult_result = mult_a * mult_b;
     wire signed [31:0] pi_sum = kp_product + ki_product;
     wire signed [31:0] pi_sum = kp_product + ki_product;
     wire signed [31:0] pi_delta = (pi_sum >= 0) ? ((pi_sum + 8) >>> 4) : -(((-pi_sum) + 8) >>> 4);
     wire signed [31:0] pi_delta = (pi_sum >= 0) ? ((pi_sum + 8) >>> 4) : -(((-pi_sum) + 8) >>> 4);
-    wire signed [31:0] previous_output_ext = {{16{previous_output[work_index][15]}}, previous_output[work_index]};
+    wire signed [31:0] previous_output_ext = {{16{pi_previous_output[15]}}, pi_previous_output};
     wire signed [31:0] pi_candidate = previous_output_ext + pi_delta;
     wire signed [31:0] pi_candidate = previous_output_ext + pi_delta;
     wire signed [31:0] slew_low = previous_output_ext - SLEW_Q8_8;
     wire signed [31:0] slew_low = previous_output_ext - SLEW_Q8_8;
     wire signed [31:0] slew_high = previous_output_ext + SLEW_Q8_8;
     wire signed [31:0] slew_high = previous_output_ext + SLEW_Q8_8;
     wire signed [31:0] slew_candidate = (pi_candidate < slew_low) ? slew_low : ((pi_candidate > slew_high) ? slew_high : pi_candidate);
     wire signed [31:0] slew_candidate = (pi_candidate < slew_low) ? slew_low : ((pi_candidate > slew_high) ? slew_high : pi_candidate);
     wire signed [15:0] clamped_output = (slew_candidate < 0) ? 16'sd0 : ((slew_candidate > 25600) ? 16'sd25600 : slew_candidate[15:0]);
     wire signed [15:0] clamped_output = (slew_candidate < 0) ? 16'sd0 : ((slew_candidate > 25600) ? 16'sd25600 : slew_candidate[15:0]);
-    wire signed [15:0] reduced_output = previous_output[work_index] - 16'sd256;
+    wire signed [15:0] reduced_output = pi_previous_output - 16'sd256;
     wire [7:0] clamped_duty = (clamped_output >= 16'sd25600) ? 8'd100 : q8_8_to_duty(clamped_output);
     wire [7:0] clamped_duty = (clamped_output >= 16'sd25600) ? 8'd100 : q8_8_to_duty(clamped_output);
-    wire [7:0] reduced_duty = (previous_output[work_index] > 16'sd256) ? q8_8_to_duty(reduced_output) : 8'd0;
-    wire [7:0] inactive_request = active_output_bank ? req0[work_index] : req1[work_index];
+    wire [7:0] reduced_duty = (pi_previous_output > 16'sd256) ? q8_8_to_duty(reduced_output) : 8'd0;
     wire signed [15:0] recovery_threshold = $signed(target_centi) + RECOVERY_MARGIN;
     wire signed [15:0] recovery_threshold = $signed(target_centi) + RECOVERY_MARGIN;
 
 
     assign stimulus_active = stimulus_running;
     assign stimulus_active = stimulus_running;
@@ -200,11 +224,11 @@ module thermal_control_core #(
         (global_fault || control_state == STOPPED ||
         (global_fault || control_state == STOPPED ||
          lane_fault_for_output(work_index) ||
          lane_fault_for_output(work_index) ||
          lane_invalid(lane_for_channel(work_index)) ||
          lane_invalid(lane_for_channel(work_index)) ||
-         ptc_shutdown_mask[work_index]) ? 8'd0 : inactive_request;
+         ptc_shutdown_mask[work_index]) ? 8'd0 : output_control_requested;
     wire [7:0] apply_fan_value =
     wire [7:0] apply_fan_value =
         (global_fault || lane_fault_for_output(work_index) ||
         (global_fault || lane_fault_for_output(work_index) ||
          lane_invalid(lane_for_output(work_index))) ? 8'd100 :
          lane_invalid(lane_for_output(work_index))) ? 8'd100 :
-        (lane_thermal_protection(lane_for_output(work_index)) ? 8'd80 : inactive_request);
+        (lane_thermal_protection(lane_for_output(work_index)) ? 8'd80 : output_control_requested);
     wire [7:0] safe_fill_value = (work_index < 24) ? 8'd0 :
     wire [7:0] safe_fill_value = (work_index < 24) ? 8'd0 :
         ((global_fault || lane_fault_for_output(work_index) ||
         ((global_fault || lane_fault_for_output(work_index) ||
           lane_invalid(lane_for_output(work_index))) ? 8'd100 :
           lane_invalid(lane_for_output(work_index))) ? 8'd100 :
@@ -214,24 +238,77 @@ module thermal_control_core #(
     // must still run before BMC stability is evaluated.
     // must still run before BMC stability is evaluated.
     wire bmc_stale_runtime = bmc_stale &&
     wire bmc_stale_runtime = bmc_stale &&
         (control_state == AUTO_BMC || control_state == SENSOR_DEGRADED);
         (control_state == AUTO_BMC || control_state == SENSOR_DEGRADED);
+    wire update_fault_clear = work_state == W_UPDATE && sample_valid &&
+        ((sample_temperature >= PRETRIP_LIMIT) || global_fault ||
+         lane_fault_for_output(work_index));
+    wire update_soft = work_state == W_UPDATE && sample_valid &&
+        !update_fault_clear && (sample_temperature >= SOFT_LIMIT);
+    wire update_normal = work_state == W_UPDATE && sample_valid &&
+        !update_fault_clear && !update_soft && !stimulus_running;
+    wire pi_clear_write = (work_state == W_INIT || work_state == W_SAFE_FILL) &&
+        (work_index < 24);
+    wire pi_state_write = pi_clear_write || update_fault_clear || update_soft || update_normal;
+    wire [31:0] pi_state_write_data = pi_clear_write || update_fault_clear ? 32'd0 :
+        (update_soft ? {sample_error, (pi_previous_output > 16'sd256 ? reduced_output : 16'sd0)} :
+                       {sample_error, clamped_output});
+
+    wire [7:0] update_request_value = !sample_valid ? 8'd0 :
+        ((sample_temperature >= PRETRIP_LIMIT) || global_fault ||
+         lane_fault_for_output(work_index)) ? 8'd0 :
+        (sample_temperature >= SOFT_LIMIT) ? reduced_duty :
+        stimulus_running ? stimulus_mem[work_index] : clamped_duty;
+    wire [7:0] fan_request_value = stimulus_running ? stimulus_mem[work_index] : 8'd30;
+    wire output_init_write = work_state == W_INIT;
+    wire output_control_write = work_state == W_UPDATE || work_state == W_FANS ||
+        work_state == W_APPLY || work_state == W_SAFE_FILL;
+    wire [7:0] apply_value = (work_index < 24) ? apply_ptc_value : apply_fan_value;
+    wire [15:0] output_control_write_data =
+        (work_state == W_UPDATE) ? {update_request_value, 8'd0} :
+        (work_state == W_FANS) ? {fan_request_value, 8'd0} :
+        (work_state == W_APPLY) ? {output_control_requested, apply_value} :
+        {safe_fill_value, safe_fill_value};
+    wire [4:0] output_control_read_addr =
+        (work_state == W_APPLY_PREFETCH) ? 5'd0 :
+        ((work_state == W_APPLY && work_index < 31) ? work_index + 1'b1 : work_index);
+    wire [7:0] init_output_value = (work_index < 24) ? 8'd0 : 8'd10;
+
+    assign bmc_rd_index = work_index;
+    assign pwm_rd_data = (work_state == W_INIT) ?
+        ((pwm_rd_addr < 24) ? 8'd0 : 8'd10) : output_pwm_applied;
+
+    ef2_bram_dp #(.DATA_WIDTH(32), .ADDR_WIDTH(5), .DATA_DEPTH(24)) u_pi_state (
+        .clk(clk), .a_en(1'b1), .a_we(1'b0), .a_addr(work_index),
+        .a_wdata(32'd0), .a_rdata(pi_state_read),
+        .b_en(1'b1), .b_we(pi_state_write), .b_addr(work_index),
+        .b_wdata(pi_state_write_data), .b_rdata(pi_state_write_port_read_unused)
+    );
+
+    thermal_output_banks u_output_banks (
+        .clk(clk), .active_bank(active_output_bank),
+        .init_write(output_init_write), .init_addr(work_index),
+        .init_data({init_output_value, init_output_value}),
+        .control_bank(~active_output_bank),
+        .control_read_addr(output_control_read_addr),
+        .control_write(output_control_write), .control_write_addr(work_index),
+        .control_write_data(output_control_write_data),
+        .pwm_addr(pwm_rd_addr), .pwm_applied(output_pwm_applied),
+        .snapshot_bank(snapshot_output_bank), .snapshot_addr(snapshot_rd_addr),
+        .snapshot_requested(snapshot_requested_data), .snapshot_applied(snapshot_applied_data),
+        .control_requested(output_control_requested_ram)
+    );
+
+    wire unused_pi_write_port_read = &{1'b0, pi_state_write_port_read_unused};
 
 
     always @* begin
     always @* begin
         mult_a = 0;
         mult_a = 0;
         mult_b = 0;
         mult_b = 0;
         if (work_state == W_KP) begin
         if (work_state == W_KP) begin
-            mult_a = live_error - previous_error[work_index[4:0]];
+            mult_a = live_error - pi_previous_error;
             mult_b = selected_kp;
             mult_b = selected_kp;
         end else if (work_state == W_KI) begin
         end else if (work_state == W_KI) begin
             mult_a = sample_error;
             mult_a = sample_error;
             mult_b = selected_ki;
             mult_b = selected_ki;
         end
         end
-        if (snapshot_output_bank) begin
-            snapshot_requested_data = req1[snapshot_rd_addr];
-            snapshot_applied_data = app1[snapshot_rd_addr];
-        end else begin
-            snapshot_requested_data = req0[snapshot_rd_addr];
-            snapshot_applied_data = app0[snapshot_rd_addr];
-        end
     end
     end
 
 
     always @(posedge clk or negedge rst_n) begin
     always @(posedge clk or negedge rst_n) begin
@@ -248,10 +325,8 @@ module thermal_control_core #(
             lane_fault_mask <= 0;
             lane_fault_mask <= 0;
             global_fault <= 0;
             global_fault <= 0;
             output_commit <= 0;
             output_commit <= 0;
-            pwm_rd_data <= 0;
-            work_state <= W_IDLE;
+            work_state <= W_INIT;
             work_index <= 0;
             work_index <= 0;
-            bmc_rd_index <= 0;
             last_bmc_epoch <= 0;
             last_bmc_epoch <= 0;
             last_ct_epoch <= 0;
             last_ct_epoch <= 0;
             stable_epochs <= 0;
             stable_epochs <= 0;
@@ -269,22 +344,42 @@ module thermal_control_core #(
             kp_product <= 0;
             kp_product <= 0;
             ki_product <= 0;
             ki_product <= 0;
             for (i = 0; i < 32; i = i + 1) begin
             for (i = 0; i < 32; i = i + 1) begin
-                req0[i] <= (i < 24) ? 0 : 10;
-                req1[i] <= (i < 24) ? 0 : 10;
-                app0[i] <= (i < 24) ? 0 : 10;
-                app1[i] <= (i < 24) ? 0 : 10;
                 stimulus_mem[i] <= 0;
                 stimulus_mem[i] <= 0;
+`ifdef FORMAL
+                formal_req0[i] <= (i < 24) ? 0 : 10;
+                formal_req1[i] <= (i < 24) ? 0 : 10;
+                formal_app0[i] <= (i < 24) ? 0 : 10;
+                formal_app1[i] <= (i < 24) ? 0 : 10;
+`endif
             end
             end
+`ifdef FORMAL
             for (i = 0; i < 24; i = i + 1) begin
             for (i = 0; i < 24; i = i + 1) begin
-                previous_error[i] <= 0;
-                previous_output[i] <= 0;
+                formal_previous_error[i] <= 0;
+                formal_previous_output[i] <= 0;
             end
             end
+`endif
         end else begin
         end else begin
             output_commit <= 0;
             output_commit <= 0;
-            if (active_output_bank)
-                pwm_rd_data <= app1[pwm_rd_addr];
-            else
-                pwm_rd_data <= app0[pwm_rd_addr];
+`ifdef FORMAL
+            if (output_init_write) begin
+                formal_req0[work_index] <= init_output_value;
+                formal_req1[work_index] <= init_output_value;
+                formal_app0[work_index] <= init_output_value;
+                formal_app1[work_index] <= init_output_value;
+            end else if (output_control_write) begin
+                if (active_output_bank) begin
+                    formal_req0[work_index] <= output_control_write_data[15:8];
+                    formal_app0[work_index] <= output_control_write_data[7:0];
+                end else begin
+                    formal_req1[work_index] <= output_control_write_data[15:8];
+                    formal_app1[work_index] <= output_control_write_data[7:0];
+                end
+            end
+            if (pi_state_write) begin
+                formal_previous_error[work_index] <= pi_state_write_data[31:16];
+                formal_previous_output[work_index] <= pi_state_write_data[15:0];
+            end
+`endif
             if (stimulus_wr_en && (ENABLE_STIMULUS != 0))
             if (stimulus_wr_en && (ENABLE_STIMULUS != 0))
                 stimulus_mem[stimulus_wr_addr] <= stimulus_wr_data;
                 stimulus_mem[stimulus_wr_addr] <= stimulus_wr_data;
             if (stimulus_commit && (ENABLE_STIMULUS != 0) && stimulus_duration_seconds != 0) begin
             if (stimulus_commit && (ENABLE_STIMULUS != 0) && stimulus_duration_seconds != 0) begin
@@ -298,7 +393,7 @@ module thermal_control_core #(
                 end else stimulus_remaining <= stimulus_remaining - 1'b1;
                 end else stimulus_remaining <= stimulus_remaining - 1'b1;
             end
             end
 
 
-            if (target_commit) begin
+            if (target_commit && work_state != W_INIT) begin
                 current_target_celsius <= target_celsius;
                 current_target_celsius <= target_celsius;
                 target_centi <= ({8'd0, target_celsius} << 6) +
                 target_centi <= ({8'd0, target_celsius} << 6) +
                     ({8'd0, target_celsius} << 5) + ({8'd0, target_celsius} << 2);
                     ({8'd0, target_celsius} << 5) + ({8'd0, target_celsius} << 2);
@@ -316,10 +411,6 @@ module thermal_control_core #(
                     control_state <= SENSOR_DEGRADED;
                     control_state <= SENSOR_DEGRADED;
                 else
                 else
                     control_state <= WAIT_CT_VALID;
                     control_state <= WAIT_CT_VALID;
-                for (i = 0; i < 24; i = i + 1) begin
-                    previous_error[i] <= 0;
-                    previous_output[i] <= 0;
-                end
             end else if (bmc_stale_runtime && !global_fault) begin
             end else if (bmc_stale_runtime && !global_fault) begin
                 global_fault <= 1;
                 global_fault <= 1;
                 control_state <= SENSOR_DEGRADED;
                 control_state <= SENSOR_DEGRADED;
@@ -330,6 +421,14 @@ module thermal_control_core #(
                 stimulus_running <= 0;
                 stimulus_running <= 0;
             end else begin
             end else begin
                 case (work_state)
                 case (work_state)
+                    W_INIT: begin
+                        if (work_index == 31) begin
+                            work_index <= 0;
+                            work_state <= W_IDLE;
+                        end else begin
+                            work_index <= work_index + 1'b1;
+                        end
+                    end
                     W_IDLE: begin
                     W_IDLE: begin
                         if (control_state == RESET_SAFE) begin
                         if (control_state == RESET_SAFE) begin
                             control_state <= WAIT_CT_VALID;
                             control_state <= WAIT_CT_VALID;
@@ -365,7 +464,6 @@ module thermal_control_core #(
                         end
                         end
                     end
                     end
                     W_PREP: begin
                     W_PREP: begin
-                        bmc_rd_index <= work_index;
                         if (work_index == 0) begin
                         if (work_index == 0) begin
                             epoch_safe <= 1;
                             epoch_safe <= 1;
                             invalid_count0 <= 0;
                             invalid_count0 <= 0;
@@ -388,7 +486,6 @@ module thermal_control_core #(
                     end
                     end
                     W_UPDATE: begin
                     W_UPDATE: begin
                         if (!sample_valid) begin
                         if (!sample_valid) begin
-                            if (active_output_bank) begin req0[work_index] <= 0; end else begin req1[work_index] <= 0; end
                             safety_override_mask[work_index] <= 1;
                             safety_override_mask[work_index] <= 1;
                             ptc_shutdown_mask[work_index] <= 1;
                             ptc_shutdown_mask[work_index] <= 1;
                             thermal_protection_mask[work_index] <= 0;
                             thermal_protection_mask[work_index] <= 0;
@@ -406,23 +503,17 @@ module thermal_control_core #(
                                 3: invalid_count3 <= invalid_count3 + 1'b1;
                                 3: invalid_count3 <= invalid_count3 + 1'b1;
                             endcase
                             endcase
                         end else if (sample_temperature >= HARD_LIMIT) begin
                         end else if (sample_temperature >= HARD_LIMIT) begin
-                            if (active_output_bank) req0[work_index] <= 0; else req1[work_index] <= 0;
                             safety_override_mask[work_index] <= 1;
                             safety_override_mask[work_index] <= 1;
                             ptc_shutdown_mask[work_index] <= 1;
                             ptc_shutdown_mask[work_index] <= 1;
                             thermal_protection_mask[work_index] <= 1;
                             thermal_protection_mask[work_index] <= 1;
-                            previous_error[work_index] <= 0;
-                            previous_output[work_index] <= 0;
                             lane_fault_mask[lane_for_channel(work_index)] <= 1;
                             lane_fault_mask[lane_for_channel(work_index)] <= 1;
                             epoch_safe <= 0;
                             epoch_safe <= 0;
                             control_state <= SENSOR_DEGRADED;
                             control_state <= SENSOR_DEGRADED;
                             stimulus_running <= 0;
                             stimulus_running <= 0;
                         end else if (sample_temperature >= PRETRIP_LIMIT) begin
                         end else if (sample_temperature >= PRETRIP_LIMIT) begin
-                            if (active_output_bank) req0[work_index] <= 0; else req1[work_index] <= 0;
                             safety_override_mask[work_index] <= 1;
                             safety_override_mask[work_index] <= 1;
                             ptc_shutdown_mask[work_index] <= 1;
                             ptc_shutdown_mask[work_index] <= 1;
                             thermal_protection_mask[work_index] <= 1;
                             thermal_protection_mask[work_index] <= 1;
-                            previous_error[work_index] <= 0;
-                            previous_output[work_index] <= 0;
                             epoch_safe <= 0;
                             epoch_safe <= 0;
                             control_state <= SENSOR_DEGRADED;
                             control_state <= SENSOR_DEGRADED;
                         end else if (global_fault || lane_fault_for_output(work_index)) begin
                         end else if (global_fault || lane_fault_for_output(work_index)) begin
@@ -430,36 +521,23 @@ module thermal_control_core #(
                             // state.  Otherwise recovery could expose duty that
                             // state.  Otherwise recovery could expose duty that
                             // accumulated while the physical output was forced
                             // accumulated while the physical output was forced
                             // off, violating bumpless limited-duty restart.
                             // off, violating bumpless limited-duty restart.
-                            if (active_output_bank) req0[work_index] <= 0; else req1[work_index] <= 0;
                             safety_override_mask[work_index] <= 0;
                             safety_override_mask[work_index] <= 0;
                             ptc_shutdown_mask[work_index] <= 0;
                             ptc_shutdown_mask[work_index] <= 0;
                             thermal_protection_mask[work_index] <= 0;
                             thermal_protection_mask[work_index] <= 0;
-                            previous_error[work_index] <= 0;
-                            previous_output[work_index] <= 0;
                         end else begin
                         end else begin
                             // Safety precedes identification stimulus.  The
                             // Safety precedes identification stimulus.  The
                             // soft limit reduces the autonomous PI state by
                             // soft limit reduces the autonomous PI state by
                             // one duty point and requests protection airflow,
                             // one duty point and requests protection airflow,
                             // but deliberately does not assert PTC shutdown.
                             // but deliberately does not assert PTC shutdown.
                             if (sample_temperature >= SOFT_LIMIT) begin
                             if (sample_temperature >= SOFT_LIMIT) begin
-                                if (active_output_bank)
-                                    req0[work_index] <= reduced_duty;
-                                else
-                                    req1[work_index] <= reduced_duty;
-                                if (previous_output[work_index] > 16'sd256) previous_output[work_index] <= previous_output[work_index] - 16'sd256; else previous_output[work_index] <= 0;
-                                previous_error[work_index] <= sample_error;
                                 safety_override_mask[work_index] <= 1;
                                 safety_override_mask[work_index] <= 1;
                                 ptc_shutdown_mask[work_index] <= 0;
                                 ptc_shutdown_mask[work_index] <= 0;
                                 thermal_protection_mask[work_index] <= 1;
                                 thermal_protection_mask[work_index] <= 1;
                             end else if (stimulus_running) begin
                             end else if (stimulus_running) begin
-                                if (active_output_bank) req0[work_index] <= stimulus_mem[work_index]; else req1[work_index] <= stimulus_mem[work_index];
                                 safety_override_mask[work_index] <= 0;
                                 safety_override_mask[work_index] <= 0;
                                 ptc_shutdown_mask[work_index] <= 0;
                                 ptc_shutdown_mask[work_index] <= 0;
                                 thermal_protection_mask[work_index] <= 0;
                                 thermal_protection_mask[work_index] <= 0;
                             end else begin
                             end else begin
-                                if (active_output_bank) req0[work_index] <= clamped_duty; else req1[work_index] <= clamped_duty;
-                                previous_output[work_index] <= clamped_output;
-                                previous_error[work_index] <= sample_error;
                                 safety_override_mask[work_index] <= 0;
                                 safety_override_mask[work_index] <= 0;
                                 ptc_shutdown_mask[work_index] <= 0;
                                 ptc_shutdown_mask[work_index] <= 0;
                                 thermal_protection_mask[work_index] <= 0;
                                 thermal_protection_mask[work_index] <= 0;
@@ -485,25 +563,14 @@ module thermal_control_core #(
                         end
                         end
                     end
                     end
                     W_FANS: begin
                     W_FANS: begin
-                        if (active_output_bank)
-                            req0[work_index] <= stimulus_running ? stimulus_mem[work_index] : 8'd30;
-                        else
-                            req1[work_index] <= stimulus_running ? stimulus_mem[work_index] : 8'd30;
-                        if (work_index == 31) begin work_index <= 0; work_state <= W_APPLY; end
+                        if (work_index == 31) begin
+                            work_index <= 0;
+                            work_state <= W_APPLY_PREFETCH;
+                        end
                         else work_index <= work_index + 1'b1;
                         else work_index <= work_index + 1'b1;
                     end
                     end
+                    W_APPLY_PREFETCH: work_state <= W_APPLY;
                     W_APPLY: begin
                     W_APPLY: begin
-                        if (active_output_bank) begin
-                            if (work_index < 24)
-                                app0[work_index] <= apply_ptc_value;
-                            else
-                                app0[work_index] <= apply_fan_value;
-                        end else begin
-                            if (work_index < 24)
-                                app1[work_index] <= apply_ptc_value;
-                            else
-                                app1[work_index] <= apply_fan_value;
-                        end
                         if (work_index == 31) begin
                         if (work_index == 31) begin
                             active_output_bank <= ~active_output_bank;
                             active_output_bank <= ~active_output_bank;
                             control_epoch <= control_epoch + 1'b1;
                             control_epoch <= control_epoch + 1'b1;
@@ -513,13 +580,6 @@ module thermal_control_core #(
                         end else work_index <= work_index + 1'b1;
                         end else work_index <= work_index + 1'b1;
                     end
                     end
                     W_SAFE_FILL: begin
                     W_SAFE_FILL: begin
-                        if (active_output_bank) begin
-                            req0[work_index] <= safe_fill_value;
-                            app0[work_index] <= safe_fill_value;
-                        end else begin
-                            req1[work_index] <= safe_fill_value;
-                            app1[work_index] <= safe_fill_value;
-                        end
                         if (work_index == 31) begin
                         if (work_index == 31) begin
                             active_output_bank <= ~active_output_bank;
                             active_output_bank <= ~active_output_bank;
                             control_epoch <= control_epoch + 1'b1;
                             control_epoch <= control_epoch + 1'b1;
@@ -540,9 +600,9 @@ module thermal_control_core #(
     (* anyconst *) reg [4:0] formal_ptc_index;
     (* anyconst *) reg [4:0] formal_ptc_index;
 
 
     wire [7:0] formal_active_applied = active_output_bank ?
     wire [7:0] formal_active_applied = active_output_bank ?
-        app1[formal_duty_index] : app0[formal_duty_index];
+        formal_app1[formal_duty_index] : formal_app0[formal_duty_index];
     wire [7:0] formal_inactive_applied = active_output_bank ?
     wire [7:0] formal_inactive_applied = active_output_bank ?
-        app0[formal_duty_index] : app1[formal_duty_index];
+        formal_app0[formal_duty_index] : formal_app1[formal_duty_index];
     wire [7:0] formal_safe_fill_value = (formal_duty_index < 24) ? 8'd0 :
     wire [7:0] formal_safe_fill_value = (formal_duty_index < 24) ? 8'd0 :
         ((global_fault || lane_fault_for_output(formal_duty_index) ||
         ((global_fault || lane_fault_for_output(formal_duty_index) ||
           lane_invalid(lane_for_output(formal_duty_index))) ?
           lane_invalid(lane_for_output(formal_duty_index))) ?
@@ -561,8 +621,10 @@ module thermal_control_core #(
                 W_KI:        formal_work_rank = 8'd134 - ({3'd0, index_value} << 2);
                 W_KI:        formal_work_rank = 8'd134 - ({3'd0, index_value} << 2);
                 W_UPDATE:    formal_work_rank = 8'd133 - ({3'd0, index_value} << 2);
                 W_UPDATE:    formal_work_rank = 8'd133 - ({3'd0, index_value} << 2);
                 W_FANS:      formal_work_rank = 8'd64 - index_value;
                 W_FANS:      formal_work_rank = 8'd64 - index_value;
-                W_APPLY:     formal_work_rank = 8'd32 - index_value;
+                W_APPLY_PREFETCH: formal_work_rank = 8'd32;
+                W_APPLY:     formal_work_rank = 8'd31 - index_value;
                 W_SAFE_FILL: formal_work_rank = 8'd64 - index_value;
                 W_SAFE_FILL: formal_work_rank = 8'd64 - index_value;
+                W_INIT:      formal_work_rank = 8'd32 - index_value;
                 default:     formal_work_rank = 8'd0;
                 default:     formal_work_rank = 8'd0;
             endcase
             endcase
         end
         end
@@ -580,10 +642,10 @@ module thermal_control_core #(
         assume(formal_ptc_index < 24);
         assume(formal_ptc_index < 24);
 
 
         // P01: every requested and applied logical duty remains in 0..100.
         // P01: every requested and applied logical duty remains in 0..100.
-        assert(req0[formal_duty_index] <= 100);
-        assert(req1[formal_duty_index] <= 100);
-        assert(app0[formal_duty_index] <= 100);
-        assert(app1[formal_duty_index] <= 100);
+        assert(formal_req0[formal_duty_index] <= 100);
+        assert(formal_req1[formal_duty_index] <= 100);
+        assert(formal_app0[formal_duty_index] <= 100);
+        assert(formal_app1[formal_duty_index] <= 100);
         assert(stimulus_mem[formal_duty_index] <= 100);
         assert(stimulus_mem[formal_duty_index] <= 100);
         assert(safe_fan_target <= 100);
         assert(safe_fan_target <= 100);
         assert(control_state <= STOPPED);
         assert(control_state <= STOPPED);
@@ -591,8 +653,8 @@ module thermal_control_core #(
                (current_target_celsius >= 20 && current_target_celsius <= 70));
                (current_target_celsius >= 20 && current_target_celsius <= 70));
         assert(target_centi <= 16'd7000);
         assert(target_centi <= 16'd7000);
         if (formal_duty_index < 24) begin
         if (formal_duty_index < 24) begin
-            assert(previous_output[formal_duty_index] >= 0);
-            assert(previous_output[formal_duty_index] <= 25600);
+            assert(formal_previous_output[formal_duty_index] >= 0);
+            assert(formal_previous_output[formal_duty_index] <= 25600);
         end
         end
 
 
         if (!rst_n) begin
         if (!rst_n) begin
@@ -605,22 +667,54 @@ module thermal_control_core #(
             assert(lane_fault_mask == 0);
             assert(lane_fault_mask == 0);
             assert(!global_fault);
             assert(!global_fault);
             if (formal_duty_index < 24) begin
             if (formal_duty_index < 24) begin
-                assert(app0[formal_duty_index] == 0);
-                assert(app1[formal_duty_index] == 0);
+                assert(formal_app0[formal_duty_index] == 0);
+                assert(formal_app1[formal_duty_index] == 0);
             end else begin
             end else begin
-                assert(app0[formal_duty_index] == 10);
-                assert(app1[formal_duty_index] == 10);
+                assert(formal_app0[formal_duty_index] == 10);
+                assert(formal_app1[formal_duty_index] == 10);
             end
             end
         end else begin
         end else begin
             // P10: an admitted scheduler pass has a finite rank that strictly
             // P10: an admitted scheduler pass has a finite rank that strictly
             // decreases every clock unless target/stale safety preempts it.
             // decreases every clock unless target/stale safety preempts it.
             assert(formal_scheduler_rank <= 136);
             assert(formal_scheduler_rank <= 136);
-            assert(work_state <= W_SAFE_FILL);
+            assert(work_state <= W_INIT);
             if (work_state == W_PREP || work_state == W_KP ||
             if (work_state == W_PREP || work_state == W_KP ||
                 work_state == W_KI || work_state == W_UPDATE)
                 work_state == W_KI || work_state == W_UPDATE)
                 assert(work_index < 24);
                 assert(work_index < 24);
             if (work_state == W_FANS)
             if (work_state == W_FANS)
                 assert(work_index >= 24);
                 assert(work_index >= 24);
+            if (work_state == W_APPLY_PREFETCH)
+                assert(work_index == 0);
+            // W_INIT is reachable only from reset.  Its prefix invariants make
+            // the deterministic RAM scrub inductive even when the solver
+            // starts an induction window in the middle of that sweep.
+            if (work_state == W_INIT) begin
+                assert(control_state == RESET_SAFE);
+                assert(safety_override_mask == 0);
+                assert(ptc_shutdown_mask == 0);
+                assert(thermal_protection_mask == 0);
+                assert(lane_fault_mask == 0);
+                assert(!global_fault);
+                assert(invalid_count0 == 0);
+                assert(invalid_count1 == 0);
+                assert(invalid_count2 == 0);
+                assert(invalid_count3 == 0);
+                if (formal_duty_index < work_index) begin
+                    if (formal_duty_index < 24) begin
+                        assert(formal_req0[formal_duty_index] == 0);
+                        assert(formal_req1[formal_duty_index] == 0);
+                        assert(formal_app0[formal_duty_index] == 0);
+                        assert(formal_app1[formal_duty_index] == 0);
+                        assert(formal_previous_error[formal_duty_index] == 0);
+                        assert(formal_previous_output[formal_duty_index] == 0);
+                    end else begin
+                        assert(formal_req0[formal_duty_index] == 10);
+                        assert(formal_req1[formal_duty_index] == 10);
+                        assert(formal_app0[formal_duty_index] == 10);
+                        assert(formal_app1[formal_duty_index] == 10);
+                    end
+                end
+            end
             // Reset-age stale must not bypass CT/preheat startup sequencing.
             // Reset-age stale must not bypass CT/preheat startup sequencing.
             if (bmc_stale && (control_state == RESET_SAFE ||
             if (bmc_stale && (control_state == RESET_SAFE ||
                               control_state == WAIT_CT_VALID ||
                               control_state == WAIT_CT_VALID ||
@@ -710,9 +804,9 @@ module thermal_control_core #(
                     assert(ptc_shutdown_mask[formal_ptc_index]);
                     assert(ptc_shutdown_mask[formal_ptc_index]);
                     assert(!thermal_protection_mask[formal_ptc_index]);
                     assert(!thermal_protection_mask[formal_ptc_index]);
                     if ($past(active_output_bank))
                     if ($past(active_output_bank))
-                        assert(req0[formal_ptc_index] == 0);
+                        assert(formal_req0[formal_ptc_index] == 0);
                     else
                     else
-                        assert(req1[formal_ptc_index] == 0);
+                        assert(formal_req1[formal_ptc_index] == 0);
                 end
                 end
 
 
                 // P05: a sampled hard limit latches the lane fault before the
                 // P05: a sampled hard limit latches the lane fault before the
@@ -758,12 +852,12 @@ module thermal_control_core #(
                           (global_fault ||
                           (global_fault ||
                            lane_fault_mask[lane_for_channel(formal_ptc_index)]) &&
                            lane_fault_mask[lane_for_channel(formal_ptc_index)]) &&
                           !target_commit && !formal_stale_preempt)) begin
                           !target_commit && !formal_stale_preempt)) begin
-                    assert(previous_error[formal_ptc_index] == 0);
-                    assert(previous_output[formal_ptc_index] == 0);
+                    assert(formal_previous_error[formal_ptc_index] == 0);
+                    assert(formal_previous_output[formal_ptc_index] == 0);
                     if ($past(active_output_bank))
                     if ($past(active_output_bank))
-                        assert(req0[formal_ptc_index] == 0);
+                        assert(formal_req0[formal_ptc_index] == 0);
                     else
                     else
-                        assert(req1[formal_ptc_index] == 0);
+                        assert(formal_req1[formal_ptc_index] == 0);
                 end
                 end
 
 
                 // P12: absence of a Host target commit cannot create STOPPED.
                 // P12: absence of a Host target commit cannot create STOPPED.
@@ -785,19 +879,19 @@ module thermal_control_core #(
             // tasks; they prevent the safety antecedents from being vacuous.
             // tasks; they prevent the safety antecedents from being vacuous.
             cover(global_fault && work_state == W_IDLE &&
             cover(global_fault && work_state == W_IDLE &&
                   formal_ptc_index < 24 &&
                   formal_ptc_index < 24 &&
-                  (active_output_bank ? app1[formal_ptc_index] :
-                                        app0[formal_ptc_index]) == 0);
+                  (active_output_bank ? formal_app1[formal_ptc_index] :
+                                        formal_app0[formal_ptc_index]) == 0);
             cover(ptc_shutdown_mask[formal_ptc_index] &&
             cover(ptc_shutdown_mask[formal_ptc_index] &&
                   work_state == W_IDLE &&
                   work_state == W_IDLE &&
-                  (active_output_bank ? app1[formal_ptc_index] :
-                                        app0[formal_ptc_index]) == 0);
+                  (active_output_bank ? formal_app1[formal_ptc_index] :
+                                        formal_app0[formal_ptc_index]) == 0);
             cover(lane_fault_mask[lane_for_channel(formal_ptc_index)] &&
             cover(lane_fault_mask[lane_for_channel(formal_ptc_index)] &&
                   work_state == W_IDLE &&
                   work_state == W_IDLE &&
-                  (active_output_bank ? app1[formal_ptc_index] :
-                                        app0[formal_ptc_index]) == 0);
+                  (active_output_bank ? formal_app1[formal_ptc_index] :
+                                        formal_app0[formal_ptc_index]) == 0);
             cover(control_state == STOPPED && work_state == W_IDLE &&
             cover(control_state == STOPPED && work_state == W_IDLE &&
-                  (active_output_bank ? app1[formal_ptc_index] :
-                                        app0[formal_ptc_index]) == 0);
+                  (active_output_bank ? formal_app1[formal_ptc_index] :
+                                        formal_app0[formal_ptc_index]) == 0);
             cover(stimulus_running && stimulus_remaining != 0);
             cover(stimulus_running && stimulus_remaining != 0);
             cover(formal_past_valid &&
             cover(formal_past_valid &&
                   $past(stimulus_running && tick_1s &&
                   $past(stimulus_running && tick_1s &&

+ 80 - 0
src/control/thermal_output_banks.v

@@ -0,0 +1,80 @@
+`timescale 1ns/1ps
+
+// Two 32 x 16 embedded-RAM banks.  Each word is {requested, applied}.
+// The active bank serves PWM plus snapshot reads; the inactive bank serves
+// the sequential controller read/write path.  A pointer flip is the commit.
+module thermal_output_banks (
+    input  wire        clk,
+    input  wire        active_bank,
+    input  wire        init_write,
+    input  wire [4:0]  init_addr,
+    input  wire [15:0] init_data,
+    input  wire        control_bank,
+    input  wire [4:0]  control_read_addr,
+    input  wire        control_write,
+    input  wire [4:0]  control_write_addr,
+    input  wire [15:0] control_write_data,
+    input  wire [4:0]  pwm_addr,
+    output wire [7:0]  pwm_applied,
+    input  wire        snapshot_bank,
+    input  wire [4:0]  snapshot_addr,
+    output wire [7:0]  snapshot_requested,
+    output wire [7:0]  snapshot_applied,
+    output wire [7:0]  control_requested
+);
+    wire bank0_active = !active_bank;
+    wire bank1_active = active_bank;
+    wire [4:0] bank0_a_addr = bank0_active ? pwm_addr : control_read_addr;
+    wire [4:0] bank1_a_addr = bank1_active ? pwm_addr : control_read_addr;
+    wire bank0_write = init_write || (control_write && !control_bank);
+    wire bank1_write = init_write || (control_write && control_bank);
+    wire [4:0] bank0_b_addr = init_write ? init_addr :
+        ((control_write && !control_bank) ? control_write_addr : snapshot_addr);
+    wire [4:0] bank1_b_addr = init_write ? init_addr :
+        ((control_write && control_bank) ? control_write_addr : snapshot_addr);
+    wire [15:0] bank_write_data = init_write ? init_data : control_write_data;
+    wire [15:0] bank0_a_data;
+    wire [15:0] bank1_a_data;
+    wire [15:0] bank0_b_data;
+    wire [15:0] bank1_b_data;
+    reg active_bank_read;
+    reg control_bank_read;
+    // Port-A data arrives one clock after its address.  Delay both selectors
+    // by the same clock so a bank-pointer commit cannot pair the new selector
+    // with the previous bank's address/result.
+    wire [7:0] active_applied = active_bank_read ?
+        bank1_a_data[7:0] : bank0_a_data[7:0];
+    wire [7:0] control_requested_word = control_bank_read ?
+        bank1_a_data[15:8] : bank0_a_data[15:8];
+    wire [15:0] snapshot_word = snapshot_bank ? bank1_b_data : bank0_b_data;
+
+    assign pwm_applied = active_applied;
+    assign control_requested = control_requested_word;
+    assign snapshot_requested = snapshot_word[15:8];
+    assign snapshot_applied = snapshot_word[7:0];
+
+    always @(posedge clk) begin
+        active_bank_read <= active_bank;
+        control_bank_read <= control_bank;
+    end
+
+    ef2_bram_dp #(.DATA_WIDTH(16), .ADDR_WIDTH(5), .DATA_DEPTH(32)) u_bank0 (
+        .clk(clk), .a_en(1'b1), .a_we(1'b0), .a_addr(bank0_a_addr),
+        .a_wdata(16'd0), .a_rdata(bank0_a_data),
+        .b_en(1'b1), .b_we(bank0_write), .b_addr(bank0_b_addr),
+        .b_wdata(bank_write_data), .b_rdata(bank0_b_data)
+    );
+    ef2_bram_dp #(.DATA_WIDTH(16), .ADDR_WIDTH(5), .DATA_DEPTH(32)) u_bank1 (
+        .clk(clk), .a_en(1'b1), .a_we(1'b0), .a_addr(bank1_a_addr),
+        .a_wdata(16'd0), .a_rdata(bank1_a_data),
+        .b_en(1'b1), .b_we(bank1_write), .b_addr(bank1_b_addr),
+        .b_wdata(bank_write_data), .b_rdata(bank1_b_data)
+    );
+
+`ifdef FORMAL
+    always @(posedge clk) begin
+        if (!init_write && control_write)
+            assert(control_bank != active_bank);
+    end
+`endif
+endmodule

+ 1 - 1
src/top/prod2u_6400_v1_top.v

@@ -205,7 +205,7 @@ module prod2u_6400_v1_top #(
         .tx_payload_length(tx_payload_length), .tx_done(host_response_done),
         .tx_payload_length(tx_payload_length), .tx_done(host_response_done),
         .transaction_done(host_transaction_done), .busy(host_command_busy)
         .transaction_done(host_transaction_done), .busy(host_command_busy)
     );
     );
-    frame_tx #(.PAYLOAD_IDX_BITS(8), .EXTERNAL_CRC(1)) u_frame_tx (
+    frame_tx #(.PAYLOAD_IDX_BITS(8), .EXTERNAL_CRC(1), .PAYLOAD_READ_LATENCY(1)) u_frame_tx (
         .clk(sys_clk), .rst_n(rst_n), .start(tx_start), .frame_type(tx_frame_type),
         .clk(sys_clk), .rst_n(rst_n), .start(tx_start), .frame_type(tx_frame_type),
         .payload_length(tx_payload_length), .busy(frame_tx_busy), .byte_valid(frame_tx_byte_valid),
         .payload_length(tx_payload_length), .busy(frame_tx_busy), .byte_valid(frame_tx_byte_valid),
         .byte_data(frame_tx_byte_data), .byte_ready(!host_tx_busy),
         .byte_data(frame_tx_byte_data), .byte_ready(!host_tx_busy),

+ 3 - 1
td/syn/prod2u_6400_front_back.tcl

@@ -12,7 +12,7 @@ proc src {relative} {
 }
 }
 proc analyze_src {relative} {
 proc analyze_src {relative} {
     global source_root
     global source_root
-    analyze -file [src $relative] -include_dir $source_root
+    analyze -file [src $relative] -include_dir $source_root -define PROD2U_TD_VENDOR_RAM
 }
 }
 
 
 import_device ef2_4.db -package EF2L45BG256B
 import_device ef2_4.db -package EF2L45BG256B
@@ -22,6 +22,7 @@ set_param place async_reg on
 analyze_src {src/common/uart_rx_byte.v}
 analyze_src {src/common/uart_rx_byte.v}
 analyze_src {src/common/uart_tx_byte.v}
 analyze_src {src/common/uart_tx_byte.v}
 analyze_src {src/common/crc16_serial.v}
 analyze_src {src/common/crc16_serial.v}
+analyze_src {src/common/ef2_bram_dp.v}
 analyze_src {src/common/frame_rx.v}
 analyze_src {src/common/frame_rx.v}
 analyze_src {src/common/frame_tx.v}
 analyze_src {src/common/frame_tx.v}
 analyze_src {src/common/payload_ram.v}
 analyze_src {src/common/payload_ram.v}
@@ -34,6 +35,7 @@ analyze_src {src/transport/thermal_host_command.v}
 analyze_src {src/acquisition/bmc_poll_engine.v}
 analyze_src {src/acquisition/bmc_poll_engine.v}
 analyze_src {src/acquisition/bmc_ascii_snapshot.v}
 analyze_src {src/acquisition/bmc_ascii_snapshot.v}
 analyze_src {src/acquisition/ct7428_snapshot.v}
 analyze_src {src/acquisition/ct7428_snapshot.v}
+analyze_src {src/control/thermal_output_banks.v}
 analyze_src {src/control/thermal_control_core.v}
 analyze_src {src/control/thermal_control_core.v}
 analyze_src {src/actuator/pwm_bitmap_engine.v}
 analyze_src {src/actuator/pwm_bitmap_engine.v}
 analyze_src {src/telemetry/thermal_snapshot_mux.v}
 analyze_src {src/telemetry/thermal_snapshot_mux.v}

+ 1 - 0
tests/cocotb/run_6400_bmc_fuzz.py

@@ -25,6 +25,7 @@ def main() -> int:
         runner = get_runner("icarus")
         runner = get_runner("icarus")
         runner.build(
         runner.build(
             sources=[
             sources=[
+                ROOT / "src/common/ef2_bram_dp.v",
                 ROOT / "src/acquisition/bmc_ascii_snapshot.v",
                 ROOT / "src/acquisition/bmc_ascii_snapshot.v",
                 TEST_DIR / "bmc_ascii_snapshot_cocotb_top.v",
                 TEST_DIR / "bmc_ascii_snapshot_cocotb_top.v",
             ],
             ],

+ 2 - 0
tests/cocotb/run_6400_pi_differential.py

@@ -28,6 +28,8 @@ def main() -> int:
         runner = get_runner("icarus")
         runner = get_runner("icarus")
         runner.build(
         runner.build(
             sources=[
             sources=[
+                ROOT / "src/common/ef2_bram_dp.v",
+                ROOT / "src/control/thermal_output_banks.v",
                 ROOT / "src/control/thermal_control_core.v",
                 ROOT / "src/control/thermal_control_core.v",
                 TEST_DIR / "thermal_control_core_cocotb_top.v",
                 TEST_DIR / "thermal_control_core_cocotb_top.v",
             ],
             ],

+ 2 - 1
tests/cocotb/test_6400_bmc_parser_fuzz.py

@@ -95,6 +95,7 @@ async def read_channels(dut) -> tuple[list[int], int]:
     valid_mask = 0
     valid_mask = 0
     for index in range(24):
     for index in range(24):
         dut.rd_index.value = index
         dut.rd_index.value = index
+        await RisingEdge(dut.sys_clk)
         await Timer(1, units="ns")
         await Timer(1, units="ns")
         raw.append(int(dut.rd_raw.value))
         raw.append(int(dut.rd_raw.value))
         valid_mask |= int(dut.rd_valid.value) << index
         valid_mask |= int(dut.rd_valid.value) << index
@@ -151,7 +152,7 @@ async def test_bmc_replay_fuzz_timeout_banks_epoch_and_freshness(dut):
     dut.snapshot_lock_bank.value = 0
     dut.snapshot_lock_bank.value = 0
     dut.rd_index.value = 0
     dut.rd_index.value = 0
     await with_timeout(RisingEdge(dut.rst_n_mon), 1, "ms")
     await with_timeout(RisingEdge(dut.rst_n_mon), 1, "ms")
-    await clock_cycles(dut, 3)
+    await clock_cycles(dut, 27)
     assert int(dut.age_seconds.value) == 0xFFFF
     assert int(dut.age_seconds.value) == 0xFFFF
     assert int(dut.stale.value) == 1
     assert int(dut.stale.value) == 1
 
 

+ 3 - 2
tests/cocotb/test_6400_pi_differential.py

@@ -84,10 +84,11 @@ async def read_outputs(dut) -> tuple[list[int], list[int], list[int], list[int]]
     applied: list[int] = []
     applied: list[int] = []
     previous_error: list[int] = []
     previous_error: list[int] = []
     previous_output: list[int] = []
     previous_output: list[int] = []
-    await FallingEdge(dut.sys_clk)
     for index in range(32):
     for index in range(32):
+        await FallingEdge(dut.sys_clk)
         dut.rd_index.value = index
         dut.rd_index.value = index
-        await Timer(1, units="ns")
+        await RisingEdge(dut.sys_clk)
+        await ReadOnly()
         requested.append(int(dut.requested_data.value))
         requested.append(int(dut.requested_data.value))
         applied.append(int(dut.applied_data.value))
         applied.append(int(dut.applied_data.value))
         if index < 24:
         if index < 24:

+ 4 - 2
tests/cocotb/thermal_control_core_cocotb_top.v

@@ -102,7 +102,9 @@ module thermal_control_core_cocotb_top (
     );
     );
 
 
     assign work_state_mon = u_dut.work_state;
     assign work_state_mon = u_dut.work_state;
-    assign previous_error_data = (rd_index < 24) ? u_dut.previous_error[rd_index] : 16'd0;
-    assign previous_output_data = (rd_index < 24) ? u_dut.previous_output[rd_index] : 16'd0;
+    assign previous_error_data = (rd_index < 24) ?
+        u_dut.u_pi_state.memory[rd_index][31:16] : 16'd0;
+    assign previous_output_data = (rd_index < 24) ?
+        u_dut.u_pi_state.memory[rd_index][15:0] : 16'd0;
     wire unused = &{1'b0, pwm_rd_data, host_target_seen, stimulus_active};
     wire unused = &{1'b0, pwm_rd_data, host_target_seen, stimulus_active};
 endmodule
 endmodule

+ 2 - 0
tests/formal/6400_bmc_bank_properties.sby

@@ -11,10 +11,12 @@ boolector: smtbmc boolector
 z3: smtbmc z3 -- --noincr
 z3: smtbmc z3 -- --noincr
 
 
 [script]
 [script]
+read_verilog -formal ef2_bram_dp.v
 read_verilog -formal -D FORMAL bmc_ascii_snapshot.v
 read_verilog -formal -D FORMAL bmc_ascii_snapshot.v
 read_verilog -formal 6400_bmc_bank_properties_formal.v
 read_verilog -formal 6400_bmc_bank_properties_formal.v
 prep -top thermal_6400_bmc_bank_properties_formal
 prep -top thermal_6400_bmc_bank_properties_formal
 
 
 [files]
 [files]
+../../src/common/ef2_bram_dp.v
 ../../src/acquisition/bmc_ascii_snapshot.v
 ../../src/acquisition/bmc_ascii_snapshot.v
 6400_bmc_bank_properties_formal.v
 6400_bmc_bank_properties_formal.v

+ 2 - 0
tests/formal/6400_bmc_bank_reachability.sby

@@ -6,10 +6,12 @@ depth 128
 smtbmc boolector
 smtbmc boolector
 
 
 [script]
 [script]
+read_verilog -formal ef2_bram_dp.v
 read_verilog -formal -D FORMAL bmc_ascii_snapshot.v
 read_verilog -formal -D FORMAL bmc_ascii_snapshot.v
 read_verilog -formal 6400_bmc_bank_properties_formal.v
 read_verilog -formal 6400_bmc_bank_properties_formal.v
 prep -top thermal_6400_bmc_bank_properties_formal
 prep -top thermal_6400_bmc_bank_properties_formal
 
 
 [files]
 [files]
+../../src/common/ef2_bram_dp.v
 ../../src/acquisition/bmc_ascii_snapshot.v
 ../../src/acquisition/bmc_ascii_snapshot.v
 6400_bmc_bank_properties_formal.v
 6400_bmc_bank_properties_formal.v

+ 3 - 1
tests/formal/6400_core_properties.sby

@@ -11,10 +11,12 @@ boolector: smtbmc boolector
 z3: smtbmc z3 -- --noincr
 z3: smtbmc z3 -- --noincr
 
 
 [script]
 [script]
-read_verilog -formal -D FORMAL thermal_control_core.v
+read_verilog -formal -D FORMAL ef2_bram_dp.v thermal_output_banks.v thermal_control_core.v
 read_verilog -formal 6400_core_properties_formal.v
 read_verilog -formal 6400_core_properties_formal.v
 prep -top thermal_6400_core_properties_formal
 prep -top thermal_6400_core_properties_formal
 
 
 [files]
 [files]
+../../src/common/ef2_bram_dp.v
+../../src/control/thermal_output_banks.v
 ../../src/control/thermal_control_core.v
 ../../src/control/thermal_control_core.v
 6400_core_properties_formal.v
 6400_core_properties_formal.v

+ 3 - 1
tests/formal/6400_core_reachability.sby

@@ -6,10 +6,12 @@ depth 220
 smtbmc boolector
 smtbmc boolector
 
 
 [script]
 [script]
-read_verilog -formal -D FORMAL thermal_control_core.v
+read_verilog -formal -D FORMAL ef2_bram_dp.v thermal_output_banks.v thermal_control_core.v
 read_verilog -formal 6400_core_properties_formal.v
 read_verilog -formal 6400_core_properties_formal.v
 prep -top thermal_6400_core_properties_formal
 prep -top thermal_6400_core_properties_formal
 
 
 [files]
 [files]
+../../src/common/ef2_bram_dp.v
+../../src/control/thermal_output_banks.v
 ../../src/control/thermal_control_core.v
 ../../src/control/thermal_control_core.v
 6400_core_properties_formal.v
 6400_core_properties_formal.v

+ 3 - 2
tests/sim/bmc_ascii_snapshot_tb.v

@@ -77,6 +77,7 @@ module bmc_ascii_snapshot_tb;
         snapshot_index = 0;
         snapshot_index = 0;
         repeat (3) @(negedge clk);
         repeat (3) @(negedge clk);
         rst_n = 1;
         rst_n = 1;
+        repeat (26) @(negedge clk);
         for (i = 0; i < 23; i = i + 1) begin
         for (i = 0; i < 23; i = i + 1) begin
             send_byte(8'd25 + i, i[0]);
             send_byte(8'd25 + i, i[0]);
             send_byte(8'd50, !i[0]);
             send_byte(8'd50, !i[0]);
@@ -91,10 +92,10 @@ module bmc_ascii_snapshot_tb;
         end
         end
         control_bank = active_bank;
         control_bank = active_bank;
         control_index = 0;
         control_index = 0;
-        #1;
+        @(posedge clk); #1;
         if (!control_valid || control_raw !== 16'h1932) $fatal;
         if (!control_valid || control_raw !== 16'h1932) $fatal;
         control_index = 23;
         control_index = 23;
-        #1;
+        @(posedge clk); #1;
         if (control_valid || control_raw !== 16'hffff) $fatal;
         if (control_valid || control_raw !== 16'hffff) $fatal;
         send_byte(8'd30, 0);
         send_byte(8'd30, 0);
         send_byte(8'd100, 0);
         send_byte(8'd100, 0);

+ 3 - 1
tests/sim/thermal_control_core_tb.v

@@ -91,7 +91,9 @@ module thermal_control_core_tb;
         for (i = 0; i < 24; i = i + 1) bmc_raw[i] = {8'd60, 8'd0};
         for (i = 0; i < 24; i = i + 1) bmc_raw[i] = {8'd60, 8'd0};
         repeat (4) @(negedge clk);
         repeat (4) @(negedge clk);
         rst_n = 1;
         rst_n = 1;
-        repeat (3) @(negedge clk);
+        // The RAM-backed controller deterministically initializes both output
+        // banks and all PI-state words before leaving RESET_SAFE.
+        repeat (36) @(negedge clk);
         if (state !== 1 || global_fault) $fatal;
         if (state !== 1 || global_fault) $fatal;
         ct_epoch = 1;
         ct_epoch = 1;
         repeat (3) @(negedge clk);
         repeat (3) @(negedge clk);