Watchdog Should Be Fed Again Before the Watchdog Counter Underflows to Prevent Resetinterrupt
Functions | |
fsp_err_t | R_WDT_Open (wdt_ctrl_t *const p_ctrl, wdt_cfg_t const *const p_cfg) |
fsp_err_t | R_WDT_TimeoutGet (wdt_ctrl_t *const p_ctrl, wdt_timeout_values_t *const p_timeout) |
fsp_err_t | R_WDT_Refresh (wdt_ctrl_t *const p_ctrl) |
fsp_err_t | R_WDT_StatusGet (wdt_ctrl_t *const p_ctrl, wdt_status_t *const p_status) |
fsp_err_t | R_WDT_StatusClear (wdt_ctrl_t *const p_ctrl, const wdt_status_t status) |
fsp_err_t | R_WDT_CounterGet (wdt_ctrl_t *const p_ctrl, uint32_t *const p_count) |
fsp_err_t | R_WDT_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) |
Commuter for the WDT peripheral on RA MCUs. This module implements the WDT Interface.
Overview
The watchdog timer is used to recover from unexpected errors in an application. The watchdog timer must exist refreshed periodically in the permitted count window by the application. If the count is allowed to underflow or refresh occurs exterior of the valid refresh period, the WDT resets the device or generates an NMI.
Features
The WDT HAL module has the following key features:
- When the WDT underflows or is refreshed exterior of the permitted refresh window, one of the following events can occur:
- Resetting of the device
- Generation of an NMI
- The WDT has two supported modes:
- In auto commencement fashion, the WDT begins counting at reset.
- In register offset mode, the WDT tin can be started from the awarding.
Selecting a Watchdog
RA MCUs accept ii watchdog peripherals: the watchdog timer (WDT) and the independent watchdog timer (IWDT). When selecting between them, consider these factors:
WDT | IWDT | |
---|---|---|
Start Style | The WDT can exist started from the application (register start mode) or configured past hardware to start automatically (auto starting time way). | The IWDT can just be configured by hardware to start automatically. |
Clock Source | The WDT runs off a peripheral clock. | The IWDT has its own clock source which improves safety. |
Configuration
When using register start manner, configure the watchdog timer on the Stacks tab.
- Annotation
- When using automobile kickoff mode, configurations on the Stacks tab are ignored. Configure the watchdog using the OFS settings on the BSP tab.
Build Time Configurations for r_wdt
The following build time configurations are defined in fsp_cfg/r_wdt_cfg.h:
Configuration | Options | Default | Clarification |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Register Start NMI Support |
| Disabled | If enabled, lawmaking for NMI back up in register outset mode is included in the build. |
Configurations for Monitoring > Watchdog (r_wdt)
This module can be added to the Stacks tab via New Stack > Monitoring > Watchdog (r_wdt). Non-secure callable guard functions tin can be generated for this module by correct clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.
Configuration | Options | Default | Description |
---|---|---|---|
Proper name | Proper noun must exist a valid C symbol | g_wdt0 | Module name. |
Timeout |
| 16,384 Cycles | Select the watchdog timeout in cycles. |
Clock Partition Ratio |
| PCLK/8192 | Select the watchdog clock divisor. |
Window Start Position |
| 100% (Window Position Not Specified) | Select the allowed watchdog refresh start point. |
Window End Position |
| 0% (Window Position Not Specified) | Select the immune watchdog refresh stop betoken. |
Reset Control |
| Reset Output | Select what happens when the watchdog timer expires. |
Stop Control |
| WDT Count Disabled in Depression Power Fashion | Select the watchdog state in depression ability mode. |
NMI Callback | Name must be a valid C symbol | Cipher | A user callback function must be provided if the WDT is configured to generate an NMI when the timer underflows or a refresh mistake occurs. If this callback part is provided, it volition be chosen from the NMI handler each time the watchdog triggers. |
Clock Configuration
The WDT clock is based on the PCLKB frequency. You lot tin can prepare the PCLKB frequency using the Clocks tab of the RA Configuration editor or by using the CGC Interface at run-time. The maximum timeout period with PCLKB running at 60 MHz is approximately 2.2 seconds.
Pin Configuration
This module does non utilize I/O pins.
Usage Notes
NMI Interrupt
The watchdog timer uses the NMI, which is enabled by default. No special configuration is required. When the NMI is triggered, the callback part registered during open is called.
- Note
- When using the WDT in software start mode with NMI and the timer underflows, the WDT status must exist reset by calling R_WDT_StatusClear before restarting the timer via R_WDT_Refresh.
Period Calculation
The WDT operates from PCLKB. With a PCLKB of 60 MHz, the maximum time from the concluding refresh to device reset or NMI generation will exist merely over ii.two seconds every bit detailed below.
PLCKB = 60 MHz
Clock partition ratio = PCLKB / 8192
Timeout flow = 16384 cycles
WDT clock frequency = sixty MHz / 8192 = vii.324 kHz
Cycle fourth dimension = i / seven.324 kHz = 136.53 us
Timeout = 136.53 us x 16384 cycles = two.23 seconds
Limitations
Developers should be enlightened of the following limitations when using the WDT:
- When using a J-Link debugger the WDT counter does not count and therefore will not reset the device or generate an NMI. To enable the watchdog to count and generate a reset or NMI while debugging, add this line of code in the awarding:
R_DEBUG->DBGSTOPCR_b.DBGSTOP_WDT = 0;
- If the WDT is configured to end the counter in low power manner, then your application must restart the watchdog past calling R_WDT_Refresh() afterward the MCU wakes from low power fashion.
Examples
WDT Basic Case
This is a basic example of minimal utilise of the WDT in an application.
void wdt_basic_example (void)
{
err = R_WDT_Open(&g_wdt0_ctrl, &g_wdt0_cfg);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
while (true)
{
affirm(FSP_SUCCESS == err);
}
}
WDT Advanced Instance
This instance demonstrates using a starting time window and gives an example callback to handle an NMI generated by an underflow or refresh error.
#define WDT_TIMEOUT_COUNTS (16384U)
#define WDT_MAX_COUNTER (WDT_TIMEOUT_COUNTS - 1U)
#define WDT_START_WINDOW_75 ((WDT_MAX_COUNTER * 3) / iv)
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
__NVIC_SystemReset();
}
void wdt_advanced_example (void)
{
R_DEBUG->DBGSTOPCR_b.DBGSTOP_WDT = 0;
if (R_SYSTEM->RSTSR1_b.WDTRF)
{
R_SYSTEM->RSTSR1 = 0U;
}
err = R_WDT_Open(&g_wdt0_ctrl, &g_wdt0_cfg);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
while (true)
{
uint32_t wdt_counter = 0U;
do
{
assert(FSP_SUCCESS == err);
} while (wdt_counter >= WDT_START_WINDOW_75);
assert(FSP_SUCCESS == err);
}
}
◆wdt_instance_ctrl_t
struct wdt_instance_ctrl_t
WDT private control cake. Exercise Non Modify. Initialization occurs when R_WDT_Open() is called.
◆R_WDT_Open()
Configure the WDT in annals start style. In machine-start_mode the NMI callback can exist registered. Implements wdt_api_t::open.
This office should only be called once as WDT configuration registers can only be written to once and so subsequent calls will have no effect.
Case:
- Return values
-
FSP_SUCCESS WDT successfully configured. FSP_ERR_ASSERTION Cypher pointer, or one or more than configuration options is invalid. FSP_ERR_ALREADY_OPEN Module is already open. This module can just be opened in one case. FSP_ERR_INVALID_STATE The security state of the NMI and the module do not match.
- Note
- In auto start mode the only valid configuration option is for registering the callback for the NMI ISR if NMI output has been selected.
◆R_WDT_TimeoutGet()
Read timeout information for the watchdog timer. Implements wdt_api_t::timeoutGet.
- Render values
-
FSP_SUCCESS WDT timeout data retrieved successfully. FSP_ERR_ASSERTION Nothing Pointer. FSP_ERR_NOT_OPEN Instance control block is not initialized.
◆R_WDT_Refresh()
Refresh the watchdog timer. Implements wdt_api_t::refresh.
In addition to refreshing the watchdog counter this function tin can be used to beginning the counter in register start way.
Example:
affirm(FSP_SUCCESS == err);
- Return values
-
FSP_SUCCESS WDT successfully refreshed. FSP_ERR_ASSERTION p_ctrl is Zilch. FSP_ERR_NOT_OPEN Instance control cake is not initialized.
- Note
- This function but returns FSP_SUCCESS. If the refresh fails due to being performed outside of the permitted refresh period the device volition either reset or trigger an NMI ISR to run.
◆R_WDT_StatusGet()
Read the WDT status flags. Implements wdt_api_t::statusGet.
Indicates both status and error conditions.
Example:
assert(FSP_SUCCESS == err);
- Render values
-
FSP_SUCCESS WDT condition successfully read. FSP_ERR_ASSERTION Null arrow as a parameter. FSP_ERR_NOT_OPEN Instance control block is not initialized. FSP_ERR_UNSUPPORTED This function is only valid if the watchdog generates an NMI when an mistake occurs.
- Note
- When the WDT is configured to output a reset on underflow or refresh error reading the status and error flags serves no purpose as they will always bespeak that no underflow has occurred and there is no refresh error. Reading the status and mistake flags is only valid when interrupt asking output is enabled.
◆R_WDT_StatusClear()
Clear the WDT status and mistake flags. Implements wdt_api_t::statusClear.
Example:
assert(FSP_SUCCESS == err);
- Return values
-
FSP_SUCCESS WDT flag(southward) successfully cleared. FSP_ERR_ASSERTION Null pointer as a parameter. FSP_ERR_NOT_OPEN Instance command block is not initialized. FSP_ERR_UNSUPPORTED This function is only valid if the watchdog generates an NMI when an error occurs.
- Note
- When the WDT is configured to output a reset on underflow or refresh error reading the status and error flags serves no purpose as they will always indicate that no underflow has occurred and in that location is no refresh error. Reading the status and error flags is only valid when interrupt request output is enabled.
◆R_WDT_CounterGet()
Read the current count value of the WDT. Implements wdt_api_t::counterGet.
Instance:
assert(FSP_SUCCESS == err);
- Render values
-
FSP_SUCCESS WDT current count successfully read. FSP_ERR_ASSERTION Null pointer passed as a parameter. FSP_ERR_NOT_OPEN Instance control block is not initialized.
◆R_WDT_CallbackSet()
Updates the user callback and has option of providing memory for callback structure. Implements wdt_api_t::callbackSet
- Return values
-
FSP_SUCCESS Callback updated successfully. FSP_ERR_ASSERTION A required pointer is Nothing. FSP_ERR_NOT_OPEN The command block has not been opened. FSP_ERR_NO_CALLBACK_MEMORY p_callback is not-secure and p_callback_memory is either secure or Nothing.
Source: https://renesas.github.io/fsp/group___w_d_t.html
0 Response to "Watchdog Should Be Fed Again Before the Watchdog Counter Underflows to Prevent Resetinterrupt"
Post a Comment