| 12345678910111213141516171819202122232425262728293031 |
- #include "WatchdogHandler.h"
- // 初始化看门狗定时器
- void setupWatchdog() {
- // 解锁写保护
- *(volatile uint32_t*)(LP_WDT_RWDT_WPROTECT_REG) = WDT_WKEY;
- // 配置看门狗超时时间为 60 秒
- // 假设时钟频率为 32.768 kHz(低速时钟),超时时间 = (LP_WDT_RWDT_CONFIG0_REG 的值) / 32768
- uint32_t timeout_ticks = 60 * 32768; // 60 秒
- *(volatile uint32_t*)(LP_WDT_RWDT_CONFIG0_REG) = timeout_ticks;
- // 重新使能写保护
- *(volatile uint32_t*)(LP_WDT_RWDT_WPROTECT_REG) = 0x0;
- Serial.println("看门狗定时器初始化完成,超时时间为 60 秒。");
- }
- // 喂狗操作
- void feedWatchdog() {
- // 解锁写保护
- *(volatile uint32_t*)(LP_WDT_RWDT_WPROTECT_REG) = WDT_WKEY;
- // 写入任意值喂狗
- *(volatile uint32_t*)(LP_WDT_RWDT_FEED_REG) = 0x1;
- // 重新使能写保护
- *(volatile uint32_t*)(LP_WDT_RWDT_WPROTECT_REG) = 0x0;
- //Serial.println("喂狗操作完成...");
- }
|