![]() |
RAFW Flexible Software Package Documentation
Release v2.0.1
|
|
Watchdog Service to monitor system tasks and avoid system freezes. This module implements the Watchdog Service Interface.
The Watchdog Service (rm_watchdog_service_w) runs on FreeRTOS and is designed to monitor system tasks and prevent system freezes. The Watchdog Service acts as a layer on top of the low-level watchdog timer driver, allowing multiple tasks (up to 64) to share the underlying hardware watchdog timer. The Watchdog Service can trigger a system reset, enabling the system to recover from catastrophic failures in one or more tasks.
To be monitored, a task must first register with the service to receive a unique handle (ID). The task must then periodically notify the Watchdog Service using this ID to signal that it is working properly.
The watchdog timer is essentially a countdown timer that triggers a system reset if it expires. To prevent this, the timer must be reset to its starting value before it expires. The timer's value is 400, which corresponds to approximately 4 seconds.
If all monitored tasks notify the Watchdog Service during a single watchdog period, the timer will be updated, and no system reset will be triggered for that period. However, if at least one task fails to notify the Watchdog Service in time, a system reset will be triggered.
Each task is responsible for periodically notifying the Watchdog Service that it is still running using the notify API. This must be done before the watchdog timer expires. Occasionally, a registered task may need to temporarily exclude itself from monitoring if it expects to be blocked for an extended period while waiting for an event. This is achieved using the suspend API.
The suspend API suspends monitoring of specific tasks in the Watchdog Service, as there is no need to monitor a task that is blocked waiting for an event that may take too long to occur (which would lead to the task failing to notify the Watchdog Service and resulting in a system reset). When the task is unblocked, the resume API should be called to restore task monitoring by the Watchdog Service. From that point on, the task must notify the Watchdog Service as usual.
Finally, the setLatency API is intended for cases where a task requires a watchdog period greater than the timer's reset value. Using this API allows a task to delay notification of the Watchdog Service for a specified number of watchdog periods without triggering a system reset. The effect of calling this API is one-time, so it must be set every time increased latency is required.
The Watchdog Service module has the following key features:
| Configuration | Options | Default | Description |
|---|---|---|---|
| Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
| Configuration | Options | Default | Description |
|---|---|---|---|
| Name | Name must be a valid C symbol | g_watchdog_service0 | Module name. |
This module has no required clock configurations.
This module does not use I/O pins.
This is a basic example of minimal use of the Watchdog Service in an application.
This gives an advanced example of using APIs other than notify.
Data Structures | |
| struct | watchdog_service_w_instance_ctrl_t |
Variables | |
| volatile uint32_t | g_watchdog_service_w_nmi_event_data [9] |
| struct watchdog_service_w_instance_ctrl_t |
Private control block. DO NOT MODIFY. Initialization occurs when RM_WATCHDOG_SERVICE_W_Open() is called.
| Data Fields | ||
|---|---|---|
| uint32_t | open | Indicates whether the open() API has been successfully called. |
| SemaphoreHandle_t | lock | Semaphore handle. |
| uint8_t | max_task_id | Current maximum value of task ID. |
| uint8_t | idle_task_id | Id of idle task. |
| uint32_t | tasks_mask[WATCHDOG_SERVICE_W_MAX_INDEX] | Bitmask of registered tasks identifiers. |
| uint32_t | tasks_monitored_mask[WATCHDOG_SERVICE_W_MAX_INDEX] | Bitmask of monitored tasks identifiers. |
| uint32_t | notified_mask[WATCHDOG_SERVICE_W_MAX_INDEX] | Bitmask of tasks which notified. |
| uint8_t | tasks_latency[WATCHDOG_SERVICE_W_MAX_TASKS] | Allowed latency set by tasks. |
| TaskHandle_t | tasks_handle[WATCHDOG_SERVICE_W_MAX_TASKS] | Handles of monitored tasks. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_Open | ( | watchdog_service_ctrl_t *const | p_api_ctrl, |
| watchdog_service_cfg_t const *const | p_cfg | ||
| ) |
Configure and start the Watchdog Service. This should be called before using the Watchdog Service, preferably at application startup.
Example:
| FSP_SUCCESS | Watchdog Service was opened successfully. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_ALREADY_OPEN | Watchdog Service is already opened. |
| FSP_ERR_INVALID_STATE | Mutex was not created successfully. |
| FSP_ERR_INVALID_HW_CONDITION | HW WDT was not opened successfully. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_Register | ( | watchdog_service_ctrl_t *const | p_api_ctrl, |
| watchdog_service_cfg_t const *const | p_cfg, | ||
| uint8_t * | p_id | ||
| ) |
Register current task in the Watchdog Service. Returned id via argument p_id shall be used in all other Watchdog Service API calls from current task. Once registered, the task shall notify the Wathcdog Service periodically using notify API to prevent watchdog expiration. It is up to each task how this is done, but a task can request that it will be triggered periodically using the task notification capability, to notify the Watchdog Service back as a response.
Example:
| FSP_SUCCESS | Task was registered successfully. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_NOT_OPEN | Watchdog Service is not opened. |
| FSP_ERR_IN_USE | Could not register a task because the registered tasks are full. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_Unregister | ( | watchdog_service_ctrl_t *const | p_api_ctrl, |
| uint8_t | id | ||
| ) |
Unregister task from the Watchdog Service.
Example:
| FSP_SUCCESS | Task was unregistered successfully. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_NOT_OPEN | Watchdog Service is not opened. |
| FSP_ERR_INVALID_ARGUMENT | Id is out of range. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_Suspend | ( | watchdog_service_ctrl_t *const | p_api_ctrl, |
| uint8_t | id | ||
| ) |
Suspend monitoring a task by the Watchdog Service. A monitor-suspended task is not unregistered entirely, but it is ignored by the Watchdog Service until its monitoring is resumed. It is faster than unregistering and registering the task again.
Example:
| FSP_SUCCESS | Monitoring task was suspended successfully. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_NOT_OPEN | Watchdog Service is not opened. |
| FSP_ERR_INVALID_ARGUMENT | Id is out of range. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_Resume | ( | watchdog_service_ctrl_t *const | p_api_ctrl, |
| uint8_t | id | ||
| ) |
Resume monitoring of a task by the Watchdog Service. It should be called as soon as the reason that suspend API was called is removed.
Example:
| FSP_SUCCESS | Monitoring task was resumed successfully. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_NOT_OPEN | Watchdog Service is not opened. |
| FSP_ERR_INVALID_ARGUMENT | Id is out of range. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_Notify | ( | watchdog_service_ctrl_t *const | p_api_ctrl, |
| watchdog_service_cfg_t const *const | p_cfg, | ||
| uint8_t | id | ||
| ) |
Notify the Watchdog Service about a task. A registered task shall call this API periodically to notify the Watchdog Service that it is alive. This should be done frequently enough to fit into the watchdog timer interval.
Example:
| FSP_SUCCESS | Task notified successfully. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_NOT_OPEN | Watchdog Service is not opened. |
| FSP_ERR_INVALID_ARGUMENT | Id is out of range. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_ResumeAndNotify | ( | watchdog_service_ctrl_t *const | p_api_ctrl, |
| watchdog_service_cfg_t const *const | p_cfg, | ||
| uint8_t | id | ||
| ) |
Resume monitoring of a task and notify the Watchdog Service about the task.
Example:
| FSP_SUCCESS | Resume monitoring task and task notified successfully. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_NOT_OPEN | Watchdog Service is not opened. |
| FSP_ERR_INVALID_ARGUMENT | Id is out of range. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_NotifyFromIdle | ( | watchdog_service_ctrl_t *const | p_api_ctrl, |
| watchdog_service_cfg_t const *const | p_cfg | ||
| ) |
Notify the Watchdog Service about the idle task.
Example:
| FSP_SUCCESS | Idle task notified successfully. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_NOT_OPEN | Watchdog Service is not opened. |
| FSP_ERR_INVALID_ARGUMENT | Id is out of range. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_SetLatency | ( | watchdog_service_ctrl_t *const | p_api_ctrl, |
| uint8_t | id, | ||
| uint8_t | latency | ||
| ) |
Set watchdog latency for a task. This allows a task to miss a given number of notification periods to the Watchdog Service without triggering a system reset. Once set, the task is allowed to not notify the Watchdog Service for “latency” consecutive watchdog timer intervals. This option can be used to facilitate the operation of code that is expected to remain blocked for long periods of time (i.e. computation). This value is set once and does not reload automatically, thus it shall be set every time increased latency is required.
Example:
| FSP_SUCCESS | Set latency successfully. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_NOT_OPEN | Watchdog Service is not opened. |
| FSP_ERR_INVALID_ARGUMENT | Id is out of range. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_SetIdleId | ( | watchdog_service_ctrl_t *const | p_api_ctrl, |
| uint8_t | id | ||
| ) |
Set watchdog ID of the idle task.
Example:
| FSP_SUCCESS | Set idle id successfully. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_NOT_OPEN | Watchdog Service is not opened. |
| FSP_ERR_INVALID_ARGUMENT | Id is out of range. |
| fsp_err_t RM_WATCHDOG_SERVICE_W_IsMonitorMaskEmpty | ( | watchdog_service_ctrl_t *const | p_api_ctrl | ) |
Find out if the only task monitored is the idle task.
| FSP_SUCCESS | Only the idle task is monitored. |
| FSP_ERR_IN_USE | Tasks other than the idle task are monitored. |
| FSP_ERR_ASSERTION | NULL pointer to parameters in argument. |
| FSP_ERR_NOT_OPEN | Watchdog Service is not opened. |
| void rm_watchdog_service_w_nmi_reset | ( | uint32_t * | p_exception_args | ) |
Store system register values at WDT NMI and wait for system reset.
| [in] | p_exception_args | Pointer to system register values at NMI. |
| volatile uint32_t g_watchdog_service_w_nmi_event_data[9] |
Hold the stack contents when NMI occurs.