In this use case, the Watchdog module is configured for:
- System reset after 4096 clocks of the Watchdog generic clock
- Always on mode disabled
- Early warning period of 2048 clocks of the Watchdog generic clock
This use case sets up the Watchdog to force a system reset after every 4096 clocks of the Watchdog's Generic Clock channel, with an Early Warning callback being generated every 2048 clocks. Each time the Early Warning interrupt fires the board LED is turned on, and each time the device resets the board LED is turned off, giving a periodic flashing pattern.
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
Copy-paste the following setup code to your user application:
{
}
{
config_wdt.always_on = false;
#if !((SAML21) || (SAMC21) || (SAML22) || (SAMR30))
#endif
}
{
}
Add to user application initialization (typically the start of main()
):
Workflow
- Configure and enable the Watchdog driver.
- Create a Watchdog module configuration struct, which can be filled out to adjust the configuration of the Watchdog.
- Initialize the Watchdog configuration struct with the module's default values.
- Note
- This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
- Adjust the configuration struct to set the timeout and early warning periods of the Watchdog.
config_wdt.always_on = false;
#if !((SAML21) || (SAMC21) || (SAML22) || (SAMR30))
#endif
- Sets up the WDT hardware module with the requested settings.
- Register and enable the Early Warning callback handler.
- Register the user-provided Early Warning callback function with the driver, so that it will be run when an Early Warning condition occurs.
- Enable the Early Warning callback so that it will generate callbacks.
Quick Start Guide for WDT - Callback
Code
Copy-paste the following code to your user application:
Workflow
- Turn off the board LED when the application starts.
- Enable global interrupts so that callbacks can be generated.
- Enter an infinite loop to hold the main program logic.