# Hardware watchdog

The base controller provides a hardware watchdog. Once configured and started, the program is expected to reset the timer. If the program stops resetting the timer, the controller resets and drives all outputs off (zero) without any software involvement.

```python
#!/usr/bin/env python3
import time
import synergy_logic

base = synergy_logic.Base()

base.config_watchdog(1000, mode="TOGGLE")   # 1000 ms timeout
base.start_watchdog()

try:
    while True:
        do_the_control_work()
        base.pet_watchdog()
        time.sleep(0.1)
finally:
    base.stop_watchdog()
```

Any read or write to the base controller resets the watchdog timer implicitly, so a program that accesses I/O every cycle rarely needs an explicit `pet_watchdog()`. Call it explicitly around code paths that may not touch the bus, such as a long computation or a blocking network call.

`mode="TOGGLE"` resets the controller and allows it to restart. `mode="HOLD"` holds it in reset until 24 V is cycled, which is the more conservative choice when a hung controller should require operator intervention.

```{admonition} A watchdog is not a safety system
:class: warning

It catches a hung *program*. It does nothing about wrong logic, a failed sensor, or a shorted output. Safety functions belong in hardwired circuits.
```
