RA Flexible Software Package Documentation
Release v5.6.0
|
|
Functions | |
fsp_err_t | R_IWDT_Open (wdt_ctrl_t *const p_api_ctrl, wdt_cfg_t const *const p_cfg) |
fsp_err_t | R_IWDT_Refresh (wdt_ctrl_t *const p_api_ctrl) |
fsp_err_t | R_IWDT_StatusGet (wdt_ctrl_t *const p_api_ctrl, wdt_status_t *const p_status) |
fsp_err_t | R_IWDT_StatusClear (wdt_ctrl_t *const p_api_ctrl, const wdt_status_t status) |
fsp_err_t | R_IWDT_CounterGet (wdt_ctrl_t *const p_api_ctrl, uint32_t *const p_count) |
fsp_err_t | R_IWDT_TimeoutGet (wdt_ctrl_t *const p_api_ctrl, wdt_timeout_values_t *const p_timeout) |
fsp_err_t | R_IWDT_CallbackSet (wdt_ctrl_t *const p_ctrl, void(*p_callback)(wdt_callback_args_t *), void const *const p_context, wdt_callback_args_t *const p_callback_memory) |
Driver for the IWDT peripheral on RA MCUs. This module implements the WDT Interface.
The independent watchdog timer is used to recover from unexpected errors in an application. The timer must be refreshed periodically in the permitted count window by the application. If the count is allowed to underflow or refresh occurs outside of the valid refresh period, the IWDT resets the device or generates an NMI.
The IWDT HAL module has the following key features:
RA MCUs have two watchdog peripherals: the watchdog timer (WDT) and the independent watchdog timer (IWDT). When selecting between them, consider these factors:
WDT | IWDT | |
---|---|---|
Start Mode | The WDT can be started from the application (register start mode) or configured by hardware to start automatically (auto start mode). | On most of MCUs, the IWDT can only be configured by hardware to start automatically1. |
Clock Source | The WDT runs off a peripheral clock. | The IWDT has its own clock source which improves safety. |
When using register start mode, configure the watchdog timer on the Stacks tab.
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Register Start NMI Support | MCU Specific Options | If enabled, code for NMI support in register start mode is included in the build. |
Configuration | Options | Default | Description |
---|---|---|---|
Name | Name must be a valid C symbol | g_wdt0 | Module name. |
Timeout | MCU Specific Options | Select the independent watchdog timeout in cycles. | |
Clock Division Ratio | MCU Specific Options | Select the independent watchdog clock divisor. | |
Window Start Position | MCU Specific Options | Select the allowed independent watchdog refresh start point in %. | |
Window End Position | MCU Specific Options | Select the allowed independent watchdog refresh end point in %. | |
Reset Control | MCU Specific Options | Select what happens when the independent watchdog timer expires. | |
Stop Control | MCU Specific Options | Select the independent watchdog state in low power mode. | |
NMI callback | Name must be a valid C symbol | NULL | A user callback function can be provided here. If this callback function is provided, it is called from the interrupt service routine (ISR) when the watchdog triggers. |
The IWDT clock is based on the IWDTCLK frequency. You can set the IWDTCLK frequency divider using the BSP tab of the RA Configuration editor.
This module does not use I/O pins.
The independent watchdog timer uses the NMI, which is enabled by default. No special configuration is required. When the NMI is triggered, the callback function registered during open is called.
The IWDT operates from IWDTCLK. With a IWDTCLK of 15000 Hz, the maximum time from the last refresh to device reset or NMI generation will be just below 35 seconds as detailed below.
IWDTCLK = 15000 Hz
Clock division ratio = IWDTCLK / 256
Timeout period = 2048 cycles
WDT clock frequency = 15000 Hz / 256 = 58.59 Hz
Cycle time = 1 / 58.59 Hz = 17.067 ms
Timeout = 17.067 ms x 2048 cycles = 34.95 seconds
Developers should be aware of the following limitations when using the IWDT:
This is a basic example of minimal use of the IWDT in an application.
This example demonstrates using a start window and gives an example callback to handle an NMI generated by an underflow or refresh error.
Data Structures | |
struct | iwdt_instance_ctrl_t |
struct iwdt_instance_ctrl_t |
IWDT control block. DO NOT INITIALIZE. Initialization occurs when wdt_api_t::open is called.
Data Fields | |
uint32_t | wdt_open |
Indicates whether the open() API has been successfully called. | |
void const * | p_context |
Placeholder for user data. Passed to the user callback in wdt_callback_args_t. | |
void(* | p_callback )(wdt_callback_args_t *p_args) |
Callback provided when a WDT NMI ISR occurs. | |
fsp_err_t R_IWDT_Open | ( | wdt_ctrl_t *const | p_api_ctrl, |
wdt_cfg_t const *const | p_cfg | ||
) |
Register the IWDT NMI callback.
Example:
FSP_SUCCESS | IWDT successfully configured. |
FSP_ERR_ASSERTION | Null Pointer. |
FSP_ERR_NOT_ENABLED | An attempt to open the IWDT when the OFS0 register is not configured for auto-start mode. |
FSP_ERR_ALREADY_OPEN | Module is already open. This module can only be opened once. |
FSP_ERR_INVALID_STATE | The security state of the NMI and the module do not match. |
fsp_err_t R_IWDT_Refresh | ( | wdt_ctrl_t *const | p_api_ctrl | ) |
Refresh the Independent Watchdog Timer. If the refresh fails due to being performed outside of the permitted refresh period the device will either reset or trigger an NMI ISR to run.
Example:
FSP_SUCCESS | IWDT successfully refreshed. |
FSP_ERR_ASSERTION | One or more parameters are NULL pointers. |
FSP_ERR_NOT_OPEN | The driver has not been opened. Perform R_IWDT_Open() first. |
fsp_err_t R_IWDT_StatusGet | ( | wdt_ctrl_t *const | p_api_ctrl, |
wdt_status_t *const | p_status | ||
) |
Read the IWDT status flags.
Indicates both status and error conditions.
Example:
FSP_SUCCESS | IWDT status successfully read. |
FSP_ERR_ASSERTION | Null pointer as a parameter. |
FSP_ERR_NOT_OPEN | The driver has not been opened. Perform R_IWDT_Open() first. |
FSP_ERR_UNSUPPORTED | This function is only valid if the IWDT generates an NMI when an error occurs. |
fsp_err_t R_IWDT_StatusClear | ( | wdt_ctrl_t *const | p_api_ctrl, |
const wdt_status_t | status | ||
) |
Clear the IWDT status and error flags. Implements wdt_api_t::statusClear.
Example:
FSP_SUCCESS | IWDT flag(s) successfully cleared. |
FSP_ERR_ASSERTION | Null pointer as a parameter. |
FSP_ERR_NOT_OPEN | The driver has not been opened. Perform R_IWDT_Open() first. |
FSP_ERR_UNSUPPORTED | This function is only valid if the IWDT generates an NMI when an error occurs. |
fsp_err_t R_IWDT_CounterGet | ( | wdt_ctrl_t *const | p_api_ctrl, |
uint32_t *const | p_count | ||
) |
Read the current count value of the IWDT. Implements wdt_api_t::counterGet.
Example:
FSP_SUCCESS | IWDT current count successfully read. |
FSP_ERR_ASSERTION | Null pointer passed as a parameter. |
FSP_ERR_NOT_OPEN | The driver has not been opened. Perform R_IWDT_Open() first. |
fsp_err_t R_IWDT_TimeoutGet | ( | wdt_ctrl_t *const | p_api_ctrl, |
wdt_timeout_values_t *const | p_timeout | ||
) |
Read timeout information for the watchdog timer. Implements wdt_api_t::timeoutGet.
FSP_SUCCESS | IWDT timeout information retrieved successfully. |
FSP_ERR_ASSERTION | One or more parameters are NULL pointers. |
FSP_ERR_NOT_OPEN | The driver has not been opened. Perform R_IWDT_Open() first. |
fsp_err_t R_IWDT_CallbackSet | ( | wdt_ctrl_t *const | p_ctrl, |
void(*)(wdt_callback_args_t *) | p_callback, | ||
void const *const | p_context, | ||
wdt_callback_args_t *const | p_callback_memory | ||
) |
Updates the user callback and has option of providing memory for callback structure. Implements wdt_api_t::callbackSet
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |