|
Safe API Framework 0.1.0 build 384e6ae
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/rte_watchdog.c |
| Real watchdog implementation: a fixed-size pool of watchdog slots, timed via the already-portable rte_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 | rte_watchdog_config_t |
| Watchdog configuration. More... | |
| struct | rte_watchdog_status_t |
| Watchdog health/status information. More... | |
Enumerations | |
| enum | rte_watchdog_type_t { RTE_WATCHDOG_SYSTEM , RTE_WATCHDOG_TASK , RTE_WATCHDOG_CHANNEL , RTE_WATCHDOG_CHECKPOINT } |
| Watchdog type. More... | |
| enum | rte_watchdog_action_t { RTE_WATCHDOG_ACTION_LOG , RTE_WATCHDOG_ACTION_SAFESTATE , RTE_WATCHDOG_ACTION_REBOOT , RTE_WATCHDOG_ACTION_FAILOVER , RTE_WATCHDOG_ACTION_CUSTOM } |
| Recovery action when watchdog fires. More... | |
Functions | |
| rte_status_t | rte_watchdog_create (rte_watchdog_t *handle_out, const rte_watchdog_config_t *config) |
| Create a watchdog. | |
| rte_status_t | rte_watchdog_start (rte_watchdog_t watchdog) |
| Start watchdog timer. | |
| rte_status_t | rte_watchdog_stop (rte_watchdog_t watchdog) |
| Stop watchdog timer. | |
| rte_status_t | rte_watchdog_kick (rte_watchdog_t watchdog) |
| Kick (pet) watchdog - prove liveness. | |
| rte_status_t | rte_watchdog_get_status (rte_watchdog_t watchdog, rte_watchdog_status_t *status_out) |
| Get watchdog status. | |
| rte_status_t | rte_watchdog_destroy (rte_watchdog_t watchdog) |
| Destroy watchdog. | |
| rte_status_t | rte_watchdog_manager_initialize (void) |
| Initialize watchdog manager (call once at startup). | |
| rte_status_t | rte_watchdog_manager_shutdown (void) |
| Shutdown watchdog manager (call once at shutdown). | |
| void | rte_watchdog_timeout_handler (uint32_t watchdog_id) |
| Watchdog timeout handler (INTERNAL - called by framework). | |
| void | rte_watchdog_timer_tick (void) |
| Poll all active watchdogs for expiry (call periodically). | |
Detect hung systems/tasks and trigger recovery.
| enum rte_watchdog_type_t |
Watchdog type.
Defines what the watchdog is monitoring.
| Enumerator | |
|---|---|
| RTE_WATCHDOG_SYSTEM | Entire system liveness |
| RTE_WATCHDOG_TASK | Specific task/thread |
| RTE_WATCHDOG_CHANNEL | IPC/redundancy channel |
| RTE_WATCHDOG_CHECKPOINT | Checkpoint barrier |
Definition at line 41 of file rte_watchdog.h.
Recovery action when watchdog fires.
Defines what happens when watchdog timeout occurs.
| Enumerator | |
|---|---|
| RTE_WATCHDOG_ACTION_LOG | Log event only |
| RTE_WATCHDOG_ACTION_SAFESTATE | Trigger safe-state |
| RTE_WATCHDOG_ACTION_REBOOT | System reboot |
| RTE_WATCHDOG_ACTION_FAILOVER | Loss of a redundant peer/channel detected - invokes config->custom_action (same dispatch as RTE_WATCHDOG_ACTION_CUSTOM; custom_action is required for this action too - see rte_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 |
| RTE_WATCHDOG_ACTION_CUSTOM | Custom callback |
Definition at line 53 of file rte_watchdog.h.
| rte_status_t rte_watchdog_create | ( | rte_watchdog_t * | handle_out, |
| const rte_watchdog_config_t * | config ) |
Create a watchdog.
Initializes a watchdog with specified configuration. Watchdog starts in disabled state; call rte_watchdog_start() to enable.
| handle_out | Receives watchdog handle |
| config | Watchdog configuration |
Example (system watchdog):
Definition at line 191 of file rte_watchdog.c.
| rte_status_t rte_watchdog_start | ( | rte_watchdog_t | watchdog | ) |
Start watchdog timer.
Enables watchdog monitoring. Countdown begins from timeout_ms. Must be called after rte_watchdog_create().
| watchdog | Watchdog handle |
Definition at line 240 of file rte_watchdog.c.
| rte_status_t rte_watchdog_stop | ( | rte_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 268 of file rte_watchdog.c.
| rte_status_t rte_watchdog_kick | ( | rte_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 280 of file rte_watchdog.c.
| rte_status_t rte_watchdog_get_status | ( | rte_watchdog_t | watchdog, |
| rte_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 315 of file rte_watchdog.c.
| rte_status_t rte_watchdog_destroy | ( | rte_watchdog_t | watchdog | ) |
Destroy watchdog.
Stops and deallocates watchdog. After destruction, handle is invalid.
| watchdog | Watchdog handle |
Definition at line 346 of file rte_watchdog.c.
| rte_status_t rte_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 163 of file rte_watchdog.c.
| rte_status_t rte_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 174 of file rte_watchdog.c.
| void rte_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 363 of file rte_watchdog.c.
| void rte_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 OSAdapter, not in this module). Instead, the integrating application is responsible for calling this function regularly - e.g. from a rte_timer periodic callback, or once per iteration of a rte_appmanager execute() cycle - so that any watchdog whose deadline has passed is detected and its configured recovery action (rte_watchdog_timeout_handler()) is dispatched.
The clock itself is supervised too (REQ-WATCHDOG-004, ISS-036): when rte_timer_now() fails while at least one watchdog is started and not yet fired, no deadline can be checked and such a watchdog could never expire - so this function logs one ERROR ("watchdog clock failed - entering SAFE state", under the first such watchdog's name) and enters RTE_SAFESTATE_LEVEL_SAFE with reason RTE_SAFESTATE_REASON_CLOCK_FAILED, which does not return (REQ-COMMON-SAFESTATE-002). With no started, unfired watchdog a failed clock read leaves this call a silent no-op.
Definition at line 446 of file rte_watchdog.c.