Driver API for WDT (plib_wdt.h)
More...
|
| typedef void(* | WDT_CALLBACK_HANDLER) (uint32_t status) |
| | Function pointer type for the Watchdog Timer fault callback.
|
| |
|
| void | WDT_Configure (uint16_t wdv, uint16_t wdd, uint32_t mode) |
| | Configures the Watchdog Timer (WDT). Programs the WDT Mode Register with the specified watchdog counter value, window value, and configuration options.
|
| |
| void | WDT_Restart (void) |
| | Restarts the Watchdog Timer. Reloads the WDT counter by writing WDT_CR with the correct password key. This function can be called at any time to kick the watchdog.
|
| |
| void | WDT_SetCallbackHandler (WDT_CALLBACK_HANDLER callback) |
| | Registers the callback handler to be invoked from the WDT ISR.
|
| |
| uint32_t | WDT_StatusGet (void) |
| | Reads and returns the Watchdog Status Register (WDT_SR). Performs a single read of WDT_SR and returns the raw value. Test the result with WDT_SR_WDUNF_Msk (underflow) and WDT_SR_WDERR_Msk (error). Reading WDT_SR clears both the WDUNF and WDERR flags.
|
| |
| bool | WDT_IsEnabled (void) |
| | Checks if the WDT is enabled.
|
| |
Driver API for WDT (plib_wdt.h)
Usage Example
The following example demonstrates typical usage of the WDT peripheral:
#include <stdint.h>
#include <stdbool.h>
volatile bool wdt_underflow_triggered = false;
volatile bool wdt_error_triggered = false;
static void WDT_FaultCallback(uint32_t status)
{
if ((status & WDT_SR_WDUNF_Msk) != 0U)
{
wdt_underflow_triggered = true;
}
if ((status & WDT_SR_WDERR_Msk) != 0U)
{
wdt_error_triggered = true;
}
}
int32_t configure_wdt(void)
{
const uint16_t wdt_timeout_period_value = 0x800U;
const uint16_t wdt_window_period_value = 0x400U;
WDT_MR_WDRSTEN_Msk | WDT_MR_WDFIEN_Msk | WDT_MR_WDDBGHLT_Msk);
return 0;
}
void WDT_SetCallbackHandler(WDT_CALLBACK_HANDLER callback)
Registers the callback handler to be invoked from the WDT ISR.
void WDT_Configure(uint16_t wdv, uint16_t wdd, uint32_t mode)
Configures the Watchdog Timer (WDT). Programs the WDT Mode Register with the specified watchdog count...
◆ WDT_CALLBACK_HANDLER
| typedef void(* WDT_CALLBACK_HANDLER) (uint32_t status) |
Function pointer type for the Watchdog Timer fault callback.
- Parameters
-
| status | Snapshot of WDT_SR captured once by WDT_Handler(). Test it with the status masks:
- WDT_SR_WDUNF_Msk : Watchdog Underflow occurred.
- WDT_SR_WDERR_Msk : Watchdog Error (out-of-window reload) occurred.
|
◆ WDT_Configure()
| void WDT_Configure |
( |
uint16_t | wdv, |
|
|
uint16_t | wdd, |
|
|
uint32_t | mode ) |
Configures the Watchdog Timer (WDT). Programs the WDT Mode Register with the specified watchdog counter value, window value, and configuration options.
- Note
- The WDT_MR register is write-once after a processor reset. Writing WDT_MR also reloads and restarts the down counter, so the watchdog begins counting immediately when this function is called.
- Parameters
-
| wdv | Watchdog counter value (12-bit). Valid range: 0x000 to 0xFFF. Values outside this range are silently truncated to the low 12 bits. |
| wdd | Watchdog delta/window value (12-bit). Valid range: 0x000 to 0xFFF. Values outside this range are silently truncated to the low 12 bits. Programming wdd >= wdv disables the reload-window check, allowing WDT_Restart() to be called anywhere within [0, wdv] (non-windowed mode). |
| mode | Bitwise OR of WDT_MR_WDDIS_Msk (disable watchdog), WDT_MR_WDRSTEN_Msk (reset on fault), WDT_MR_WDFIEN_Msk (fault interrupt), WDT_MR_WDIDLEHLT_Msk (halt in idle/sleep), and/or WDT_MR_WDDBGHLT_Msk (halt in debug). |
- Returns
- void
◆ WDT_IsEnabled()
| bool WDT_IsEnabled |
( |
void | | ) |
|
Checks if the WDT is enabled.
- Returns
- true if the WDT is enabled (WDDIS = 0), false if disabled.
◆ WDT_Restart()
| void WDT_Restart |
( |
void | | ) |
|
Restarts the Watchdog Timer. Reloads the WDT counter by writing WDT_CR with the correct password key. This function can be called at any time to kick the watchdog.
- Returns
- void
◆ WDT_SetCallbackHandler()
Registers the callback handler to be invoked from the WDT ISR.
- Parameters
-
| callback | Pointer to the callback function. This function sets a user-defined function that will be called when a WDT fault (underflow or error) interrupt occurs. The callback receives the WDT_SR status value as an argument. |
- Returns
- void
◆ WDT_StatusGet()
| uint32_t WDT_StatusGet |
( |
void | | ) |
|
Reads and returns the Watchdog Status Register (WDT_SR). Performs a single read of WDT_SR and returns the raw value. Test the result with WDT_SR_WDUNF_Msk (underflow) and WDT_SR_WDERR_Msk (error). Reading WDT_SR clears both the WDUNF and WDERR flags.
- Returns
- The WDT_SR register value at the time of the read.