WDOG - Watchdog Timer#
Watchdog timer peripheral API.
The Watchdog API functions provide full support for the WDOG peripheral. The WDOG resets the system in case of a fault condition.
Example#
The following example demonstrates how to configure and use the Watchdog Timer. This example shows how to initialize the watchdog with a custom configuration, enable interrupts, feed the watchdog, and properly clean up when done.
// WDOG warning interrupt handler
void WDOG0_IRQHandler(void)
{
// Get pending interrupts
uint32_t flags = sl_hal_wdog_get_pending_interrupts(WDOG0);
// Check for warning interrupt
if (flags & WDOG_IF_WARN) {
// Clear the warning interrupt flag
sl_hal_wdog_clear_interrupts(WDOG0, WDOG_IF_WARN);
// Feed the watchdog before timeout occurs
sl_hal_wdog_feed(WDOG0);
// Application can perform other actions here
// ...
}
}
void wdog_example(void)
{
// Initialize WDOG with default configuration
sl_hal_wdog_init_t init = SL_HAL_WDOG_INIT_DEFAULT;
// Customize configuration
init.period_select = SL_WDOG_PERIOD_64k; // Set timeout period
init.warning_time_select = SL_WDOG_WARNING_TIME75; // Get warning at 75% of timeout
// Initialize WDOG with our configuration
sl_hal_wdog_init(WDOG0, &init);
// Enable warning interrupt
sl_hal_wdog_clear_interrupts(WDOG0, WDOG_IF_WARN);
sl_hal_wdog_enable_interrupts(WDOG0, WDOG_IF_WARN);
// Enable NVIC interrupt for WDOG
sl_interrupt_manager_clear_irq_pending(WDOG0_IRQn);
sl_interrupt_manager_enable_irq(WDOG0_IRQn);
// Enable WDOG - this starts the watchdog timer
sl_hal_wdog_enable(WDOG0);
// Verify WDOG is enabled (optional)
if (sl_hal_wdog_is_enabled(WDOG0)) {
// WDOG is now running
// Feed the watchdog initially
sl_hal_wdog_feed(WDOG0);
// Wait for feed operation to complete
sl_hal_wdog_wait_sync(WDOG0);
// Main application loop would continue here
// The watchdog will now trigger a warning interrupt at 75% of timeout
// which will feed the watchdog in the interrupt handler
// ...
}
// When no longer needed, disable the watchdog (if not locked)
if (!sl_hal_wdog_is_locked(WDOG0)) {
sl_hal_wdog_disable(WDOG0);
sl_hal_wdog_wait_ready(WDOG0);
// Disable NVIC interrupt for WDOG
sl_interrupt_manager_disable_irq(WDOG0_IRQn);
}
}
Modules#
Enumerations#
Watchdog timeout period selection.
Select Watchdog warning timeout period as percentage of timeout.
Select Watchdog illegal window limit.
Functions#
Enable the watchdog peripheral.
Disable the watchdog peripheral.
Feed the watchdog peripheral.
Initialize watchdog (assuming the watchdog configuration has not been locked).
Lock the watchdog configuration.
Wait for the watchdog to complete all synchronization of register changes and commands.
Wait for the watchdog to be completely disabled after calling sl_hal_wdog_disable().
Unlock the watchdog configuration.
Clear one or more pending watchdog interrupts.
Disable one or more watchdog interrupts.
Enable one or more watchdog interrupts.
Get pending watchdog interrupt flags.
Get enabled and pending watchdog interrupt flags.
Set one or more pending watchdog interrupts from SW.
Get enabled status of the watchdog.
Get locked status of the watchdog.
Macros#
Check if WDOG instance is valid.
Suggested default configuration for WDOG initialization structure.
Enumeration Documentation#
sl_hal_wdog_period_select_t#
sl_hal_wdog_period_select_t
Watchdog timeout period selection.
Enumerator | |
---|---|
SL_WDOG_PERIOD_9 | 9 clock periods. |
SL_WDOG_PERIOD_17 | 17 clock periods. |
SL_WDOG_PERIOD_33 | 33 clock periods. |
SL_WDOG_PERIOD_65 | 65 clock periods. |
SL_WDOG_PERIOD_129 | 129 clock periods. |
SL_WDOG_PERIOD_257 | 257 clock periods. |
SL_WDOG_PERIOD_513 | 513 clock periods. |
SL_WDOG_PERIOD_1k | 1025 clock periods. |
SL_WDOG_PERIOD_2k | 2049 clock periods. |
SL_WDOG_PERIOD_4k | 4097 clock periods. |
SL_WDOG_PERIOD_8k | 8193 clock periods. |
SL_WDOG_PERIOD_16k | 16385 clock periods. |
SL_WDOG_PERIOD_32k | 32769 clock periods. |
SL_WDOG_PERIOD_64k | 65537 clock periods. |
SL_WDOG_PERIOD_128k | 131073 clock periods. |
SL_WDOG_PERIOD_256k | 262145 clock periods. |
sl_hal_wdog_warning_timeout_select_t#
sl_hal_wdog_warning_timeout_select_t
Select Watchdog warning timeout period as percentage of timeout.
Enumerator | |
---|---|
SL_WDOG_WARNING_DISABLE | Watchdog warning period is disabled. |
SL_WDOG_WARNING_TIME25 | Watchdog warning period is 25% of the timeout. |
SL_WDOG_WARNING_TIME50 | Watchdog warning period is 50% of the timeout. |
SL_WDOG_WARNING_TIME75 | Watchdog warning period is 75% of the timeout. |
sl_hal_wdog_illegal_window_select_t#
sl_hal_wdog_illegal_window_select_t
Select Watchdog illegal window limit.
Enumerator | |
---|---|
SL_WDOG_ILLEGAL_WINDOW_DISABLE | Watchdog illegal window disabled. |
SL_WDOG_ILLEGAL_WINDOW_TIME12_5 | Window timeout is 12.5% of the timeout. |
SL_WDOG_ILLEGAL_WINDOW_TIME25_0 | Window timeout is 25% of the timeout. |
SL_WDOG_ILLEGAL_WINDOW_TIME37_5 | Window timeout is 37.5% of the timeout. |
SL_WDOG_ILLEGAL_WINDOW_TIME50_0 | Window timeout is 50% of the timeout. |
SL_WDOG_ILLEGAL_WINDOW_TIME62_5 | Window timeout is 62.5% of the timeout. |
SL_WDOG_ILLEGAL_WINDOW_TIME75_0 | Window timeout is 75% of the timeout. |
SL_WDOG_ILLEGAL_WINDOW_TIME87_5 | Window timeout is 87.5% of the timeout. |
Function Documentation#
sl_hal_wdog_enable#
void sl_hal_wdog_enable (WDOG_TypeDef * wdog)
Enable the watchdog peripheral.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
Note
This function modifies the WDOG CTRL register which requires synchronization into the low-frequency domain. If this register is modified before a previous update to the same register has completed, this function will stall until the previous synchronization has completed.
sl_hal_wdog_disable#
void sl_hal_wdog_disable (WDOG_TypeDef * wdog)
Disable the watchdog peripheral.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
Note
This function modifies the WDOG CTRL register which requires synchronization into the low-frequency domain. If this register is modified before a previous update to the same register has completed, this function will stall until the previous synchronization has completed.
sl_hal_wdog_feed#
void sl_hal_wdog_feed (WDOG_TypeDef * wdog)
Feed the watchdog peripheral.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
When WDOG is activated, it must be fed (i.e., clearing the counter) before it reaches the defined timeout period. Otherwise, WDOG will generate a reset.
Note
Note that WDOG is an asynchronous peripheral and when calling the sl_hal_wdog_feed() function the hardware starts the process of clearing the counter. This process takes some time before it completes depending on the selected oscillator (up to 4 peripheral clock cycles). When using the ULFRCO for instance as the oscillator the watchdog runs on a 1 kHz clock and a watchdog clear operation might take up to 4 ms.
If the device supports EM2 or EM3 and it enters EM2 or EM3 while a command is in progress then that command will be aborted. An application can use sl_hal_wdog_sync_wait() to wait for a command to complete.
sl_hal_wdog_init#
void sl_hal_wdog_init (WDOG_TypeDef * wdog, const sl_hal_wdog_init_t * init)
Initialize watchdog (assuming the watchdog configuration has not been locked).
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
const sl_hal_wdog_init_t * | [in] | init | The structure holding the WDOG configuration. A default setting #WDOG_INIT_DEFAULT is available for initialization. |
Note
This function modifies the WDOG CTRL register which requires synchronization into the low-frequency domain. If this register is modified before a previous update to the same register has completed, this function will stall until the previous synchronization has completed.
sl_hal_wdog_lock#
void sl_hal_wdog_lock (WDOG_TypeDef * wdog)
Lock the watchdog configuration.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to WDOG peripheral register block. |
This prevents errors from overwriting the WDOG configuration, possibly disabling it. Only a reset can unlock the WDOG configuration once locked.
If the LFRCO or LFXO clocks are used to clock WDOG, consider using the option of inhibiting those clocks to be disabled. See the #WDOG_INIT_DEFAULT initialization structure.
Note
This function modifies the WDOG CTRL register which requires synchronization into the low-frequency domain. If this register is modified before a previous update to the same register has completed, this function will stall until the previous synchronization has completed.
sl_hal_wdog_wait_sync#
void sl_hal_wdog_wait_sync (WDOG_TypeDef * wdog)
Wait for the watchdog to complete all synchronization of register changes and commands.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to WDOG peripheral register block. |
sl_hal_wdog_wait_ready#
void sl_hal_wdog_wait_ready (WDOG_TypeDef * wdog)
Wait for the watchdog to be completely disabled after calling sl_hal_wdog_disable().
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to WDOG peripheral register block. |
sl_hal_wdog_unlock#
void sl_hal_wdog_unlock (WDOG_TypeDef * wdog)
Unlock the watchdog configuration.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to WDOG peripheral register block. |
Note that this function will have no effect on devices where a reset is the only way to unlock the watchdog.
sl_hal_wdog_clear_interrupts#
void sl_hal_wdog_clear_interrupts (WDOG_TypeDef * wdog, uint32_t flags)
Clear one or more pending watchdog interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
uint32_t | [in] | flags | WDOG interrupt sources to clear. Use a set of interrupt flags OR-ed together to clear multiple interrupt sources. |
sl_hal_wdog_disable_interrupts#
void sl_hal_wdog_disable_interrupts (WDOG_TypeDef * wdog, uint32_t flags)
Disable one or more watchdog interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
uint32_t | [in] | flags | WDOG interrupt sources to disable. Use a set of interrupt flags OR-ed together to disable multiple interrupt. |
sl_hal_wdog_enable_interrupts#
void sl_hal_wdog_enable_interrupts (WDOG_TypeDef * wdog, uint32_t flags)
Enable one or more watchdog interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
uint32_t | [in] | flags | WDOG interrupt sources to enable. Use a set of interrupt flags OR-ed together to set multiple interrupt. |
Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using sl_hal_wdog_clear_interrupts() prior to enabling the interrupt.
sl_hal_wdog_get_pending_interrupts#
uint32_t sl_hal_wdog_get_pending_interrupts (WDOG_TypeDef * wdog)
Get pending watchdog interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
Returns
Pending WDOG interrupt sources. Returns a set of interrupt flags OR-ed together for the interrupt sources set.
Note
The event bits are not cleared by the use of this function.
sl_hal_wdog_get_enabled_pending_interrupts#
uint32_t sl_hal_wdog_get_enabled_pending_interrupts (WDOG_TypeDef * wdog)
Get enabled and pending watchdog interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
Returns
Pending and enabled WDOG interrupt sources. Returns a set of interrupt flags OR-ed together for the interrupt sources set.
Useful for handling more interrupt sources in the same interrupt handler.
sl_hal_wdog_set_interrupts#
void sl_hal_wdog_set_interrupts (WDOG_TypeDef * wdog, uint32_t flags)
Set one or more pending watchdog interrupts from SW.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
uint32_t | [in] | flags | WDOG interrupt sources to set to pending. Use a set of interrupt flags (WDOG_IFS_nnn). |
sl_hal_wdog_is_enabled#
bool sl_hal_wdog_is_enabled (WDOG_TypeDef * wdog)
Get enabled status of the watchdog.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
Returns
True if Watchdog is enabled, false otherwise.
sl_hal_wdog_is_locked#
bool sl_hal_wdog_is_locked (WDOG_TypeDef * wdog)
Get locked status of the watchdog.
Type | Direction | Argument Name | Description |
---|---|---|---|
WDOG_TypeDef * | [in] | wdog | Pointer to the WDOG peripheral register block. |
Returns
True if Watchdog is locked, false otherwise.