|
Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
|
Detect hung systems/tasks and trigger recovery. More...
Files | |
| file | src/redundancy/watchdog/sapi_watchdog.c |
| Real watchdog implementation: a fixed-size pool of watchdog slots, timed via the already-portable sapi_timer_now() OAL primitive rather than any new OS-specific timing code of its own (REQ-OAL-COMMON-010: no dynamic allocation). | |
Data Structures | |
| struct | sapi_watchdog_config_t |
| Watchdog configuration. More... | |
| struct | sapi_watchdog_status_t |
| Watchdog health/status information. More... | |
Enumerations | |
| enum | sapi_watchdog_type_t { SAPI_WATCHDOG_SYSTEM , SAPI_WATCHDOG_TASK , SAPI_WATCHDOG_CHANNEL , SAPI_WATCHDOG_CHECKPOINT } |
| Watchdog type. More... | |
| enum | sapi_watchdog_action_t { SAPI_WATCHDOG_ACTION_LOG , SAPI_WATCHDOG_ACTION_SAFESTATE , SAPI_WATCHDOG_ACTION_REBOOT , SAPI_WATCHDOG_ACTION_FAILOVER , SAPI_WATCHDOG_ACTION_CUSTOM } |
| Recovery action when watchdog fires. More... | |
Functions | |
| sapi_status_t | sapi_watchdog_create (sapi_watchdog_t *handle_out, const sapi_watchdog_config_t *config) |
| Create a watchdog. | |
| sapi_status_t | sapi_watchdog_start (sapi_watchdog_t watchdog) |
| Start watchdog timer. | |
| sapi_status_t | sapi_watchdog_stop (sapi_watchdog_t watchdog) |
| Stop watchdog timer. | |
| sapi_status_t | sapi_watchdog_kick (sapi_watchdog_t watchdog) |
| Kick (pet) watchdog - prove liveness. | |
| sapi_status_t | sapi_watchdog_get_status (sapi_watchdog_t watchdog, sapi_watchdog_status_t *status_out) |
| Get watchdog status. | |
| sapi_status_t | sapi_watchdog_destroy (sapi_watchdog_t watchdog) |
| Destroy watchdog. | |
| sapi_status_t | sapi_watchdog_manager_initialize (void) |
| Initialize watchdog manager (call once at startup). | |
| sapi_status_t | sapi_watchdog_manager_shutdown (void) |
| Shutdown watchdog manager (call once at shutdown). | |
| void | sapi_watchdog_timeout_handler (uint32_t watchdog_id) |
| Watchdog timeout handler (INTERNAL - called by framework). | |
| void | sapi_watchdog_timer_tick (void) |
| Poll all active watchdogs for expiry (call periodically). | |
Detect hung systems/tasks and trigger recovery.
| enum sapi_watchdog_type_t |
Watchdog type.
Defines what the watchdog is monitoring.
| Enumerator | |
|---|---|
| SAPI_WATCHDOG_SYSTEM | Entire system liveness |
| SAPI_WATCHDOG_TASK | Specific task/thread |
| SAPI_WATCHDOG_CHANNEL | IPC/redundancy channel |
| SAPI_WATCHDOG_CHECKPOINT | Checkpoint barrier |
Definition at line 41 of file sapi_watchdog.h.
Recovery action when watchdog fires.
Defines what happens when watchdog timeout occurs.
| Enumerator | |
|---|---|
| SAPI_WATCHDOG_ACTION_LOG | Log event only |
| SAPI_WATCHDOG_ACTION_SAFESTATE | Trigger safe-state |
| SAPI_WATCHDOG_ACTION_REBOOT | System reboot |
| SAPI_WATCHDOG_ACTION_FAILOVER | Loss of a redundant peer/channel detected - invokes config->custom_action (same dispatch as SAPI_WATCHDOG_ACTION_CUSTOM; custom_action is required for this action too - see sapi_watchdog_create()). Use this over CUSTOM when the reason a watchdog exists is specifically "my redundant partner stopped responding" (e.g. a dual-channel cross-compare link) - the distinct name documents intent at the call site, even though the mechanism is identical to CUSTOM. REQ-WATCHDOG-002 |
| SAPI_WATCHDOG_ACTION_CUSTOM | Custom callback |
Definition at line 53 of file sapi_watchdog.h.
| sapi_status_t sapi_watchdog_create | ( | sapi_watchdog_t * | handle_out, |
| const sapi_watchdog_config_t * | config ) |
Create a watchdog.
Initializes a watchdog with specified configuration. Watchdog starts in disabled state; call sapi_watchdog_start() to enable.
| handle_out | Receives watchdog handle |
| config | Watchdog configuration |
Example (system watchdog):
Definition at line 146 of file sapi_watchdog.c.
| sapi_status_t sapi_watchdog_start | ( | sapi_watchdog_t | watchdog | ) |
Start watchdog timer.
Enables watchdog monitoring. Countdown begins from timeout_ms. Must be called after sapi_watchdog_create().
| watchdog | Watchdog handle |
Definition at line 195 of file sapi_watchdog.c.
| sapi_status_t sapi_watchdog_stop | ( | sapi_watchdog_t | watchdog | ) |
Stop watchdog timer.
Disables watchdog monitoring. No timeout will occur until restarted. Used during shutdown or maintenance.
| watchdog | Watchdog handle |
Definition at line 212 of file sapi_watchdog.c.
| sapi_status_t sapi_watchdog_kick | ( | sapi_watchdog_t | watchdog | ) |
Kick (pet) watchdog - prove liveness.
Resets timeout countdown. Must be called periodically (before timeout expires) to prevent watchdog from firing.
Typical usage: called in main event loop, task loop, or after checkpoint.
| watchdog | Watchdog handle |
Example:
Definition at line 224 of file sapi_watchdog.c.
| sapi_status_t sapi_watchdog_get_status | ( | sapi_watchdog_t | watchdog, |
| sapi_watchdog_status_t * | status_out ) |
Get watchdog status.
Non-blocking query of watchdog state (kicks, fires, time remaining). Useful for health monitoring and diagnostics.
| watchdog | Watchdog handle |
| status_out | Receives watchdog status |
Example:
Definition at line 249 of file sapi_watchdog.c.
| sapi_status_t sapi_watchdog_destroy | ( | sapi_watchdog_t | watchdog | ) |
Destroy watchdog.
Stops and deallocates watchdog. After destruction, handle is invalid.
| watchdog | Watchdog handle |
Definition at line 269 of file sapi_watchdog.c.
| sapi_status_t sapi_watchdog_manager_initialize | ( | void | ) |
Initialize watchdog manager (call once at startup).
Sets up the central watchdog manager that coordinates all watchdog timers. Must be called before creating any watchdogs.
Definition at line 118 of file sapi_watchdog.c.
| sapi_status_t sapi_watchdog_manager_shutdown | ( | void | ) |
Shutdown watchdog manager (call once at shutdown).
Stops all running watchdogs and shuts down manager. After shutdown, cannot create new watchdogs until re-initialized.
Definition at line 129 of file sapi_watchdog.c.
| void sapi_watchdog_timeout_handler | ( | uint32_t | watchdog_id | ) |
Watchdog timeout handler (INTERNAL - called by framework).
Invoked by watchdog timer when timeout occurs. Applies recovery action (log, safe-state, reboot, failover, or custom callback).
This is a framework-internal function; applications don't call it directly.
| watchdog_id | ID of watchdog that fired |
Definition at line 286 of file sapi_watchdog.c.
| void sapi_watchdog_timer_tick | ( | void | ) |
Poll all active watchdogs for expiry (call periodically).
This implementation has no OS-specific interrupt/thread of its own (consistent with ADR-005: OS-specific timing belongs in an integrator backend, not in this module). Instead, the integrating application is responsible for calling this function regularly - e.g. from a sapi_timer periodic callback, or once per iteration of a sapi_appmanager execute() cycle - so that any watchdog whose deadline has passed is detected and its configured recovery action (sapi_watchdog_timeout_handler()) is dispatched.
Definition at line 369 of file sapi_watchdog.c.