From e905a35467d4ef8c1e1bb961b3b484594258f063 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 8 Jan 2024 15:09:38 -0800 Subject: [PATCH] tici: check that peripherals are fully booted (#30942) * tici: check that peripherals are fully booted * default * typo * fix --------- Co-authored-by: Comma Device old-commit-hash: 5f191321fddca4eafb55c992415209a9389e2617 --- selfdrive/thermald/thermald.py | 3 +++ system/hardware/base.py | 3 +++ system/hardware/tici/hardware.py | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 8b51aedbdb..7011ff0a99 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -312,6 +312,9 @@ def thermald_thread(end_event, hw_queue) -> None: # must be at an engageable thermal band to go onroad startup_conditions["device_temp_engageable"] = thermal_status < ThermalStatus.red + # ensure device is fully booted + startup_conditions["device_booted"] = startup_conditions.get("device_booted", False) or HARDWARE.booted() + # if the temperature enters the danger zone, go offroad to cool down onroad_conditions["device_temp_good"] = thermal_status < ThermalStatus.danger extra_text = f"{offroad_comp_temp:.1f}C" diff --git a/system/hardware/base.py b/system/hardware/base.py index 0b6ca44c3c..b432a41907 100644 --- a/system/hardware/base.py +++ b/system/hardware/base.py @@ -23,6 +23,9 @@ class HardwareBase(ABC): except Exception: return default + def booted(self) -> bool: + return True + @abstractmethod def reboot(self, reason=None): pass diff --git a/system/hardware/tici/hardware.py b/system/hardware/tici/hardware.py index f895bbc508..d1ac52c8dc 100644 --- a/system/hardware/tici/hardware.py +++ b/system/hardware/tici/hardware.py @@ -74,6 +74,11 @@ def sudo_write(val, path): # fallback for debugfs files os.system(f"sudo su -c 'echo {val} > {path}'") +def sudo_read(path: str) -> str: + try: + return subprocess.check_output(f"sudo cat {path}", shell=True, encoding='utf8') + except Exception: + return "" def affine_irq(val, action): irqs = get_irqs_for_action(action) @@ -554,6 +559,12 @@ class Tici(HardwareBase): time.sleep(0.5) gpio_set(GPIO.STM_BOOT0, 0) + def booted(self): + # this normally boots within 8s, but on rare occasions takes 30+s + encoder_state = sudo_read("/sys/kernel/debug/msm_vidc/core0/info") + if "Core state: 0" in encoder_state and (time.monotonic() < 60*2): + return False + return True if __name__ == "__main__": t = Tici()