CMSIS-Driver_PIC32CM-PL  
Peripheral Library (PLIB) Documentation
 
Loading...
Searching...
No Matches
WDT Interface

Driver API for WDT (plib_wdt.h) More...

Typedefs

typedef void(* WDT_CALLBACK_HANDLER) (void)
 Function pointer type for Watchdog Timer callback.
 
typedef uint8_t WDT_TIMEOUT_PERIOD
 WDT timeout period identifier.
 
typedef uint8_t WDT_WINDOW_CLOSED_PERIOD
 WDT window closed period identifier.
 
typedef uint8_t WDT_EARLY_WARNING_OFFSET
 WDT early warning offset identifier.
 

Functions

void WDT_Enable (void)
 Enables the Watchdog Timer.
 
void WDT_Disable (void)
 Disables the Watchdog Timer.
 
void WDT_Clear (void)
 Clears (refreshes) the Watchdog Timer.
 
void WDT_SetCallbackHandler (WDT_CALLBACK_HANDLER callback)
 Registers the callback handler to be invoked from the WDT ISR.
 
void WDT_SetTimeout (WDT_TIMEOUT_PERIOD period)
 Sets the WDT timeout period.
 
bool WDT_EnableWindowMode (WDT_WINDOW_CLOSED_PERIOD window)
 Enables the WDT window mode.
 
void WDT_DisableWindowMode (void)
 Disables the WDT window mode.
 
bool WDT_SetEarlyWarningOffset (WDT_EARLY_WARNING_OFFSET offset)
 Sets the WDT early warning offset.
 
bool WDT_IsAlwaysOn (void)
 Checks if the WDT is configured as always-on.
 
void WDT_EnableEarlyWarning (void)
 Enables WDT Early Warning interrupt.
 
void WDT_DisableEarlyWarning (void)
 Disables WDT Early Warning interrupt.
 
bool WDT_EarlyWarningIsSet (void)
 Checks if Early Warning interrupt flag is set.
 
void WDT_ClearEarlyWarning (void)
 Clears Early Warning interrupt flag.
 

Description

Driver API for WDT (plib_wdt.h)

Usage Example

The following example demonstrates typical usage of the WDT peripheral:

#include "plib_wdt.h"
#include <pic32c.h>
#include <stdint.h>
/*******************************************************************************
* @brief Configure WDT in Normal Mode
*
* In Normal Mode:
* - The watchdog counts continuously.
* - The application must periodically call WDT_Clear().
* - An Early Warning interrupt can occur before the timeout.
*
* WDT CLK timing (1.024 kHz clock):
* Timeout period = 4096 cycles ≈ 4 seconds
* Early warning offset = 512 cycles ≈ 0.5 s after start
*
* Timeline:
*
* WDT_Clear()
* ↓0 0.5 4
* |------ offset ------|-------- remaining --------|
* ↑ ↑ ↑
* start Early Warning Reset
******************************************************************************/
int32_t configure_wdt_normal_mode(void (*callback)(void))
{
// Configure watchdog timeout period
WDT_SetTimeout(WDT_CONFIG_PER_CYC4096_Val);
// Configure Early Warning offset
WDT_SetEarlyWarningOffset(WDT_EWCTRL_EWOFFSET_CYC512_Val);
// Enable Early Warning interrupt
// Register callback handler if provided
if (callback != NULL)
{
}
// Enable WDT interrupt at CPU level
NVIC_EnableIRQ(WDT_IRQn);
// Start the watchdog timer
return 0;
}
/*******************************************************************************
* @brief Configure WDT in Window Mode
*
* In Window Mode:
* - The watchdog can only be cleared during the open window.
* - Clearing the watchdog too early or too late triggers a reset.
*
* WDT CLK timing (1.024 kHz clock):
*
* Timeout = 4096 cycles ≈ 4 seconds
* Closed window = 1024 cycles ≈ 1 second
*
* Timeline:
*
* WDT_Enable() / WDT_Clear()
* ↓0 1 5
* |---- CLOSED ----|----------- OPEN -----------|
* ↑ ↑ ↑
* start window opens Reset
*
******************************************************************************/
int32_t configure_wdt_window_mode(void (*callback)(void))
{
// Configure watchdog timeout period
WDT_SetTimeout(WDT_CONFIG_PER_CYC4096_Val);
// Enable window mode with closed window period
WDT_EnableWindowMode(WDT_CONFIG_WINDOW_CYC1024_Val);
// Enable Early Warning interrupt
// Register callback handler
if (callback != NULL)
{
}
// Enable WDT interrupt in NVIC
NVIC_EnableIRQ(WDT_IRQn);
// Start watchdog timer
return 0;
}
bool WDT_EnableWindowMode(WDT_WINDOW_CLOSED_PERIOD window)
Enables the WDT window mode.
void WDT_SetTimeout(WDT_TIMEOUT_PERIOD period)
Sets the WDT timeout period.
void WDT_SetCallbackHandler(WDT_CALLBACK_HANDLER callback)
Registers the callback handler to be invoked from the WDT ISR.
void WDT_Enable(void)
Enables the Watchdog Timer.
bool WDT_SetEarlyWarningOffset(WDT_EARLY_WARNING_OFFSET offset)
Sets the WDT early warning offset.
void WDT_EnableEarlyWarning(void)
Enables WDT Early Warning interrupt.

Typedef Documentation

◆ WDT_CALLBACK_HANDLER

typedef void(* WDT_CALLBACK_HANDLER) (void)

Function pointer type for Watchdog Timer callback.

◆ WDT_EARLY_WARNING_OFFSET

WDT early warning offset identifier.

Defines how many watchdog clock cycles before timeout the Early Warning interrupt is generated.

◆ WDT_TIMEOUT_PERIOD

WDT timeout period identifier.

A system reset occurs if the watchdog is not cleared before timeout.

◆ WDT_WINDOW_CLOSED_PERIOD

WDT window closed period identifier.

Defines the time interval during which clearing the watchdog is not allowed when Window Mode is enabled. Writing CLEAR during this closed window causes an immediate reset.

Function Documentation

◆ WDT_Clear()

void WDT_Clear ( void )

Clears (refreshes) the Watchdog Timer.

Resets the WDT counter to avoid system reset. Must be called periodically.

Returns
void

◆ WDT_ClearEarlyWarning()

void WDT_ClearEarlyWarning ( void )

Clears Early Warning interrupt flag.

Returns
void

◆ WDT_Disable()

void WDT_Disable ( void )

Disables the Watchdog Timer.

Stops the WDT from counting down.

Returns
void

◆ WDT_DisableEarlyWarning()

void WDT_DisableEarlyWarning ( void )

Disables WDT Early Warning interrupt.

Returns
void

◆ WDT_DisableWindowMode()

void WDT_DisableWindowMode ( void )

Disables the WDT window mode.

Disables the restricted window requirement for clearing the WDT.

Returns
void

◆ WDT_EarlyWarningIsSet()

bool WDT_EarlyWarningIsSet ( void )

Checks if Early Warning interrupt flag is set.

Returns
true if the early warning flag is set, false otherwise.

◆ WDT_Enable()

void WDT_Enable ( void )

Enables the Watchdog Timer.

Starts the WDT countdown.

Returns
void

◆ WDT_EnableEarlyWarning()

void WDT_EnableEarlyWarning ( void )

Enables WDT Early Warning interrupt.

Returns
void

◆ WDT_EnableWindowMode()

bool WDT_EnableWindowMode ( WDT_WINDOW_CLOSED_PERIOD window)

Enables the WDT window mode.

When enabled, the WDT must be cleared only within a specific window period.

Parameters
windowWindow size to configure.
Returns
true if enabled successfully, false otherwise.

◆ WDT_IsAlwaysOn()

bool WDT_IsAlwaysOn ( void )

Checks if the WDT is configured as always-on.

Some devices may not allow disabling the WDT. This function returns that status.

Returns
true if the WDT is always-on, false otherwise.

◆ WDT_SetCallbackHandler()

void WDT_SetCallbackHandler ( WDT_CALLBACK_HANDLER callback)

Registers the callback handler to be invoked from the WDT ISR.

Parameters
callbackPointer to the callback function.

This function is used to set a user-defined function that will be called when a WDT interrupt or timeout event occurs.

◆ WDT_SetEarlyWarningOffset()

bool WDT_SetEarlyWarningOffset ( WDT_EARLY_WARNING_OFFSET offset)

Sets the WDT early warning offset.

Configures the Early Warning interrupt offset. Valid only in normal mode.

Parameters
offsetEarly warning offset value.
Returns
true if set successfully, false otherwise.

◆ WDT_SetTimeout()

void WDT_SetTimeout ( WDT_TIMEOUT_PERIOD period)

Sets the WDT timeout period.

Configures the WDT to timeout after the given period.

Parameters
periodThe timeout value in supported units (hardware-dependent).