|
|
@@ -1,106 +1,73 @@
|
|
|
`timescale 1ns/1ps
|
|
|
`include "generated/6400/prod2u_6400_v1_params.vh"
|
|
|
|
|
|
-// Single-owner controller. Host and PID values are connector-side duties.
|
|
|
-// Safety is an independent applied-output layer; board polarity is external.
|
|
|
+// 6400 production control core: SAFE + MANUAL SET_ALL only.
|
|
|
+// No automatic controller, target temperature, or controller state is present.
|
|
|
module thermal_control_core #(
|
|
|
parameter integer WATCHDOG_TICKS_OVERRIDE = 0,
|
|
|
- parameter signed [15:0] CHANNEL_LIMIT = `FB_TEMP_CHANNEL_CLAMP,
|
|
|
- parameter signed [15:0] HARD_LIMIT = `FB_TEMP_LANE_HARD,
|
|
|
parameter [7:0] FAN_SAFE_DUTY = `FAN_SAFE_DUTY,
|
|
|
parameter [7:0] WATCHDOG_SECONDS = `SET_ALL_WATCHDOG_SECONDS
|
|
|
) (
|
|
|
- input wire clk,
|
|
|
- input wire rst_n,
|
|
|
- input wire tick_1s,
|
|
|
- input wire manual_wr_en,
|
|
|
- input wire [4:0] manual_wr_addr,
|
|
|
- input wire [7:0] manual_wr_data,
|
|
|
- input wire manual_commit,
|
|
|
- output reg manual_commit_done,
|
|
|
- output reg manual_commit_ok,
|
|
|
- input wire pid_target_commit,
|
|
|
- input wire [7:0] pid_target_celsius,
|
|
|
- input wire [15:0] bmc_epoch,
|
|
|
- input wire bmc_stale,
|
|
|
- input wire [23:0] bmc_valid_mask,
|
|
|
- output wire [4:0] bmc_rd_index,
|
|
|
- input wire [15:0] bmc_rd_raw,
|
|
|
- input wire bmc_rd_valid,
|
|
|
- input wire [15:0] ct_epoch,
|
|
|
- input wire ct_stale,
|
|
|
- input wire [26:0] ct_valid_mask,
|
|
|
- input wire snapshot_lock,
|
|
|
- input wire snapshot_lock_bank,
|
|
|
- input wire [4:0] pwm_rd_addr,
|
|
|
- output wire [7:0] pwm_rd_data,
|
|
|
- input wire snapshot_output_bank,
|
|
|
- input wire [4:0] snapshot_rd_addr,
|
|
|
- output wire [7:0] snapshot_requested_data,
|
|
|
- output wire [7:0] snapshot_applied_data,
|
|
|
- output reg active_output_bank,
|
|
|
- output reg [2:0] control_state,
|
|
|
- output reg [7:0] current_target_celsius,
|
|
|
- output reg [15:0] control_epoch,
|
|
|
- output reg [23:0] safety_override_mask,
|
|
|
- output reg [3:0] lane_fault_mask,
|
|
|
- output reg global_fault,
|
|
|
- output reg output_commit,
|
|
|
- output wire watchdog_active,
|
|
|
- output reg [7:0] watchdog_remaining,
|
|
|
- output wire pid_running,
|
|
|
- output wire manual_mode,
|
|
|
- output wire hard_protect,
|
|
|
- input wire pwm_phase_boundary,
|
|
|
- input wire pwm_scan_idle,
|
|
|
- output reg boot_init_complete
|
|
|
-`ifdef FORMAL
|
|
|
- , output wire [3:0] formal_work_state_o
|
|
|
- , output wire [1:0] formal_commit_kind_o
|
|
|
- , output wire formal_manual_commit_applied_o
|
|
|
- , output wire formal_manual_pending_o
|
|
|
- , output wire formal_safe_pending_o
|
|
|
- , output wire formal_stale_hold_committed_o
|
|
|
- , output wire formal_pi_state_write_o
|
|
|
- , output wire formal_complete_valid_bmc_o
|
|
|
- , output wire [3:0] formal_epoch_above_release_mask_o
|
|
|
-`endif
|
|
|
+ input wire clk,
|
|
|
+ input wire rst_n,
|
|
|
+ input wire tick_1s,
|
|
|
+ input wire manual_wr_en,
|
|
|
+ input wire [4:0] manual_wr_addr,
|
|
|
+ input wire [7:0] manual_wr_data,
|
|
|
+ input wire manual_commit,
|
|
|
+ output reg manual_commit_done,
|
|
|
+ output reg manual_commit_ok,
|
|
|
+ input wire [15:0] bmc_epoch,
|
|
|
+ input wire bmc_stale,
|
|
|
+ input wire [23:0] bmc_valid_mask,
|
|
|
+ output wire [4:0] bmc_rd_index,
|
|
|
+ input wire [15:0] bmc_rd_raw,
|
|
|
+ input wire bmc_rd_valid,
|
|
|
+ input wire [15:0] ct_epoch,
|
|
|
+ input wire ct_stale,
|
|
|
+ input wire [26:0] ct_valid_mask,
|
|
|
+ input wire snapshot_lock,
|
|
|
+ input wire snapshot_lock_bank,
|
|
|
+ input wire [4:0] pwm_rd_addr,
|
|
|
+ output wire [7:0] pwm_rd_data,
|
|
|
+ input wire snapshot_output_bank,
|
|
|
+ input wire [4:0] snapshot_rd_addr,
|
|
|
+ output wire [7:0] snapshot_requested_data,
|
|
|
+ output wire [7:0] snapshot_applied_data,
|
|
|
+ output reg active_output_bank,
|
|
|
+ output reg [2:0] control_state,
|
|
|
+ output reg [7:0] current_target_celsius,
|
|
|
+ output reg [15:0] control_epoch,
|
|
|
+ output reg [23:0] safety_override_mask,
|
|
|
+ output reg [3:0] lane_fault_mask,
|
|
|
+ output reg global_fault,
|
|
|
+ output reg output_commit,
|
|
|
+ output wire watchdog_active,
|
|
|
+ output reg [7:0] watchdog_remaining,
|
|
|
+ output wire manual_mode,
|
|
|
+ output wire hard_protect,
|
|
|
+ input wire pwm_phase_boundary,
|
|
|
+ input wire pwm_scan_idle,
|
|
|
+ output reg boot_init_complete
|
|
|
);
|
|
|
localparam [2:0] OWNER_SAFE = `FB_OWNER_SAFE;
|
|
|
localparam [2:0] OWNER_MANUAL = `FB_OWNER_MANUAL;
|
|
|
- localparam [2:0] OWNER_PID = `FB_OWNER_PID;
|
|
|
+ localparam [3:0] W_INIT = 0, W_IDLE = 1, W_MANUAL_COPY = 2,
|
|
|
+ W_SAFE_FILL = 3, W_APPLY_PREFETCH = 4, W_APPLY_WRITE = 5,
|
|
|
+ W_SAFETY_PREFETCH = 6, W_SAFETY_CHECK = 7, W_COMMIT_WAIT = 8;
|
|
|
+ localparam [1:0] COMMIT_NONE = 0, COMMIT_MANUAL = 1, COMMIT_SAFE = 2;
|
|
|
localparam [7:0] WATCHDOG_LOAD = WATCHDOG_TICKS_OVERRIDE != 0 ?
|
|
|
WATCHDOG_TICKS_OVERRIDE[7:0] : WATCHDOG_SECONDS;
|
|
|
|
|
|
- localparam [3:0] W_INIT = 0, W_IDLE = 1, W_MANUAL_COPY = 2,
|
|
|
- W_PID_PREFETCH = 3, W_PID_WRITE = 4, W_FAN_WRITE = 5,
|
|
|
- W_APPLY_PREFETCH = 6, W_APPLY_WRITE = 7, W_SAFE_FILL = 8,
|
|
|
- W_COMMIT_WAIT = 9,
|
|
|
- W_SAFETY_PREFETCH = 11, W_SAFETY_CHECK = 12;
|
|
|
- localparam [1:0] COMMIT_NONE = 0, COMMIT_MANUAL = 1,
|
|
|
- COMMIT_SAFE = 2, COMMIT_PID = 3;
|
|
|
-
|
|
|
reg [3:0] work_state;
|
|
|
reg [1:0] commit_kind;
|
|
|
reg [4:0] work_index;
|
|
|
reg [15:0] last_bmc_epoch;
|
|
|
- reg [3:0] epoch_hard_mask;
|
|
|
- reg [3:0] epoch_above_release_mask;
|
|
|
- reg [1:0] lane_release_count [0:3];
|
|
|
reg manual_pending;
|
|
|
reg safe_pending;
|
|
|
- reg stale_hold_committed;
|
|
|
- reg [15:0] manual_request_epoch;
|
|
|
- reg pi_state_write;
|
|
|
- reg [4:0] pi_state_write_addr;
|
|
|
- reg [31:0] pi_state_write_data;
|
|
|
- wire [31:0] pi_state_read_data;
|
|
|
- wire [31:0] pi_state_unused_read_data;
|
|
|
-
|
|
|
- wire manual_bank_active;
|
|
|
- wire manual_commit_applied;
|
|
|
- wire [7:0] manual_data;
|
|
|
-
|
|
|
+ reg [3:0] epoch_hard_mask;
|
|
|
+ reg [3:0] scan_lane_mask;
|
|
|
+ reg [3:0] lane_release_unused [0:3];
|
|
|
reg output_init_write;
|
|
|
reg [4:0] output_init_addr;
|
|
|
reg [15:0] output_init_data;
|
|
|
@@ -109,88 +76,29 @@ module thermal_control_core #(
|
|
|
reg [15:0] output_control_data;
|
|
|
reg [4:0] output_control_read_addr;
|
|
|
wire [7:0] output_control_requested;
|
|
|
-
|
|
|
- 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);
|
|
|
- wire signed [15:0] bmc_temperature = $signed(bmc_integer_scaled + {8'd0, bmc_rd_raw[7:0]});
|
|
|
- // One physical incremental-PI datapath services all 24 BRAM-resident
|
|
|
- // channel states. Arithmetic matches thermal-control-lab fixed_point/pi.py.
|
|
|
- wire signed [16:0] pid_error_full =
|
|
|
- $signed({1'b0, current_target_celsius}) * 17'sd100 - $signed(bmc_temperature);
|
|
|
- wire signed [15:0] pid_error = pid_error_full[15:0];
|
|
|
- wire signed [15:0] pi_previous_error = $signed(pi_state_read_data[31:16]);
|
|
|
- wire signed [15:0] pi_previous_output = $signed(pi_state_read_data[15:0]);
|
|
|
- wire signed [15:0] pi_delta_error = pid_error - pi_previous_error;
|
|
|
- wire [1:0] channel_lane = (work_index < 6) ? 0 : (work_index < 12) ? 1 :
|
|
|
+ wire manual_bank_active;
|
|
|
+ wire manual_commit_applied;
|
|
|
+ wire [7:0] manual_data;
|
|
|
+ wire [15:0] bmc_celsius = {8'd0, bmc_rd_raw[15:8]};
|
|
|
+ wire [1:0] scan_lane = (work_index < 6) ? 0 : (work_index < 12) ? 1 :
|
|
|
(work_index < 18) ? 2 : 3;
|
|
|
- wire [1:0] output_lane = work_index[1:0];
|
|
|
- wire signed [15:0] pi_kp_q4_12 =
|
|
|
- (channel_lane == 0 || channel_lane == 3) ? `FB_EDGE_KP_Q4_12 : `FB_CENTER_KP_Q4_12;
|
|
|
- wire signed [15:0] pi_ki_q4_12 =
|
|
|
- (channel_lane == 0 || channel_lane == 3) ? `FB_EDGE_KI_Q4_12 : `FB_CENTER_KI_Q4_12;
|
|
|
- wire signed [31:0] pi_kp_product = pi_kp_q4_12 * pi_delta_error;
|
|
|
- wire signed [31:0] pi_ki_product = pi_ki_q4_12 * pid_error;
|
|
|
- wire signed [32:0] pi_product_sum = pi_kp_product + pi_ki_product;
|
|
|
- wire signed [32:0] pi_delta_q8_8 = (pi_product_sum >= 0) ?
|
|
|
- ((pi_product_sum + 33'sd8) >>> 4) :
|
|
|
- -(((-pi_product_sum) + 33'sd8) >>> 4);
|
|
|
- wire signed [33:0] pi_previous_output_extended =
|
|
|
- {{18{pi_previous_output[15]}}, pi_previous_output};
|
|
|
- wire signed [33:0] pi_delta_extended =
|
|
|
- {{1{pi_delta_q8_8[32]}}, pi_delta_q8_8};
|
|
|
- wire signed [33:0] pi_candidate = pi_previous_output_extended + pi_delta_extended;
|
|
|
- wire signed [16:0] pi_slew_low_unclamped = $signed(pi_previous_output) - 17'sd1280;
|
|
|
- wire signed [16:0] pi_slew_high_unclamped = $signed(pi_previous_output) + 17'sd1280;
|
|
|
- wire signed [16:0] pi_slew_low = (pi_slew_low_unclamped < 0) ? 0 : pi_slew_low_unclamped;
|
|
|
- wire signed [16:0] pi_slew_high = (pi_slew_high_unclamped > 17'sd25600) ?
|
|
|
- 17'sd25600 : pi_slew_high_unclamped;
|
|
|
- wire signed [33:0] pi_slew_low_extended = {{17{pi_slew_low[16]}}, pi_slew_low};
|
|
|
- wire signed [33:0] pi_slew_high_extended = {{17{pi_slew_high[16]}}, pi_slew_high};
|
|
|
- wire [15:0] pi_applied_q8_8 = (pi_candidate < pi_slew_low_extended) ? pi_slew_low[15:0] :
|
|
|
- (pi_candidate > pi_slew_high_extended) ? pi_slew_high[15:0] : pi_candidate[15:0];
|
|
|
- wire [16:0] pi_rounded_duty = {1'b0, pi_applied_q8_8} + 17'd128;
|
|
|
- wire [7:0] pid_duty = (pi_rounded_duty[16:8] > 100) ? 8'd100 : pi_rounded_duty[15:8];
|
|
|
- wire complete_valid_bmc = !bmc_stale && (&bmc_valid_mask);
|
|
|
- wire any_valid_bmc = !bmc_stale && (|bmc_valid_mask);
|
|
|
- wire new_bmc_epoch = bmc_epoch != last_bmc_epoch;
|
|
|
- wire channel_over_76 = bmc_rd_valid && bmc_temperature >= CHANNEL_LIMIT;
|
|
|
- wire channel_over_77 = bmc_rd_valid && bmc_temperature >= HARD_LIMIT;
|
|
|
- wire channel_above_release = bmc_rd_valid && bmc_temperature > `FB_TEMP_LANE_RELEASE;
|
|
|
- wire [3:0] channel_lane_bit = 4'b0001 << channel_lane;
|
|
|
- wire [3:0] observed_hard_mask = epoch_hard_mask |
|
|
|
- (channel_over_77 ? channel_lane_bit : 4'd0);
|
|
|
- wire [3:0] newly_hard_mask = observed_hard_mask & ~lane_fault_mask;
|
|
|
+ wire [3:0] scan_lane_bit = 4'b0001 << scan_lane;
|
|
|
+ wire scan_over76 = bmc_rd_valid && (bmc_celsius >= 16'd76);
|
|
|
+ wire scan_over77 = bmc_rd_valid && (bmc_celsius >= 16'd77);
|
|
|
+ wire [3:0] scan_hard_final = epoch_hard_mask |
|
|
|
+ (scan_over77 ? scan_lane_bit : 4'd0);
|
|
|
+ wire scan_any_final = (|safety_override_mask) || scan_over76 || (|scan_hard_final);
|
|
|
|
|
|
assign bmc_rd_index = work_index;
|
|
|
- assign watchdog_active = control_state == OWNER_SAFE || control_state == OWNER_MANUAL;
|
|
|
- assign pid_running = control_state == OWNER_PID && complete_valid_bmc;
|
|
|
assign manual_mode = control_state == OWNER_MANUAL;
|
|
|
assign hard_protect = |lane_fault_mask;
|
|
|
-`ifdef FORMAL
|
|
|
- assign formal_work_state_o = work_state;
|
|
|
- assign formal_commit_kind_o = commit_kind;
|
|
|
- assign formal_manual_commit_applied_o = manual_commit_applied;
|
|
|
- assign formal_manual_pending_o = manual_pending;
|
|
|
- assign formal_safe_pending_o = safe_pending;
|
|
|
- assign formal_stale_hold_committed_o = stale_hold_committed;
|
|
|
- assign formal_pi_state_write_o = pi_state_write;
|
|
|
- assign formal_complete_valid_bmc_o = complete_valid_bmc;
|
|
|
- assign formal_epoch_above_release_mask_o = epoch_above_release_mask;
|
|
|
-`endif
|
|
|
+ assign watchdog_active = manual_mode && (watchdog_remaining != 0);
|
|
|
|
|
|
manual_set_all_bank u_manual_bank (
|
|
|
.clk(clk), .rst_n(rst_n), .write_enable(manual_wr_en),
|
|
|
.write_address(manual_wr_addr), .write_data(manual_wr_data),
|
|
|
.commit(manual_commit), .commit_applied(manual_commit_applied),
|
|
|
- .active_bank(manual_bank_active),
|
|
|
- .read_address(work_index), .read_data(manual_data)
|
|
|
- );
|
|
|
-
|
|
|
- ef2_bram_dp #(.DATA_WIDTH(32), .ADDR_WIDTH(5), .DATA_DEPTH(32)) 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_data),
|
|
|
- .b_en(1'b1), .b_we(pi_state_write), .b_addr(pi_state_write_addr),
|
|
|
- .b_wdata(pi_state_write_data), .b_rdata(pi_state_unused_read_data)
|
|
|
+ .active_bank(manual_bank_active), .read_address(work_index), .read_data(manual_data)
|
|
|
);
|
|
|
|
|
|
thermal_output_banks u_output_banks (
|
|
|
@@ -198,287 +106,135 @@ module thermal_control_core #(
|
|
|
.init_write(output_init_write), .init_addr(output_init_addr), .init_data(output_init_data),
|
|
|
.control_bank(~active_output_bank), .control_read_addr(output_control_read_addr),
|
|
|
.control_write(output_control_write), .control_write_addr(output_control_addr),
|
|
|
- .control_write_data(output_control_data), .pwm_addr(pwm_rd_addr),
|
|
|
- .pwm_applied(pwm_rd_data), .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)
|
|
|
+ .control_write_data(output_control_data), .pwm_addr(pwm_rd_addr), .pwm_applied(pwm_rd_data),
|
|
|
+ .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)
|
|
|
);
|
|
|
|
|
|
integer i;
|
|
|
always @(posedge clk or negedge rst_n) begin
|
|
|
if (!rst_n) begin
|
|
|
- active_output_bank <= 0;
|
|
|
+ active_output_bank <= 1'b0;
|
|
|
control_state <= OWNER_SAFE;
|
|
|
- current_target_celsius <= `DEFAULT_PID_TARGET_C;
|
|
|
- control_epoch <= 0;
|
|
|
- safety_override_mask <= 0;
|
|
|
- lane_fault_mask <= 0;
|
|
|
- global_fault <= 0;
|
|
|
- output_commit <= 0;
|
|
|
- manual_commit_done <= 0;
|
|
|
- manual_commit_ok <= 0;
|
|
|
- watchdog_remaining <= WATCHDOG_LOAD;
|
|
|
- boot_init_complete <= 0;
|
|
|
+ current_target_celsius <= 8'd0;
|
|
|
+ control_epoch <= 16'd0;
|
|
|
+ safety_override_mask <= 24'd0;
|
|
|
+ lane_fault_mask <= 4'd0;
|
|
|
+ global_fault <= 1'b0;
|
|
|
+ output_commit <= 1'b0;
|
|
|
+ manual_commit_done <= 1'b0;
|
|
|
+ manual_commit_ok <= 1'b0;
|
|
|
+ watchdog_remaining <= 8'd0;
|
|
|
+ boot_init_complete <= 1'b0;
|
|
|
work_state <= W_INIT;
|
|
|
commit_kind <= COMMIT_NONE;
|
|
|
- work_index <= 0;
|
|
|
- last_bmc_epoch <= 0;
|
|
|
- epoch_hard_mask <= 0;
|
|
|
- epoch_above_release_mask <= 0;
|
|
|
- manual_pending <= 0;
|
|
|
- safe_pending <= 0;
|
|
|
- stale_hold_committed <= 0;
|
|
|
- manual_request_epoch <= 0;
|
|
|
- output_init_write <= 0;
|
|
|
- output_init_addr <= 0;
|
|
|
- output_init_data <= 0;
|
|
|
- output_control_write <= 0;
|
|
|
- output_control_addr <= 0;
|
|
|
- output_control_data <= 0;
|
|
|
- output_control_read_addr <= 0;
|
|
|
- pi_state_write <= 0;
|
|
|
- pi_state_write_addr <= 0;
|
|
|
- pi_state_write_data <= 0;
|
|
|
- for (i = 0; i < 4; i = i + 1) lane_release_count[i] <= 0;
|
|
|
+ work_index <= 5'd0;
|
|
|
+ last_bmc_epoch <= 16'd0;
|
|
|
+ manual_pending <= 1'b0;
|
|
|
+ safe_pending <= 1'b0;
|
|
|
+ epoch_hard_mask <= 4'd0;
|
|
|
+ scan_lane_mask <= 4'd0;
|
|
|
+ output_init_write <= 1'b0;
|
|
|
+ output_init_addr <= 5'd0;
|
|
|
+ output_init_data <= 16'd0;
|
|
|
+ output_control_write <= 1'b0;
|
|
|
+ output_control_addr <= 5'd0;
|
|
|
+ output_control_data <= 16'd0;
|
|
|
+ output_control_read_addr <= 5'd0;
|
|
|
+ for (i = 0; i < 4; i = i + 1) lane_release_unused[i] <= 0;
|
|
|
end else begin
|
|
|
- output_commit <= 0;
|
|
|
- manual_commit_done <= 0;
|
|
|
- manual_commit_ok <= 0;
|
|
|
- output_init_write <= 0;
|
|
|
- output_control_write <= 0;
|
|
|
- pi_state_write <= 0;
|
|
|
-
|
|
|
- if (pid_target_commit)
|
|
|
- current_target_celsius <= pid_target_celsius;
|
|
|
+ output_commit <= 1'b0;
|
|
|
+ manual_commit_done <= 1'b0;
|
|
|
+ manual_commit_ok <= 1'b0;
|
|
|
+ output_init_write <= 1'b0;
|
|
|
+ output_control_write <= 1'b0;
|
|
|
if (manual_commit_applied) begin
|
|
|
- manual_pending <= 1;
|
|
|
- manual_request_epoch <= bmc_epoch;
|
|
|
- safe_pending <= 0;
|
|
|
- stale_hold_committed <= 0;
|
|
|
+ manual_pending <= 1'b1;
|
|
|
+ safe_pending <= 1'b0;
|
|
|
end
|
|
|
- // An in-flight SET_ALL suppresses timeout, but only the final
|
|
|
- // safely-applied Manual commit is allowed to feed the watchdog.
|
|
|
- if (manual_commit_applied) begin
|
|
|
- safe_pending <= 0;
|
|
|
- end else if (watchdog_active && tick_1s && !manual_pending &&
|
|
|
- commit_kind != COMMIT_MANUAL) begin
|
|
|
- if (watchdog_remaining > 1)
|
|
|
- watchdog_remaining <= watchdog_remaining - 1'b1;
|
|
|
- else begin
|
|
|
- watchdog_remaining <= 0;
|
|
|
- safe_pending <= 1;
|
|
|
- end
|
|
|
+ if (watchdog_active && tick_1s && !manual_pending && commit_kind != COMMIT_MANUAL) begin
|
|
|
+ if (watchdog_remaining > 1) watchdog_remaining <= watchdog_remaining - 1'b1;
|
|
|
+ else begin watchdog_remaining <= 0; safe_pending <= 1'b1; end
|
|
|
end
|
|
|
-
|
|
|
case (work_state)
|
|
|
W_INIT: begin
|
|
|
- output_init_write <= 1;
|
|
|
+ output_init_write <= 1'b1;
|
|
|
output_init_addr <= work_index;
|
|
|
output_init_data <= (work_index < 24) ? 16'h0000 : {FAN_SAFE_DUTY, FAN_SAFE_DUTY};
|
|
|
- if (work_index < 24) begin
|
|
|
- pi_state_write <= 1;
|
|
|
- pi_state_write_addr <= work_index;
|
|
|
- pi_state_write_data <= 32'd0;
|
|
|
- end
|
|
|
if (work_index == 31) begin
|
|
|
- work_index <= 0;
|
|
|
- work_state <= W_IDLE;
|
|
|
- boot_init_complete <= 1;
|
|
|
+ work_index <= 0; boot_init_complete <= 1'b1; work_state <= W_IDLE;
|
|
|
end else work_index <= work_index + 1'b1;
|
|
|
end
|
|
|
W_IDLE: begin
|
|
|
- if (any_valid_bmc && new_bmc_epoch) begin
|
|
|
+ if (!bmc_stale && (bmc_epoch != last_bmc_epoch)) begin
|
|
|
last_bmc_epoch <= bmc_epoch;
|
|
|
- work_index <= 0;
|
|
|
- safety_override_mask <= 0;
|
|
|
- epoch_hard_mask <= 0;
|
|
|
- epoch_above_release_mask <= 0;
|
|
|
- global_fault <= 0;
|
|
|
- stale_hold_committed <= 0;
|
|
|
+ work_index <= 0; epoch_hard_mask <= 0; scan_lane_mask <= 0;
|
|
|
work_state <= W_SAFETY_PREFETCH;
|
|
|
- end else if (manual_pending || manual_commit_applied) begin
|
|
|
- manual_pending <= 0;
|
|
|
- work_index <= 0;
|
|
|
- global_fault <= 0;
|
|
|
- commit_kind <= COMMIT_MANUAL;
|
|
|
+ end else if (manual_pending) begin
|
|
|
+ manual_pending <= 0; work_index <= 0; commit_kind <= COMMIT_MANUAL;
|
|
|
work_state <= W_MANUAL_COPY;
|
|
|
end else if (safe_pending) begin
|
|
|
- safe_pending <= 0;
|
|
|
- work_index <= 0;
|
|
|
- commit_kind <= COMMIT_SAFE;
|
|
|
- work_state <= W_SAFE_FILL;
|
|
|
- end else if (control_state == OWNER_PID && bmc_stale && !stale_hold_committed) begin
|
|
|
- global_fault <= 1;
|
|
|
- work_index <= 0;
|
|
|
- commit_kind <= COMMIT_SAFE;
|
|
|
+ safe_pending <= 0; work_index <= 0; commit_kind <= COMMIT_SAFE;
|
|
|
work_state <= W_SAFE_FILL;
|
|
|
end
|
|
|
end
|
|
|
- W_SAFETY_PREFETCH: begin
|
|
|
- work_state <= W_SAFETY_CHECK;
|
|
|
- end
|
|
|
- W_SAFETY_CHECK: begin
|
|
|
- if (channel_over_76)
|
|
|
- safety_override_mask[work_index] <= 1;
|
|
|
- if (channel_over_77)
|
|
|
- epoch_hard_mask <= epoch_hard_mask | channel_lane_bit;
|
|
|
- if (channel_above_release)
|
|
|
- epoch_above_release_mask <= epoch_above_release_mask | channel_lane_bit;
|
|
|
- if (work_index == 23) begin
|
|
|
- for (i = 0; i < 4; i = i + 1) begin
|
|
|
- if ((((epoch_hard_mask |
|
|
|
- (channel_over_77 ? channel_lane_bit : 4'd0)) >> i) & 4'd1) != 0) begin
|
|
|
- lane_fault_mask[i] <= 1;
|
|
|
- lane_release_count[i] <= 0;
|
|
|
- safety_override_mask[i*6 +: 6] <= 6'h3F;
|
|
|
- end else if (lane_fault_mask[i]) begin
|
|
|
- if (!complete_valid_bmc ||
|
|
|
- ((((epoch_above_release_mask |
|
|
|
- (channel_above_release ? channel_lane_bit : 4'd0)) >> i) & 4'd1) != 0)) begin
|
|
|
- lane_release_count[i] <= 0;
|
|
|
- safety_override_mask[i*6 +: 6] <= 6'h3F;
|
|
|
- end else if (lane_release_count[i] == 2) begin
|
|
|
- lane_fault_mask[i] <= 0;
|
|
|
- lane_release_count[i] <= 0;
|
|
|
- end else begin
|
|
|
- lane_release_count[i] <= lane_release_count[i] + 1'b1;
|
|
|
- safety_override_mask[i*6 +: 6] <= 6'h3F;
|
|
|
- end
|
|
|
- end
|
|
|
- end
|
|
|
- work_index <= 0;
|
|
|
- if (|newly_hard_mask) begin
|
|
|
- control_state <= OWNER_PID;
|
|
|
- if (manual_pending) begin
|
|
|
- manual_pending <= 0;
|
|
|
- manual_commit_done <= 1;
|
|
|
- manual_commit_ok <= 0;
|
|
|
- end
|
|
|
- commit_kind <= COMMIT_SAFE;
|
|
|
- work_state <= W_SAFE_FILL;
|
|
|
- end else if (control_state == OWNER_PID && complete_valid_bmc) begin
|
|
|
- work_state <= W_PID_PREFETCH;
|
|
|
- end else if (control_state == OWNER_PID) begin
|
|
|
- commit_kind <= COMMIT_SAFE;
|
|
|
- work_state <= W_SAFE_FILL;
|
|
|
- end else if (control_state == OWNER_MANUAL) begin
|
|
|
- commit_kind <= COMMIT_NONE;
|
|
|
- output_control_read_addr <= 0;
|
|
|
- work_state <= W_APPLY_PREFETCH;
|
|
|
- end else begin
|
|
|
- work_state <= W_IDLE;
|
|
|
- end
|
|
|
- end else begin
|
|
|
- work_index <= work_index + 1'b1;
|
|
|
- work_state <= W_SAFETY_PREFETCH;
|
|
|
- end
|
|
|
- end
|
|
|
W_MANUAL_COPY: begin
|
|
|
if (hard_protect) begin
|
|
|
- commit_kind <= COMMIT_NONE;
|
|
|
- manual_commit_done <= 1;
|
|
|
- manual_commit_ok <= 0;
|
|
|
- work_state <= W_IDLE;
|
|
|
- end else if (any_valid_bmc && bmc_epoch != manual_request_epoch) begin
|
|
|
- manual_pending <= 1;
|
|
|
- manual_request_epoch <= bmc_epoch;
|
|
|
- last_bmc_epoch <= bmc_epoch;
|
|
|
- work_index <= 0;
|
|
|
- safety_override_mask <= 0;
|
|
|
- epoch_hard_mask <= 0;
|
|
|
- epoch_above_release_mask <= 0;
|
|
|
- commit_kind <= COMMIT_NONE;
|
|
|
- work_state <= W_SAFETY_PREFETCH;
|
|
|
+ manual_commit_done <= 1'b1; manual_commit_ok <= 1'b0;
|
|
|
+ commit_kind <= COMMIT_NONE; work_state <= W_IDLE;
|
|
|
end else begin
|
|
|
- output_control_write <= 1;
|
|
|
+ output_control_write <= 1'b1;
|
|
|
output_control_addr <= work_index;
|
|
|
if (work_index < 24)
|
|
|
output_control_data <= {manual_data,
|
|
|
- (!bmc_stale && safety_override_mask[work_index]) ? 8'd0 : manual_data};
|
|
|
+ safety_override_mask[work_index] ? 8'd0 : manual_data};
|
|
|
else
|
|
|
- output_control_data <= {manual_data, manual_data};
|
|
|
- if (work_index == 31) begin
|
|
|
- work_index <= 0;
|
|
|
- work_state <= W_COMMIT_WAIT;
|
|
|
- end else work_index <= work_index + 1'b1;
|
|
|
+ output_control_data <= {manual_data,
|
|
|
+ lane_fault_mask[work_index[1:0]] ? 8'd100 : manual_data};
|
|
|
+ if (work_index == 31) begin work_index <= 0; work_state <= W_COMMIT_WAIT; end
|
|
|
+ else work_index <= work_index + 1'b1;
|
|
|
end
|
|
|
end
|
|
|
W_SAFE_FILL: begin
|
|
|
- output_control_write <= 1;
|
|
|
+ output_control_write <= 1'b1;
|
|
|
output_control_addr <= work_index;
|
|
|
output_control_data <= (work_index < 24) ? 16'h0000 :
|
|
|
- {FAN_SAFE_DUTY, lane_fault_mask[output_lane] ? 8'd100 : FAN_SAFE_DUTY};
|
|
|
- if (work_index < 24) begin
|
|
|
- pi_state_write <= 1;
|
|
|
- pi_state_write_addr <= work_index;
|
|
|
- pi_state_write_data <= 32'd0;
|
|
|
- end
|
|
|
- if (work_index == 31) begin
|
|
|
- work_index <= 0;
|
|
|
- work_state <= W_COMMIT_WAIT;
|
|
|
- end else work_index <= work_index + 1'b1;
|
|
|
+ {FAN_SAFE_DUTY, lane_fault_mask[work_index[1:0]] ? 8'd100 : FAN_SAFE_DUTY};
|
|
|
+ if (work_index == 31) begin work_index <= 0; work_state <= W_COMMIT_WAIT; end
|
|
|
+ else work_index <= work_index + 1'b1;
|
|
|
end
|
|
|
- W_PID_PREFETCH: begin
|
|
|
- work_state <= W_PID_WRITE;
|
|
|
+ W_SAFETY_PREFETCH: begin
|
|
|
+ work_state <= W_SAFETY_CHECK;
|
|
|
end
|
|
|
- W_PID_WRITE: begin
|
|
|
- output_control_write <= 1;
|
|
|
- output_control_addr <= work_index;
|
|
|
- if (!bmc_rd_valid) begin
|
|
|
- output_control_data <= 16'h0000;
|
|
|
- safety_override_mask[work_index] <= 1;
|
|
|
- end else begin
|
|
|
- output_control_data <= {pid_duty, pid_duty};
|
|
|
- if (!safety_override_mask[work_index] && !lane_fault_mask[channel_lane]) begin
|
|
|
- pi_state_write <= 1;
|
|
|
- pi_state_write_addr <= work_index;
|
|
|
- pi_state_write_data <= {pid_error, pi_applied_q8_8};
|
|
|
- end
|
|
|
- end
|
|
|
+ W_SAFETY_CHECK: begin
|
|
|
+ if (scan_over76) safety_override_mask[work_index] <= 1'b1;
|
|
|
+ if (scan_over77) epoch_hard_mask <= epoch_hard_mask | scan_lane_bit;
|
|
|
if (work_index == 23) begin
|
|
|
- work_index <= 24;
|
|
|
- work_state <= W_FAN_WRITE;
|
|
|
- end else begin
|
|
|
- work_index <= work_index + 1'b1;
|
|
|
- work_state <= W_PID_PREFETCH;
|
|
|
- end
|
|
|
- end
|
|
|
- W_FAN_WRITE: begin
|
|
|
- output_control_write <= 1;
|
|
|
- output_control_addr <= work_index;
|
|
|
- output_control_data <= {FAN_SAFE_DUTY,
|
|
|
- lane_fault_mask[output_lane] ? 8'd100 : FAN_SAFE_DUTY};
|
|
|
- if (work_index == 31) begin
|
|
|
+ lane_fault_mask <= scan_hard_final;
|
|
|
work_index <= 0;
|
|
|
output_control_read_addr <= 0;
|
|
|
work_state <= W_APPLY_PREFETCH;
|
|
|
- end else work_index <= work_index + 1'b1;
|
|
|
+ end else begin
|
|
|
+ work_index <= work_index + 1'b1;
|
|
|
+ work_state <= W_SAFETY_PREFETCH;
|
|
|
+ end
|
|
|
end
|
|
|
W_APPLY_PREFETCH: begin
|
|
|
output_control_read_addr <= work_index;
|
|
|
work_state <= W_APPLY_WRITE;
|
|
|
end
|
|
|
W_APPLY_WRITE: begin
|
|
|
- output_control_write <= 1;
|
|
|
+ output_control_write <= 1'b1;
|
|
|
output_control_addr <= work_index;
|
|
|
- if (work_index < 24 && control_state == OWNER_MANUAL)
|
|
|
- output_control_data <= {manual_data,
|
|
|
- (lane_fault_mask[channel_lane] || safety_override_mask[work_index]) ?
|
|
|
- 8'd0 : manual_data};
|
|
|
- else if (work_index < 24)
|
|
|
+ if (work_index < 24)
|
|
|
output_control_data <= {output_control_requested,
|
|
|
- (lane_fault_mask[channel_lane] || safety_override_mask[work_index]) ?
|
|
|
- 8'd0 : output_control_requested};
|
|
|
- else if (control_state == OWNER_MANUAL)
|
|
|
- output_control_data <= {manual_data,
|
|
|
- lane_fault_mask[output_lane] ? 8'd100 : manual_data};
|
|
|
+ safety_override_mask[work_index] ? 8'd0 : output_control_requested};
|
|
|
else
|
|
|
output_control_data <= {output_control_requested,
|
|
|
- lane_fault_mask[output_lane] ? 8'd100 : output_control_requested};
|
|
|
+ lane_fault_mask[work_index[1:0]] ? 8'd100 : output_control_requested};
|
|
|
if (work_index == 31) begin
|
|
|
- work_index <= 0;
|
|
|
- commit_kind <= (control_state == OWNER_PID) ? COMMIT_PID : COMMIT_NONE;
|
|
|
- work_state <= W_COMMIT_WAIT;
|
|
|
+ work_index <= 0; commit_kind <= COMMIT_SAFE; work_state <= W_COMMIT_WAIT;
|
|
|
end else begin
|
|
|
work_index <= work_index + 1'b1;
|
|
|
output_control_read_addr <= work_index + 1'b1;
|
|
|
@@ -486,43 +242,19 @@ module thermal_control_core #(
|
|
|
end
|
|
|
end
|
|
|
W_COMMIT_WAIT: begin
|
|
|
- if (commit_kind == COMMIT_MANUAL && hard_protect) begin
|
|
|
- manual_commit_done <= 1;
|
|
|
- manual_commit_ok <= 0;
|
|
|
- commit_kind <= COMMIT_NONE;
|
|
|
- work_state <= W_IDLE;
|
|
|
- end else if (commit_kind == COMMIT_MANUAL && any_valid_bmc &&
|
|
|
- bmc_epoch != manual_request_epoch) begin
|
|
|
- manual_pending <= 1;
|
|
|
- manual_request_epoch <= bmc_epoch;
|
|
|
- last_bmc_epoch <= bmc_epoch;
|
|
|
- work_index <= 0;
|
|
|
- safety_override_mask <= 0;
|
|
|
- epoch_hard_mask <= 0;
|
|
|
- epoch_above_release_mask <= 0;
|
|
|
- commit_kind <= COMMIT_NONE;
|
|
|
- work_state <= W_SAFETY_PREFETCH;
|
|
|
- end else if (pwm_phase_boundary && pwm_scan_idle && !snapshot_lock) begin
|
|
|
+ if (pwm_phase_boundary && pwm_scan_idle && !snapshot_lock) begin
|
|
|
active_output_bank <= ~active_output_bank;
|
|
|
- output_commit <= 1;
|
|
|
+ output_commit <= 1'b1;
|
|
|
control_epoch <= control_epoch + 1'b1;
|
|
|
if (commit_kind == COMMIT_MANUAL) begin
|
|
|
- manual_commit_done <= 1;
|
|
|
- manual_commit_ok <= 1;
|
|
|
- control_state <= OWNER_MANUAL;
|
|
|
- watchdog_remaining <= WATCHDOG_LOAD;
|
|
|
- safe_pending <= 0;
|
|
|
- stale_hold_committed <= 0;
|
|
|
- end else if (commit_kind == COMMIT_SAFE) begin
|
|
|
- control_state <= OWNER_PID;
|
|
|
- watchdog_remaining <= 0;
|
|
|
- stale_hold_committed <= 1;
|
|
|
- end else if (commit_kind == COMMIT_PID) begin
|
|
|
- control_state <= OWNER_PID;
|
|
|
- stale_hold_committed <= 0;
|
|
|
+ manual_commit_done <= 1'b1; manual_commit_ok <= 1'b1;
|
|
|
+ control_state <= OWNER_MANUAL; watchdog_remaining <= WATCHDOG_LOAD;
|
|
|
+ global_fault <= 1'b0;
|
|
|
+ end else begin
|
|
|
+ control_state <= OWNER_SAFE; watchdog_remaining <= 0;
|
|
|
+ global_fault <= |lane_fault_mask;
|
|
|
end
|
|
|
- commit_kind <= COMMIT_NONE;
|
|
|
- work_state <= W_IDLE;
|
|
|
+ commit_kind <= COMMIT_NONE; work_state <= W_IDLE;
|
|
|
end
|
|
|
end
|
|
|
default: work_state <= W_INIT;
|