Jump to main content

##

# 3.42.27 Watchdog Timer (WDT)

The Watchdog timer (WDT) is designed to give an added level of safety in critical systems, to ensure a device reset is triggered in the case of a deadlock or other software malfunction that prevents normal device operation.

When enabled, the WDT is a constantly running timer that is configured to a predefined time-out period. Before the end of the time-out period, the WDT should be set back, or else, a system Reset is issued.

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

Early Warning

In some cases it is desirable to receive an early warning that the Watchdog is about to expire, so that some system action (such as saving any system configuration data for failure analysis purposes) can be performed before the system reset occurs.

The Early Warning feature of the Watchdog module allows such a notification to be requested; after the configured early warning time (but before the expiry of the Watchdog counter) the Early Warning flag will become set, so that the user application can take an appropriate action.

It is important to note that the purpose of the Early Warning feature is not to allow the user application to reset the Watchdog; doing so will defeat the safety the module gives to the user application. Instead, this feature should be used purely to perform any tasks that need to be undertaken before the system reset occurs.

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 the WDT peripheral
WDT_Enable | Enables the WDT peripheral
WDT_Disable | Disables the WDT peripheral
WDT_TimeoutPeriodSet | Set WDT Timeout Period
WDT_Clear | Restarts the WDT counter
WDT_ClearWithSync | Restarts the WDT counter with write sync
WDT_CallbackRegister | Sets the pointer to the function (and it's context) to be called when the Early Warning event occurs

Data types and constants

Name | Type | Description
--- | --- | ---
WDT_CALLBACK | Typedef | Defines the data type and function signature for the WDT peripheral callback function