In this use case, the Watchdog module is configured for:
- System reset after 2048 clocks of the Watchdog generic clock
- Always on mode disabled
- Basic mode, with no window or early warning periods
This use case sets up the Watchdog to force a system reset after every 2048 clocks of the Watchdog's Generic Clock channel, unless the user periodically resets the Watchdog counter via a button before the timer expires. If the Watchdog resets the device, a LED on the board is turned off.
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
Copy-paste the following setup code to your user application:
void configure_wdt(void)
{
config_wdt.always_on = false;
#if !((SAML21) || (SAMC21) || (SAML22) || (SAMR30))
#endif
}
Add to user application initialization (typically the start of main()
):
Workflow
- 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 period and lock mode of the Watchdog.
config_wdt.always_on = false;
#if !((SAML21) || (SAMC21) || (SAML22) || (SAMR30))
#endif
- Setups the WDT hardware module with the requested settings.
Quick Start Guide for WDT - Basic
Code
Copy-paste the following code to your user application:
}
else {
}
while (true) {
}
}
Workflow
- Retrieve the cause of the system reset to determine if the Watchdog module was the cause of the last reset.
- Turn on or off the board LED based on whether the Watchdog reset the device.
- Enter an infinite loop to hold the main program logic.
- Test to see if the board button is currently being pressed.
- If the button is pressed, turn on the board LED and reset the Watchdog timer.