2.125 Watchdog Timer (WDT)
The Watchdog timer (WDT) is designed to give an added level of safety in critical systems, to ensure a system reset is triggered in the case of a deadlock or other software malfunction that prevents normal device operation.
It operates from the internal Low-Power Oscillator (LPRC) clock source. Various WDT time-out periods can be selected using the WDT postscaler. The WDT can also be used to wake the device from Sleep or Idle mode.
The following are some of the key features of the WDT module:
-
Configuration or software controlled
-
User-configurable time-out period
-
Can wake the device from Sleep or Idle
Using The Library
The Watchdog Timer (WDT) runs independent of the rest of the system, causing system resets whenever it times out. However, the application software should ensure that the timeout never occurs by resetting the WDT periodically as long as the software is in a known healthy state.
If the system hangs or program execution is corrupted, the WDT will not receive its periodic reset, and will eventually time out and cause a system reset.
In many systems, there is an obvious upper boundary to the amount of time each iteration of the main application loop can be expected to run, before a malfunction can be assumed (either due to a deadlock waiting on hardware or software, or due to other means).
When the Watchdog is configured with a timeout period equal to this upper boundary, a malfunction in the system will force a full system reset to allow for a graceful recovery.
Here is an example code to enable watchdog timer and keep clearing at regular intervals
WDT_Enable(); while ( true ) { // Application Code WDT_Clear(); }
Library Interface
Watchdog Timer peripheral library provides the following interfaces:
Functions
Name | Description |
---|---|
WDT_Initialize | Initializes given instance of WDT peripheral. |
WDT_Initialize | Initializes given instance of WDT peripheral. |
WDT_Enable | Enables WDT peripheral |
WDT_Enable | Enables WDT peripheral |
WDT_Disable | Disables WDT peripheral |
WDT_Disable | Disables WDT peripheral |
WDT_Clear | Restarts the WDT counter |
WDT_Clear | Clears WDT timer |
WDT_ClearWithSync | Restarts the WDT counter with write sync |
WDT_CountGet | Provides the current WDT count |
WDT_IsEnabled | Returns true if the WDT is enabled |
WDT_isPowerFailWDTEventSet | Indicates if the reset cause was due to WDT timeout or not |
WDT_PeriodLoad | Reloads the WDT counter with the given period value |
WDT_PowerFailWDTEventClear | Clears the WDT event bit in the Power Fail and Reset Status register |
WDT_TimeoutPeriodSet | Set WDT Timeout Period |
WDT_TimeoutActionSet | Selects the action to be taken when WDT expires |
WDT_WindowEnable | Enables the WDT window mode |
WDT_WindowDisable | Disables the WDT window mode |
WDT_CallbackRegister | Sets the pointer to the function (and it is context) to be called when the Early Warning event occurs |
WDT_CallbackRegister | Allows application to register a callback with the WDT peripheral |
Data types and constants
Name | Type | Description |
---|---|---|
WDT_CALLBACK | Typedef | Defines the data type and function signature for the WDT peripheral callback function |
WDT_CALLBACK | Typedef | Defines the data type and function signature for the WDT peripheral callback function |
WDT_TIMEOUT_ACTION | Enum | Defines the enums associated with WDT timeout action |