|
@@ -1,20 +1,20 @@
|
|
|
-"""L7 bit-exact differential checks against the thermal-control-lab model."""
|
|
|
|
|
|
|
+"""Current 6400 bit-exact PI differential against the canonical lab model."""
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
|
|
+import os
|
|
|
import sys
|
|
import sys
|
|
|
|
|
|
|
|
import cocotb
|
|
import cocotb
|
|
|
-from cocotb.triggers import FallingEdge, ReadOnly, RisingEdge, Timer, with_timeout
|
|
|
|
|
|
|
+from cocotb.triggers import FallingEdge, ReadOnly, RisingEdge, with_timeout
|
|
|
|
|
|
|
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
-LAB_ROOT = ROOT.parent / "thermal-control-lab"
|
|
|
|
|
-if not LAB_ROOT.is_dir():
|
|
|
|
|
- raise RuntimeError(f"thermal-control-lab sibling is required for L7: {LAB_ROOT}")
|
|
|
|
|
|
|
+LAB_ROOT = Path(os.environ.get(
|
|
|
|
|
+ "THERMAL_CONTROL_LAB_ROOT", "/root/workspaces/thermal-system/thermal-control-lab"
|
|
|
|
|
+))
|
|
|
sys.path.insert(0, str(LAB_ROOT))
|
|
sys.path.insert(0, str(LAB_ROOT))
|
|
|
-
|
|
|
|
|
from thermal_control_lab.fixed_point import ControllerBank, PIConfig # noqa: E402
|
|
from thermal_control_lab.fixed_point import ControllerBank, PIConfig # noqa: E402
|
|
|
|
|
|
|
|
|
|
|
|
@@ -22,319 +22,162 @@ FULL_VALID = (1 << 24) - 1
|
|
|
|
|
|
|
|
|
|
|
|
|
def raw_from_centi(value: int) -> int:
|
|
def raw_from_centi(value: int) -> int:
|
|
|
- if not 0 <= value <= 25_499:
|
|
|
|
|
- raise ValueError(f"BMC test temperature out of range: {value}")
|
|
|
|
|
integer, fraction = divmod(value, 100)
|
|
integer, fraction = divmod(value, 100)
|
|
|
return (integer << 8) | fraction
|
|
return (integer << 8) | fraction
|
|
|
|
|
|
|
|
|
|
|
|
|
-def errors_for(target_c: int, temperatures: list[int]) -> list[int]:
|
|
|
|
|
- return [target_c * 100 - value for value in temperatures]
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-async def clock_cycles(dut, count: int) -> None:
|
|
|
|
|
|
|
+async def cycles(dut, count: int) -> None:
|
|
|
for _ in range(count):
|
|
for _ in range(count):
|
|
|
await RisingEdge(dut.sys_clk)
|
|
await RisingEdge(dut.sys_clk)
|
|
|
|
|
|
|
|
|
|
|
|
|
-async def wait_for(dut, predicate, *, cycles: int, label: str) -> None:
|
|
|
|
|
- for _ in range(cycles):
|
|
|
|
|
|
|
+async def pulse(dut, signal) -> None:
|
|
|
|
|
+ await FallingEdge(dut.sys_clk)
|
|
|
|
|
+ signal.value = 1
|
|
|
|
|
+ await FallingEdge(dut.sys_clk)
|
|
|
|
|
+ signal.value = 0
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async def wait_value(dut, signal, value: int, limit: int, label: str) -> None:
|
|
|
|
|
+ for _ in range(limit):
|
|
|
await RisingEdge(dut.sys_clk)
|
|
await RisingEdge(dut.sys_clk)
|
|
|
await ReadOnly()
|
|
await ReadOnly()
|
|
|
- if predicate():
|
|
|
|
|
|
|
+ if int(signal.value) == value:
|
|
|
return
|
|
return
|
|
|
raise AssertionError(f"timeout waiting for {label}")
|
|
raise AssertionError(f"timeout waiting for {label}")
|
|
|
|
|
|
|
|
|
|
|
|
|
-async def load_temperatures(dut, temperatures: list[int]) -> None:
|
|
|
|
|
- assert len(temperatures) == 24
|
|
|
|
|
|
|
+async def load_epoch(dut, epoch: int, temperatures: list[int], valid_mask: int = FULL_VALID) -> None:
|
|
|
await FallingEdge(dut.sys_clk)
|
|
await FallingEdge(dut.sys_clk)
|
|
|
dut.bmc_wr_en.value = 1
|
|
dut.bmc_wr_en.value = 1
|
|
|
- for index, value in enumerate(temperatures):
|
|
|
|
|
|
|
+ for index, temperature in enumerate(temperatures):
|
|
|
dut.bmc_wr_index.value = index
|
|
dut.bmc_wr_index.value = index
|
|
|
- dut.bmc_wr_raw.value = raw_from_centi(value)
|
|
|
|
|
|
|
+ dut.bmc_wr_raw.value = raw_from_centi(temperature)
|
|
|
await FallingEdge(dut.sys_clk)
|
|
await FallingEdge(dut.sys_clk)
|
|
|
dut.bmc_wr_en.value = 0
|
|
dut.bmc_wr_en.value = 0
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-async def set_epoch(
|
|
|
|
|
- dut,
|
|
|
|
|
- epoch: int,
|
|
|
|
|
- temperatures: list[int],
|
|
|
|
|
- *,
|
|
|
|
|
- valid_mask: int = FULL_VALID,
|
|
|
|
|
-) -> None:
|
|
|
|
|
- await load_temperatures(dut, temperatures)
|
|
|
|
|
- await FallingEdge(dut.sys_clk)
|
|
|
|
|
dut.bmc_valid_mask_test.value = valid_mask
|
|
dut.bmc_valid_mask_test.value = valid_mask
|
|
|
- dut.bmc_epoch_test.value = epoch & 0xFFFF
|
|
|
|
|
|
|
+ dut.bmc_epoch_test.value = epoch
|
|
|
|
|
|
|
|
|
|
|
|
|
-async def wait_commit(dut, previous_count: int, label: str) -> None:
|
|
|
|
|
- await wait_for(
|
|
|
|
|
- dut,
|
|
|
|
|
- lambda: int(dut.commit_count_mon.value) > previous_count,
|
|
|
|
|
- cycles=500,
|
|
|
|
|
- label=label,
|
|
|
|
|
- )
|
|
|
|
|
|
|
+async def wait_commit(dut, before: int, label: str) -> None:
|
|
|
|
|
+ for _ in range(500):
|
|
|
|
|
+ await RisingEdge(dut.sys_clk)
|
|
|
|
|
+ await ReadOnly()
|
|
|
|
|
+ if int(dut.commit_count_mon.value) > before:
|
|
|
|
|
+ return
|
|
|
|
|
+ raise AssertionError(f"timeout waiting for {label}")
|
|
|
|
|
|
|
|
|
|
|
|
|
-async def read_outputs(dut) -> tuple[list[int], list[int], list[int], list[int]]:
|
|
|
|
|
- requested: list[int] = []
|
|
|
|
|
- applied: list[int] = []
|
|
|
|
|
- previous_error: list[int] = []
|
|
|
|
|
- previous_output: list[int] = []
|
|
|
|
|
|
|
+async def read_outputs_and_state(dut) -> tuple[list[int], list[int], list[int]]:
|
|
|
|
|
+ outputs: list[int] = []
|
|
|
|
|
+ errors: list[int] = []
|
|
|
|
|
+ state_outputs: list[int] = []
|
|
|
for index in range(32):
|
|
for index in range(32):
|
|
|
await FallingEdge(dut.sys_clk)
|
|
await FallingEdge(dut.sys_clk)
|
|
|
dut.rd_index.value = index
|
|
dut.rd_index.value = index
|
|
|
await RisingEdge(dut.sys_clk)
|
|
await RisingEdge(dut.sys_clk)
|
|
|
await ReadOnly()
|
|
await ReadOnly()
|
|
|
- requested.append(int(dut.requested_data.value))
|
|
|
|
|
- applied.append(int(dut.applied_data.value))
|
|
|
|
|
|
|
+ outputs.append(int(dut.applied_data.value))
|
|
|
if index < 24:
|
|
if index < 24:
|
|
|
- error = int(dut.previous_error_data.value)
|
|
|
|
|
- previous_error.append(error - 0x10000 if error & 0x8000 else error)
|
|
|
|
|
- previous_output.append(int(dut.previous_output_data.value))
|
|
|
|
|
- return requested, applied, previous_error, previous_output
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-async def compare_epoch(
|
|
|
|
|
- dut,
|
|
|
|
|
- model: ControllerBank,
|
|
|
|
|
- epoch: int,
|
|
|
|
|
- temperatures: list[int],
|
|
|
|
|
- *,
|
|
|
|
|
- target_c: int = 70,
|
|
|
|
|
- valid_mask: int = FULL_VALID,
|
|
|
|
|
- override: list[bool] | None = None,
|
|
|
|
|
- expected_fans: list[int] | None = None,
|
|
|
|
|
- label: str,
|
|
|
|
|
-) -> tuple[list[int], list[int]]:
|
|
|
|
|
|
|
+ raw_error = int(dut.previous_error_data.value)
|
|
|
|
|
+ errors.append(raw_error - 0x10000 if raw_error & 0x8000 else raw_error)
|
|
|
|
|
+ state_outputs.append(int(dut.previous_output_data.value))
|
|
|
|
|
+ return outputs, errors, state_outputs
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async def compare_epoch(dut, model: ControllerBank, epoch: int, temperatures: list[int], label: str) -> None:
|
|
|
before = int(dut.commit_count_mon.value)
|
|
before = int(dut.commit_count_mon.value)
|
|
|
- await set_epoch(dut, epoch, temperatures, valid_mask=valid_mask)
|
|
|
|
|
|
|
+ await load_epoch(dut, epoch, temperatures)
|
|
|
await wait_commit(dut, before, label)
|
|
await wait_commit(dut, before, label)
|
|
|
- valid = [bool(valid_mask & (1 << index)) for index in range(24)]
|
|
|
|
|
- expected = model.update(
|
|
|
|
|
- epoch,
|
|
|
|
|
- errors_for(target_c, temperatures),
|
|
|
|
|
- valid,
|
|
|
|
|
- safety_override=override,
|
|
|
|
|
- )
|
|
|
|
|
- requested, applied, previous_error, previous_output = await read_outputs(dut)
|
|
|
|
|
- assert applied[:24] == expected, f"{label}: applied RTL/Python mismatch"
|
|
|
|
|
- assert all(0 <= value <= 100 for value in requested + applied)
|
|
|
|
|
- if override is None and valid_mask == FULL_VALID:
|
|
|
|
|
- assert requested[:24] == expected, f"{label}: requested RTL/Python mismatch"
|
|
|
|
|
- expected_state_error = [state.previous_error_centi for state in model.states]
|
|
|
|
|
- expected_state_output = [state.previous_output_q8_8 for state in model.states]
|
|
|
|
|
- assert previous_error == expected_state_error, f"{label}: error-state mismatch"
|
|
|
|
|
- assert previous_output == expected_state_output, f"{label}: output-state mismatch"
|
|
|
|
|
- fans = expected_fans or [30] * 8
|
|
|
|
|
- assert applied[24:] == fans, f"{label}: fan safety mismatch"
|
|
|
|
|
- return requested, applied
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-async def bootstrap_auto(dut, temperatures: list[int], start_epoch: int = 1) -> int:
|
|
|
|
|
- await wait_for(
|
|
|
|
|
- dut,
|
|
|
|
|
- lambda: int(dut.control_state.value) == 2,
|
|
|
|
|
- cycles=50,
|
|
|
|
|
- label="PREHEAT_CT",
|
|
|
|
|
- )
|
|
|
|
|
- await set_epoch(dut, start_epoch, temperatures)
|
|
|
|
|
- await wait_for(
|
|
|
|
|
- dut,
|
|
|
|
|
- lambda: int(dut.control_state.value) == 3,
|
|
|
|
|
- cycles=50,
|
|
|
|
|
- label="WAIT_BMC_STABLE",
|
|
|
|
|
- )
|
|
|
|
|
- for epoch in (start_epoch + 1, start_epoch + 2):
|
|
|
|
|
- await set_epoch(dut, epoch, temperatures)
|
|
|
|
|
- await clock_cycles(dut, 8)
|
|
|
|
|
- return start_epoch + 3
|
|
|
|
|
|
|
+ expected = model.update(epoch, [7000 - value for value in temperatures], [True] * 24)
|
|
|
|
|
+ outputs, errors, state_outputs = await read_outputs_and_state(dut)
|
|
|
|
|
+ assert outputs[:24] == expected, f"{label}: output mismatch"
|
|
|
|
|
+ assert outputs[24:] == [20] * 8, f"{label}: fan policy mismatch"
|
|
|
|
|
+ assert errors == [state.previous_error_centi for state in model.states]
|
|
|
|
|
+ assert state_outputs == [state.previous_output_q8_8 for state in model.states]
|
|
|
|
|
|
|
|
|
|
|
|
|
@cocotb.test()
|
|
@cocotb.test()
|
|
|
-async def test_pi_python_rtl_differential_safety_epoch_target_and_recovery(dut):
|
|
|
|
|
|
|
+async def test_current_incremental_pi_epoch_manual_and_stale_semantics(dut):
|
|
|
dut.tick_1s_test.value = 0
|
|
dut.tick_1s_test.value = 0
|
|
|
dut.target_commit_test.value = 0
|
|
dut.target_commit_test.value = 0
|
|
|
dut.target_celsius_test.value = 70
|
|
dut.target_celsius_test.value = 70
|
|
|
|
|
+ dut.manual_wr_en_test.value = 0
|
|
|
|
|
+ dut.manual_wr_addr_test.value = 0
|
|
|
|
|
+ dut.manual_wr_data_test.value = 0
|
|
|
|
|
+ dut.manual_commit_test.value = 0
|
|
|
dut.bmc_epoch_test.value = 0
|
|
dut.bmc_epoch_test.value = 0
|
|
|
- dut.bmc_stale_test.value = 0
|
|
|
|
|
- dut.bmc_valid_mask_test.value = FULL_VALID
|
|
|
|
|
|
|
+ dut.bmc_stale_test.value = 1
|
|
|
|
|
+ dut.bmc_valid_mask_test.value = 0
|
|
|
dut.bmc_wr_en.value = 0
|
|
dut.bmc_wr_en.value = 0
|
|
|
dut.bmc_wr_index.value = 0
|
|
dut.bmc_wr_index.value = 0
|
|
|
dut.bmc_wr_raw.value = 0
|
|
dut.bmc_wr_raw.value = 0
|
|
|
- dut.ct_epoch_test.value = 1
|
|
|
|
|
- dut.ct_stale_test.value = 0
|
|
|
|
|
- dut.ct_valid_mask_test.value = (1 << 27) - 1
|
|
|
|
|
|
|
+ dut.ct_epoch_test.value = 0
|
|
|
|
|
+ dut.ct_stale_test.value = 1
|
|
|
|
|
+ dut.ct_valid_mask_test.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")
|
|
|
|
|
|
|
|
|
|
+ # Three override ticks model the production 30-second lease expiration.
|
|
|
|
|
+ for _ in range(3):
|
|
|
|
|
+ await pulse(dut, dut.tick_1s_test)
|
|
|
|
|
+ await wait_value(dut, dut.control_state, 2, 500, "SAFE to PID")
|
|
|
|
|
+ outputs, _, _ = await read_outputs_and_state(dut)
|
|
|
|
|
+ assert outputs == [0] * 24 + [20] * 8
|
|
|
|
|
+
|
|
|
model = ControllerBank(PIConfig(32, 4), PIConfig(24, 3))
|
|
model = ControllerBank(PIConfig(32, 4), PIConfig(24, 3))
|
|
|
|
|
+ await FallingEdge(dut.sys_clk)
|
|
|
|
|
+ dut.bmc_stale_test.value = 0
|
|
|
temperatures = [6500 + ((index * 37) % 400) for index in range(24)]
|
|
temperatures = [6500 + ((index * 37) % 400) for index in range(24)]
|
|
|
- epoch = await bootstrap_auto(dut, temperatures)
|
|
|
|
|
- await compare_epoch(dut, model, epoch, temperatures, label="initial mixed edge/center pass")
|
|
|
|
|
-
|
|
|
|
|
- # The same BMC epoch is a strict hold: no reintegration and no new bank flip.
|
|
|
|
|
- held_commit = int(dut.commit_count_mon.value)
|
|
|
|
|
- held_outputs = (await read_outputs(dut))[1]
|
|
|
|
|
- assert model.update(epoch, errors_for(70, temperatures), [True] * 24) == held_outputs[:24]
|
|
|
|
|
- await clock_cycles(dut, 300)
|
|
|
|
|
- assert int(dut.commit_count_mon.value) == held_commit
|
|
|
|
|
- assert (await read_outputs(dut))[1] == held_outputs
|
|
|
|
|
-
|
|
|
|
|
- # Mixed fractional errors cover both coefficient classes and half-away
|
|
|
|
|
- # rounding. Repeated cold epochs then hit slew and upper anti-windup.
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- temperatures = [6999 - ((index * 7) % 180) for index in range(24)]
|
|
|
|
|
- await compare_epoch(dut, model, epoch, temperatures, label="fractional rounding")
|
|
|
|
|
- for iteration in range(24):
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- temperatures = [2000 + ((index * 11 + iteration) % 90) for index in range(24)]
|
|
|
|
|
- await compare_epoch(dut, model, epoch, temperatures, label=f"positive slew {iteration}")
|
|
|
|
|
- assert max(model.outputs_q8_8) == 25_600
|
|
|
|
|
|
|
+ await compare_epoch(dut, model, 1, temperatures, "mixed EDGE/CENTER")
|
|
|
|
|
+
|
|
|
|
|
+ # Same epoch is a strict hold with no Bank churn or repeated integration.
|
|
|
|
|
+ held = int(dut.commit_count_mon.value)
|
|
|
|
|
+ await cycles(dut, 300)
|
|
|
|
|
+ assert int(dut.commit_count_mon.value) == held
|
|
|
|
|
|
|
|
- # Hold at saturation, then prove the negative slew path is equally exact.
|
|
|
|
|
- for iteration in range(2):
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- await compare_epoch(dut, model, epoch, temperatures, label=f"anti-windup hold {iteration}")
|
|
|
|
|
- for iteration in range(5):
|
|
|
|
|
- epoch += 1
|
|
|
|
|
|
|
+ for epoch in range(2, 28):
|
|
|
|
|
+ temperatures = [2000 + ((index * 11 + epoch) % 90) for index in range(24)]
|
|
|
|
|
+ await compare_epoch(dut, model, epoch, temperatures, f"positive slew {epoch}")
|
|
|
|
|
+ assert max(model.outputs_q8_8) == 25_600
|
|
|
|
|
+ for epoch in range(28, 34):
|
|
|
temperatures = [7399 - (index % 5) for index in range(24)]
|
|
temperatures = [7399 - (index % 5) for index in range(24)]
|
|
|
- await compare_epoch(dut, model, epoch, temperatures, label=f"negative slew {iteration}")
|
|
|
|
|
-
|
|
|
|
|
- # A single invalid channel is off while its PI state freezes. When the
|
|
|
|
|
- # channel becomes valid, the Python and RTL paths resume from that state.
|
|
|
|
|
- invalid_mask = FULL_VALID ^ 1
|
|
|
|
|
- frozen_state = model.states[0]
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- await compare_epoch(
|
|
|
|
|
- dut,
|
|
|
|
|
- model,
|
|
|
|
|
- epoch,
|
|
|
|
|
- temperatures,
|
|
|
|
|
- valid_mask=invalid_mask,
|
|
|
|
|
- label="single invalid freeze",
|
|
|
|
|
- )
|
|
|
|
|
- assert model.states[0] == frozen_state
|
|
|
|
|
- temperatures = [7100] * 24
|
|
|
|
|
- for iteration in range(3):
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- await compare_epoch(dut, model, epoch, temperatures, label=f"invalid recovery {iteration}")
|
|
|
|
|
- assert int(dut.control_state.value) == 4
|
|
|
|
|
-
|
|
|
|
|
- # Pretrip clears one production controller, forces its PTC off, and raises
|
|
|
|
|
- # both lane fans. The reference is explicitly rebased for safe recovery.
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- temperatures = [6900] * 24
|
|
|
|
|
- temperatures[6] = 7600
|
|
|
|
|
- override = [index == 6 for index in range(24)]
|
|
|
|
|
- await compare_epoch(
|
|
|
|
|
- dut,
|
|
|
|
|
- model,
|
|
|
|
|
- epoch,
|
|
|
|
|
- temperatures,
|
|
|
|
|
- override=override,
|
|
|
|
|
- expected_fans=[30, 80, 30, 30, 30, 80, 30, 30],
|
|
|
|
|
- label="76 C pretrip",
|
|
|
|
|
- )
|
|
|
|
|
- model.clear_channels([6])
|
|
|
|
|
- temperatures = [6900] * 24
|
|
|
|
|
- for iteration in range(3):
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- await compare_epoch(dut, model, epoch, temperatures, label=f"pretrip recovery {iteration}")
|
|
|
|
|
-
|
|
|
|
|
- # A 77 C sample clamps and clears the complete six-channel lane. Three
|
|
|
|
|
- # safe epochs retain zero duty; the next epoch ramps from the cleared state.
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- temperatures[12] = 7700
|
|
|
|
|
- lane_override = [12 <= index < 18 for index in range(24)]
|
|
|
|
|
- await compare_epoch(
|
|
|
|
|
- dut,
|
|
|
|
|
- model,
|
|
|
|
|
- epoch,
|
|
|
|
|
- temperatures,
|
|
|
|
|
- override=lane_override,
|
|
|
|
|
- expected_fans=[30, 30, 100, 30, 30, 30, 100, 30],
|
|
|
|
|
- label="77 C lane hard clamp",
|
|
|
|
|
- )
|
|
|
|
|
- assert int(dut.lane_fault_mask.value) & (1 << 2)
|
|
|
|
|
- model.clear_channels(range(12, 18))
|
|
|
|
|
- temperatures[12] = 6900
|
|
|
|
|
- for iteration in range(3):
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- recovery_fans = (
|
|
|
|
|
- [30, 30, 100, 30, 30, 30, 100, 30]
|
|
|
|
|
- if iteration < 2
|
|
|
|
|
- else [30] * 8
|
|
|
|
|
- )
|
|
|
|
|
- await compare_epoch(
|
|
|
|
|
- dut,
|
|
|
|
|
- model,
|
|
|
|
|
- epoch,
|
|
|
|
|
- temperatures,
|
|
|
|
|
- override=lane_override,
|
|
|
|
|
- expected_fans=recovery_fans,
|
|
|
|
|
- label=f"hard-clamp recovery hold {iteration}",
|
|
|
|
|
- )
|
|
|
|
|
- assert int(dut.lane_fault_mask.value) == 0
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- await compare_epoch(dut, model, epoch, temperatures, label="hard-clamp limited restart")
|
|
|
|
|
-
|
|
|
|
|
- # Runtime stale preempts without a new epoch, atomically fills 0/100 safe
|
|
|
|
|
- # outputs, and requires three fresh recovery epochs before limited restart.
|
|
|
|
|
- before = int(dut.commit_count_mon.value)
|
|
|
|
|
|
|
+ await compare_epoch(dut, model, epoch, temperatures, f"negative rounding {epoch}")
|
|
|
|
|
+
|
|
|
|
|
+ # Manual SET_ALL freezes hidden PI state while BMC epochs continue.
|
|
|
|
|
+ frozen = list(model.states)
|
|
|
await FallingEdge(dut.sys_clk)
|
|
await FallingEdge(dut.sys_clk)
|
|
|
- dut.bmc_stale_test.value = 1
|
|
|
|
|
- await wait_commit(dut, before, "global stale safe fill")
|
|
|
|
|
- _, stale_applied, _, _ = await read_outputs(dut)
|
|
|
|
|
- assert stale_applied == [0] * 24 + [100] * 8
|
|
|
|
|
- assert model.update(epoch, errors_for(70, temperatures), [True] * 24, stale=True) == [0] * 24
|
|
|
|
|
|
|
+ dut.manual_wr_en_test.value = 1
|
|
|
|
|
+ for index in range(32):
|
|
|
|
|
+ dut.manual_wr_addr_test.value = index
|
|
|
|
|
+ dut.manual_wr_data_test.value = 40 if index < 24 else 20
|
|
|
|
|
+ await FallingEdge(dut.sys_clk)
|
|
|
|
|
+ dut.manual_wr_en_test.value = 0
|
|
|
|
|
+ await pulse(dut, dut.manual_commit_test)
|
|
|
|
|
+ await wait_value(dut, dut.manual_commit_done, 1, 500, "manual commit")
|
|
|
|
|
+ assert int(dut.manual_commit_ok.value) == 1
|
|
|
|
|
+ await load_epoch(dut, 34, [6000] * 24)
|
|
|
|
|
+ await cycles(dut, 300)
|
|
|
|
|
+ _, errors, state_outputs = await read_outputs_and_state(dut)
|
|
|
|
|
+ assert errors == [state.previous_error_centi for state in frozen]
|
|
|
|
|
+ assert state_outputs == [state.previous_output_q8_8 for state in frozen]
|
|
|
|
|
+
|
|
|
|
|
+ # Manual timeout atomically returns to 0/20 PID wait and clears PI state.
|
|
|
|
|
+ for _ in range(3):
|
|
|
|
|
+ await pulse(dut, dut.tick_1s_test)
|
|
|
|
|
+ await wait_value(dut, dut.control_state, 2, 500, "MANUAL to PID")
|
|
|
|
|
+ outputs, errors, state_outputs = await read_outputs_and_state(dut)
|
|
|
|
|
+ assert outputs == [0] * 24 + [20] * 8
|
|
|
|
|
+ assert errors == [0] * 24 and state_outputs == [0] * 24
|
|
|
|
|
+
|
|
|
|
|
+ # Resume PID on a new valid epoch, then persistent stale performs exactly
|
|
|
|
|
+ # one safe transition and no subsequent Bank churn.
|
|
|
model.stop()
|
|
model.stop()
|
|
|
|
|
+ await compare_epoch(dut, model, 35, [6500] * 24, "post-manual PID restart")
|
|
|
await FallingEdge(dut.sys_clk)
|
|
await FallingEdge(dut.sys_clk)
|
|
|
- dut.bmc_stale_test.value = 0
|
|
|
|
|
- all_override = [True] * 24
|
|
|
|
|
- for iteration in range(3):
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- recovery_fans = [100] * 8 if iteration < 2 else [30] * 8
|
|
|
|
|
- await compare_epoch(
|
|
|
|
|
- dut,
|
|
|
|
|
- model,
|
|
|
|
|
- epoch,
|
|
|
|
|
- temperatures,
|
|
|
|
|
- override=all_override,
|
|
|
|
|
- expected_fans=recovery_fans,
|
|
|
|
|
- label=f"stale recovery hold {iteration}",
|
|
|
|
|
- )
|
|
|
|
|
- assert int(dut.global_fault.value) == 0
|
|
|
|
|
- epoch += 1
|
|
|
|
|
- await compare_epoch(dut, model, epoch, temperatures, label="stale limited restart")
|
|
|
|
|
-
|
|
|
|
|
- # Target changes clear the PI path, commit a safe image, and require the
|
|
|
|
|
- # CT/BMC qualification sequence before the new-target Python path runs.
|
|
|
|
|
|
|
+ dut.bmc_stale_test.value = 1
|
|
|
before = int(dut.commit_count_mon.value)
|
|
before = int(dut.commit_count_mon.value)
|
|
|
- await FallingEdge(dut.sys_clk)
|
|
|
|
|
- dut.target_celsius_test.value = 60
|
|
|
|
|
- dut.target_commit_test.value = 1
|
|
|
|
|
- await FallingEdge(dut.sys_clk)
|
|
|
|
|
- dut.target_commit_test.value = 0
|
|
|
|
|
- await wait_commit(dut, before, "target-change safe fill")
|
|
|
|
|
- assert (await read_outputs(dut))[1][:24] == [0] * 24
|
|
|
|
|
- model.stop()
|
|
|
|
|
- await FallingEdge(dut.sys_clk)
|
|
|
|
|
- dut.ct_epoch_test.value = 2
|
|
|
|
|
- temperatures = [5500 + (index % 20) for index in range(24)]
|
|
|
|
|
- next_epoch = await bootstrap_auto(dut, temperatures, start_epoch=epoch + 1)
|
|
|
|
|
- await compare_epoch(
|
|
|
|
|
- dut,
|
|
|
|
|
- model,
|
|
|
|
|
- next_epoch,
|
|
|
|
|
- temperatures,
|
|
|
|
|
- target_c=60,
|
|
|
|
|
- label="new-target qualified restart",
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- assert int(dut.current_target_celsius.value) == 60
|
|
|
|
|
- assert int(dut.control_state.value) == 4
|
|
|
|
|
- assert int(dut.work_state_mon.value) == 0
|
|
|
|
|
|
|
+ await wait_commit(dut, before, "stale safe hold")
|
|
|
|
|
+ held = int(dut.commit_count_mon.value)
|
|
|
|
|
+ await cycles(dut, 500)
|
|
|
|
|
+ assert int(dut.commit_count_mon.value) == held
|