This is the quickstart guide for the SAM4L watchdog driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.
The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.
Use cases
Basic use case
In this basic use case, the watchdog will use the RCSYS as the source clock and the timeout period will be configured as 0.57 second. Then the watchdog will be kicked every 100ms.
Prerequisites
Setup Steps
- Note
- The watchdog clock (CLK_WDT) is enabled at reset and the default source is system RC oscillator(RCSYS). If you want to use 32KHz oscillator as watchdog clock, please make sure it is enabled first:
if (BPM->BPM_PMCON & BPM_PMCON_CK32S) {
}
} else {
}
}
Setup Example Code
Add the following code in the application C-file to setup watchdog:
Setup Workflow
- Create variables to store the watchdog instance and configuration:
- Get default configuration but change timeout period to 0.57s (Ttimeout = 2pow(PSEL+1) / Fclk_cnt = 65535 / 115000).
- Initialize the watchdog:
Usage Steps
Usage Example Code
Add to, e.g., main loop in application C-file:
Usage Workflow
- Enable the watchdog:
- Kick the watchdog in every 100ms:
- A daemon program is created now. The MCU tasks can be added after the code of wdt_clear() then the tasks are under the monitor of watchdog. If the tasks lasted more than 0.57 second, the options of the watchdog timeout period should be adjusted accordingly.
Reset MCU by the WDT
We can reset MCU by generating a WDT reset as soon as possible.