3.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

NameDescription
WDT_InitializeInitializes given instance of WDT peripheral.
WDT_ClearClears WDT timer
WDT_CountGetProvides the current WDT count
WDT_DisableDisables WDT peripheral
WDT_EnableEnables WDT peripheral
WDT_IsEnabledReturns true if the WDT is enabled
WDT_isPowerFailWDTEventSetIndicates if the reset cause was due to WDT timeout or not
WDT_PeriodLoadReloads the WDT counter with the given period value
WDT_PowerFailWDTEventClearClears the WDT event bit in the Power Fail and Reset Status register
WDT_TimeoutActionSetSelects the action to be taken when WDT expires
WDT_CallbackRegisterAllows application to register a callback with the WDT peripheral
Data types and constants
NameTypeDescription
WDT_CALLBACKTypedefDefines the data type and function signature for the WDT peripheral callback function.
WDT_TIMEOUT_ACTIONEnumDefines the enums associated with WDT timeout action