|
Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
|
Watchdog tracks liveness via timeout mechanism. Application periodically kicks to reset countdown. On timeout, registered recovery action fires (log, safe-state, reboot, custom callback, or failover). Framework manages global watchdog manager that coordinates all watchdog instances.
Caller provides storage; framework fills it with state. Config specifies type, timeout, and recovery action.
Returns: kicks (total), fires (total timeouts), time_until_fire, active flag.
Global singleton managing all watchdogs:
Manager coordinates timeout callbacks and recovery actions.
Countdown timer - Current time until timeout Last kick time - When last kicked Total kicks - Diagnostic counter Total fires - Diagnostic counter Is active - Enabled/disabled state Type/action/config - Static configuration
On every tick (typically 1ms from system timer):
On kick:
Action on timeout depends on configuration:
LOG - Log the event via rte_log SAFESTATE - Invoke RTE_SAFESTATE(SAFE, APP_REASON_WATCHDOG) REBOOT - Invoke RTE_REBOOT(APP_REASON_WATCHDOG) FAILOVER - Application-defined failover (distributed systems) CUSTOM - Call custom callback (application-provided)
| Operation | Time | Notes |
|---|---|---|
| create() | O(1) | Initialize state |
| start() | O(1) | Set countdown |
| kick() | O(1) | Reset countdown |
| get_status() | O(1) | Read state |
| destroy() | O(1) | Clean up |
| Manager tick | O(n) | n = active watchdogs |
System tick is the only O(n) operation; called once per millisecond.
Max watchdog count - No limit; all static Min timeout - Depends on timer resolution (typically 1ms) Max timeout - 2^32 - 1 milliseconds (~49 days) Watchdog size - 64 bytes (RTE_DECLARE_STORAGE)
Watchdog recovery action can trigger safe-state:
Test 1: Timeout fires recovery action**
Test 2: Kick resets countdown**