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

fix(rtl): enforce 6400 thermal protection priorities

root 3 месяцев назад
Родитель
Сommit
5dd3fcb56c
2 измененных файлов с 142 добавлено и 21 удалено
  1. 115 18
      src/control/thermal_control_core.v
  2. 27 3
      tests/sim/thermal_control_core_tb.v

+ 115 - 18
src/control/thermal_control_core.v

@@ -92,6 +92,12 @@ module thermal_control_core #(
     reg stimulus_running;
     reg [7:0] stimulus_remaining;
     reg [7:0] safe_fan_target;
+    // safety_override_mask is Host telemetry for every per-channel safety
+    // action.  Keep shutdown and airflow intent separate so the 74 C soft
+    // action can reduce (rather than zero) PTC duty while still raising both
+    // fans for the affected lane.
+    reg [23:0] ptc_shutdown_mask;
+    reg [23:0] thermal_protection_mask;
     reg sample_valid;
     reg signed [15:0] sample_error;
     reg signed [15:0] sample_temperature;
@@ -178,17 +184,36 @@ module thermal_control_core #(
         end
     endfunction
 
+    function lane_thermal_protection;
+        input [1:0] lane;
+        begin
+            case (lane)
+                0: lane_thermal_protection = |thermal_protection_mask[5:0];
+                1: lane_thermal_protection = |thermal_protection_mask[11:6];
+                2: lane_thermal_protection = |thermal_protection_mask[17:12];
+                default: lane_thermal_protection = |thermal_protection_mask[23:18];
+            endcase
+        end
+    endfunction
+
     wire [7:0] apply_ptc_value =
         (global_fault || control_state == STOPPED ||
          lane_fault_for_output(work_index) ||
          lane_invalid(lane_for_channel(work_index)) ||
-         safety_override_mask[work_index]) ? 8'd0 : inactive_request;
+         ptc_shutdown_mask[work_index]) ? 8'd0 : inactive_request;
     wire [7:0] apply_fan_value =
         (global_fault || lane_fault_for_output(work_index) ||
-         lane_invalid(lane_for_output(work_index))) ? 8'd100 : inactive_request;
+         lane_invalid(lane_for_output(work_index))) ? 8'd100 :
+        (lane_thermal_protection(lane_for_output(work_index)) ? 8'd80 : inactive_request);
     wire [7:0] safe_fill_value = (work_index < 24) ? 8'd0 :
         ((global_fault || lane_fault_for_output(work_index) ||
-          lane_invalid(lane_for_output(work_index))) ? 8'd100 : safe_fan_target);
+          lane_invalid(lane_for_output(work_index))) ? 8'd100 :
+         (lane_thermal_protection(lane_for_output(work_index)) ? 8'd80 : safe_fan_target));
+    // BMC age intentionally resets stale.  That is an acquisition-startup
+    // condition, not a runtime sensor failure: CT qualification and preheat
+    // must still run before BMC stability is evaluated.
+    wire bmc_stale_runtime = bmc_stale &&
+        (control_state == AUTO_BMC || control_state == SENSOR_DEGRADED);
 
     always @* begin
         mult_a = 0;
@@ -218,6 +243,8 @@ module thermal_control_core #(
             host_target_seen <= 0;
             control_epoch <= 0;
             safety_override_mask <= 0;
+            ptc_shutdown_mask <= 0;
+            thermal_protection_mask <= 0;
             lane_fault_mask <= 0;
             global_fault <= 0;
             output_commit <= 0;
@@ -280,12 +307,12 @@ module thermal_control_core #(
                 stimulus_running <= 0;
                 work_index <= 0;
                 work_state <= W_SAFE_FILL;
-                safe_fan_target <= (global_fault || bmc_stale) ? 8'd100 :
+                safe_fan_target <= (global_fault || bmc_stale_runtime) ? 8'd100 :
                     ((target_celsius == 0) ? 8'd30 : 8'd10);
-                global_fault <= global_fault || bmc_stale;
+                global_fault <= global_fault || bmc_stale_runtime;
                 if (target_celsius == 0)
                     control_state <= STOPPED;
-                else if (global_fault || bmc_stale)
+                else if (global_fault || bmc_stale_runtime)
                     control_state <= SENSOR_DEGRADED;
                 else
                     control_state <= WAIT_CT_VALID;
@@ -293,7 +320,7 @@ module thermal_control_core #(
                     previous_error[i] <= 0;
                     previous_output[i] <= 0;
                 end
-            end else if (bmc_stale && !global_fault && control_state != STOPPED && control_state != RESET_SAFE) begin
+            end else if (bmc_stale_runtime && !global_fault) begin
                 global_fault <= 1;
                 control_state <= SENSOR_DEGRADED;
                 stable_epochs <= 0;
@@ -363,6 +390,8 @@ module thermal_control_core #(
                         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;
+                            ptc_shutdown_mask[work_index] <= 1;
+                            thermal_protection_mask[work_index] <= 0;
                             previous_error[work_index] <= 0;
                             previous_output[work_index] <= 0;
                             epoch_safe <= 0;
@@ -376,6 +405,8 @@ module thermal_control_core #(
                         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;
+                            ptc_shutdown_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;
@@ -385,6 +416,8 @@ module thermal_control_core #(
                         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;
+                            ptc_shutdown_mask[work_index] <= 1;
+                            thermal_protection_mask[work_index] <= 1;
                             previous_error[work_index] <= 0;
                             previous_output[work_index] <= 0;
                             epoch_safe <= 0;
@@ -395,12 +428,17 @@ module thermal_control_core #(
                             // accumulated while the physical output was forced
                             // 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;
+                            ptc_shutdown_mask[work_index] <= 0;
+                            thermal_protection_mask[work_index] <= 0;
                             previous_error[work_index] <= 0;
                             previous_output[work_index] <= 0;
                         end else begin
-                            if (stimulus_running) begin
-                                if (active_output_bank) req0[work_index] <= stimulus_mem[work_index]; else req1[work_index] <= stimulus_mem[work_index];
-                            end else if (sample_temperature >= SOFT_LIMIT) begin
+                            // Safety precedes identification stimulus.  The
+                            // soft limit reduces the autonomous PI state by
+                            // one duty point and requests protection airflow,
+                            // but deliberately does not assert PTC shutdown.
+                            if (sample_temperature >= SOFT_LIMIT) begin
                                 if (active_output_bank)
                                     req0[work_index] <= reduced_duty;
                                 else
@@ -408,11 +446,20 @@ module thermal_control_core #(
                                 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;
+                                ptc_shutdown_mask[work_index] <= 0;
+                                thermal_protection_mask[work_index] <= 1;
+                            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;
+                                ptc_shutdown_mask[work_index] <= 0;
+                                thermal_protection_mask[work_index] <= 0;
                             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;
+                                ptc_shutdown_mask[work_index] <= 0;
+                                thermal_protection_mask[work_index] <= 0;
                             end
                             if (sample_temperature > recovery_threshold) epoch_safe <= 0;
                         end
@@ -496,9 +543,10 @@ module thermal_control_core #(
     wire [7:0] formal_safe_fill_value = (formal_duty_index < 24) ? 8'd0 :
         ((global_fault || lane_fault_for_output(formal_duty_index) ||
           lane_invalid(lane_for_output(formal_duty_index))) ?
-            8'd100 : safe_fan_target);
-    wire formal_stale_preempt = bmc_stale && !global_fault &&
-        control_state != STOPPED && control_state != RESET_SAFE;
+            8'd100 :
+         (lane_thermal_protection(lane_for_output(formal_duty_index)) ?
+            8'd80 : safe_fan_target));
+    wire formal_stale_preempt = bmc_stale_runtime && !global_fault;
 
     function [7:0] formal_work_rank;
         input [3:0] state_value;
@@ -549,6 +597,8 @@ module thermal_control_core #(
             assert(control_state == RESET_SAFE);
             assert(current_target_celsius == 70);
             assert(safety_override_mask == 0);
+            assert(ptc_shutdown_mask == 0);
+            assert(thermal_protection_mask == 0);
             assert(lane_fault_mask == 0);
             assert(!global_fault);
             if (formal_duty_index < 24) begin
@@ -568,11 +618,17 @@ module thermal_control_core #(
                 assert(work_index < 24);
             if (work_state == W_FANS)
                 assert(work_index >= 24);
+            // Reset-age stale must not bypass CT/preheat startup sequencing.
+            if (bmc_stale && (control_state == RESET_SAFE ||
+                              control_state == WAIT_CT_VALID ||
+                              control_state == PREHEAT_CT ||
+                              control_state == WAIT_BMC_STABLE))
+                assert(!formal_stale_preempt);
             // P02/P03/P04/P05/P16: the production apply datapath gives every
             // hard safety condition priority over an ordinary PTC request.
             if (work_state == W_APPLY && work_index == formal_ptc_index &&
                 (global_fault || control_state == STOPPED ||
-                 safety_override_mask[formal_ptc_index] ||
+                 ptc_shutdown_mask[formal_ptc_index] ||
                  lane_fault_mask[lane_for_channel(formal_ptc_index)] ||
                  lane_invalid(lane_for_channel(formal_ptc_index))))
                 assert(apply_ptc_value == 0);
@@ -586,7 +642,7 @@ module thermal_control_core #(
                 formal_duty_index < work_index) begin
                 if (formal_duty_index < 24 &&
                     (global_fault || control_state == STOPPED ||
-                     safety_override_mask[formal_duty_index] ||
+                     ptc_shutdown_mask[formal_duty_index] ||
                      lane_fault_mask[lane_for_channel(formal_duty_index)] ||
                      lane_invalid(lane_for_channel(formal_duty_index))))
                     assert(formal_inactive_applied == 0);
@@ -595,6 +651,12 @@ module thermal_control_core #(
                      lane_fault_for_output(formal_duty_index) ||
                      lane_invalid(lane_for_output(formal_duty_index))))
                     assert(formal_inactive_applied == 100);
+                if (formal_duty_index >= 24 &&
+                    !global_fault &&
+                    !lane_fault_for_output(formal_duty_index) &&
+                    !lane_invalid(lane_for_output(formal_duty_index)) &&
+                    lane_thermal_protection(lane_for_output(formal_duty_index)))
+                    assert(formal_inactive_applied == 80);
             end
 
             // Once a safety pass has committed, the active bank itself (not
@@ -604,7 +666,7 @@ module thermal_control_core #(
             if (work_state == W_IDLE) begin
                 if (formal_duty_index < 24 &&
                     (global_fault || control_state == STOPPED ||
-                     safety_override_mask[formal_duty_index] ||
+                     ptc_shutdown_mask[formal_duty_index] ||
                      lane_fault_mask[lane_for_channel(formal_duty_index)] ||
                      lane_invalid(lane_for_channel(formal_duty_index))))
                     assert(formal_active_applied == 0);
@@ -613,6 +675,12 @@ module thermal_control_core #(
                      lane_fault_for_output(formal_duty_index) ||
                      lane_invalid(lane_for_output(formal_duty_index))))
                     assert(formal_active_applied == 100);
+                if (formal_duty_index >= 24 &&
+                    !global_fault &&
+                    !lane_fault_for_output(formal_duty_index) &&
+                    !lane_invalid(lane_for_output(formal_duty_index)) &&
+                    lane_thermal_protection(lane_for_output(formal_duty_index)))
+                    assert(formal_active_applied == 80);
             end
             if (formal_past_valid && $past(rst_n)) begin
                 if ($past(formal_scheduler_rank) != 0 &&
@@ -636,6 +704,8 @@ module thermal_control_core #(
                           work_index == formal_ptc_index && !sample_valid &&
                           !target_commit && !formal_stale_preempt)) begin
                     assert(safety_override_mask[formal_ptc_index]);
+                    assert(ptc_shutdown_mask[formal_ptc_index]);
+                    assert(!thermal_protection_mask[formal_ptc_index]);
                     if ($past(active_output_bank))
                         assert(req0[formal_ptc_index] == 0);
                     else
@@ -647,8 +717,35 @@ module thermal_control_core #(
                 if ($past(work_state == W_UPDATE &&
                           work_index == formal_ptc_index && sample_valid &&
                           sample_temperature >= HARD_LIMIT &&
-                          !target_commit && !formal_stale_preempt))
+                          !target_commit && !formal_stale_preempt)) begin
                     assert(lane_fault_mask[lane_for_channel(formal_ptc_index)]);
+                    assert(ptc_shutdown_mask[formal_ptc_index]);
+                    assert(thermal_protection_mask[formal_ptc_index]);
+                end
+
+                // Soft and pretrip telemetry share the public override bit,
+                // but only pretrip shuts the PTC down.  Both request 80%
+                // airflow until a normal sample clears the channel masks.
+                if ($past(work_state == W_UPDATE &&
+                          work_index == formal_ptc_index && sample_valid &&
+                          sample_temperature >= PRETRIP_LIMIT &&
+                          sample_temperature < HARD_LIMIT &&
+                          !target_commit && !formal_stale_preempt)) begin
+                    assert(safety_override_mask[formal_ptc_index]);
+                    assert(ptc_shutdown_mask[formal_ptc_index]);
+                    assert(thermal_protection_mask[formal_ptc_index]);
+                end
+                if ($past(work_state == W_UPDATE &&
+                          work_index == formal_ptc_index && sample_valid &&
+                          sample_temperature >= SOFT_LIMIT &&
+                          sample_temperature < PRETRIP_LIMIT &&
+                          !global_fault &&
+                          !lane_fault_mask[lane_for_channel(formal_ptc_index)] &&
+                          !target_commit && !formal_stale_preempt)) begin
+                    assert(safety_override_mask[formal_ptc_index]);
+                    assert(!ptc_shutdown_mask[formal_ptc_index]);
+                    assert(thermal_protection_mask[formal_ptc_index]);
+                end
 
                 // Fault-clamped control passes cannot accumulate hidden PI
                 // state or a nonzero request for later release.
@@ -687,7 +784,7 @@ module thermal_control_core #(
                   formal_ptc_index < 24 &&
                   (active_output_bank ? app1[formal_ptc_index] :
                                         app0[formal_ptc_index]) == 0);
-            cover(safety_override_mask[formal_ptc_index] &&
+            cover(ptc_shutdown_mask[formal_ptc_index] &&
                   work_state == W_IDLE &&
                   (active_output_bank ? app1[formal_ptc_index] :
                                         app0[formal_ptc_index]) == 0);

+ 27 - 3
tests/sim/thermal_control_core_tb.v

@@ -7,7 +7,7 @@ module thermal_control_core_tb;
     reg target_commit = 0;
     reg [7:0] target = 70;
     reg [15:0] bmc_epoch = 0;
-    reg bmc_stale = 0;
+    reg bmc_stale = 1;
     reg [23:0] bmc_valid_mask = 24'hffffff;
     wire [4:0] bmc_index;
     reg [15:0] bmc_raw [0:23];
@@ -92,10 +92,11 @@ module thermal_control_core_tb;
         repeat (4) @(negedge clk);
         rst_n = 1;
         repeat (3) @(negedge clk);
-        if (state !== 1) $fatal;
+        if (state !== 1 || global_fault) $fatal;
         ct_epoch = 1;
         repeat (3) @(negedge clk);
-        if (state !== 2) $fatal;
+        if (state !== 2 || global_fault) $fatal;
+        bmc_stale = 0;
         next_bmc_epoch();
         if (state !== 3) $fatal;
         next_bmc_epoch();
@@ -105,6 +106,29 @@ module thermal_control_core_tb;
         if (state !== 4 || control_epoch == 0) $fatal;
         check_duty(0, 5);
         check_duty(24, 30);
+
+        // 74 C is a soft reduction, not a shutdown: retain a reduced PTC
+        // request and raise both fans for only the affected lane to 80%.
+        bmc_raw[0] = {8'd74, 8'd0};
+        i = commits;
+        next_bmc_epoch();
+        wait_commit_after(i);
+        if (!safety[0] || state !== 4) $fatal;
+        check_duty(0, 4);
+        check_duty(24, 80);
+        check_duty(28, 80);
+        check_duty(25, 30);
+
+        // 76 C shuts down only the matching PTC while retaining 80% lane
+        // airflow; the 77 C lane latch below remains the 100% action.
+        bmc_raw[0] = {8'd76, 8'd0};
+        i = commits;
+        next_bmc_epoch();
+        wait_commit_after(i);
+        if (!safety[0] || lane_fault[0] || state !== 5) $fatal;
+        check_duty(0, 0);
+        check_duty(24, 80);
+        check_duty(28, 80);
         bmc_raw[0] = {8'd77, 8'd0};
         i = commits;
         next_bmc_epoch();