feat: add discrete-input support and RPU config-writable check
This commit is contained in:
+15
-1
@@ -1,10 +1,16 @@
|
||||
import time
|
||||
|
||||
from common.config_loader import load_garuda_registers
|
||||
from drivers.modbus_device import ModbusDevice
|
||||
from drivers.modbus_device import ModbusDevice, ModbusDeviceError
|
||||
|
||||
DEFAULT_DATASETS = ["Sec_normal", "sec_flash"]
|
||||
|
||||
# SEC_STATE values that allow modbus_to_config()/write_all_flash() to run
|
||||
# (garuda-dsp/app/app_modbus/app_modbus.c update_modbus_input()).
|
||||
# SEC_RUN (charging) is NOT in this set - config writes are silently ignored
|
||||
# while charging is active.
|
||||
CONFIG_WRITABLE_STATES = {1, 9, 238, 240, 241} # READY, PRE_READY, ERROR, DEBUG_READY, DEBUG_FREQ_CAL
|
||||
|
||||
|
||||
class Rpu(ModbusDevice):
|
||||
"""Covers every register in Sec_normal + sec_flash by label via read()/write()
|
||||
@@ -37,6 +43,14 @@ class Rpu(ModbusDevice):
|
||||
def read_shadow_error_code(self):
|
||||
return (self.read("Shadow_error_code_hi") << 16) | self.read("Shadow_error_code_lo")
|
||||
|
||||
def wait_until_config_writable(self, timeout_s=10, poll_interval_s=0.5):
|
||||
deadline = time.time() + timeout_s
|
||||
while time.time() < deadline:
|
||||
if self.read("Main_state") in CONFIG_WRITABLE_STATES:
|
||||
return
|
||||
time.sleep(poll_interval_s)
|
||||
raise ModbusDeviceError(f"RPU did not reach a config-writable state within {timeout_s}s")
|
||||
|
||||
def rewrite_config(self):
|
||||
self.write_holding_register(self._addr("PASSWORD_LO"), self.REWRITE_PASSWORD_LO)
|
||||
self.write_holding_register(self._addr("PASSWORD_HI"), self.REWRITE_PASSWORD_HI)
|
||||
|
||||
Reference in New Issue
Block a user