1.1.14 Watchdog Timer
The function of the Watchdog Timer is to provide a mechanism to detect if the internal embedded controller has failed.
When enabled, the Watchdog Timer (WDT) circuit will generate a WDT Event if the user program fails to reload the WDT
within a specified length of time known as the WDT Interval.
Using the Library
The application toggles an LED and keeps refreshing the WDT. User can enter a character on
the UART terminal to emulate a lockup situation. The application stops toggling the LED and
stops refreshing the WDT upon receiving a character on the UART terminal. After the
configured timeout, the WDT timer expires and resets the
application
char wdtDemoMessage[] =
{
"\n\r -------------------------------------------------------------"
"\n\r WDT DEMO "
"\n\r -------------------------------------------------------------)"
"\n\r Enter a character to emulate deadlock "
};
char wdtDeadlockMessage[] =
{
"\n\r Emulating deadlock................ "
"\n\r WDT should reset device in 4 seconds "
};
int main ( void )
{
/* Initialize all modules */
SYS_Initialize ( NULL );
UART0_Write(wdtDemoMessage, strlen(wdtDemoMessage));
SYSTICK_TimerStart();
WDT_Enable();
while ( true )
{
if(UART0_ReceiverIsReady() == false)
{
if(SYSTICK_TimerPeriodHasExpired())
{
LED0_Toggle();
WDT_Clear();
}
}
else
{
(void)UART0_ReadByte();
UART0_Write(wdtDeadlockMessage, strlen(wdtDeadlockMessage));
while(1);
}
}
/* Execution should not come here during normal operation */
return ( EXIT_FAILURE );
Library Interface
Functions
Name | Description |
---|---|
WDT_Initialize | Initializes given instance of WDT peripheral. |
WDT_Clear | Clears WDT timer |
WDT_CountGet | Provides the current WDT count |
WDT_Disable | Disables WDT peripheral |
WDT_Enable | Enables WDT peripheral |
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_TimeoutActionSet | Selects the action to be taken when WDT expires |
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_TIMEOUT_ACTION | Enum | Defines the enums associated with WDT timeout action |