WatchdogHandler.cpp 976 B

12345678910111213141516171819202122232425262728293031
  1. #include "WatchdogHandler.h"
  2. // 初始化看门狗定时器
  3. void setupWatchdog() {
  4. // 解锁写保护
  5. *(volatile uint32_t*)(LP_WDT_RWDT_WPROTECT_REG) = WDT_WKEY;
  6. // 配置看门狗超时时间为 60 秒
  7. // 假设时钟频率为 32.768 kHz(低速时钟),超时时间 = (LP_WDT_RWDT_CONFIG0_REG 的值) / 32768
  8. uint32_t timeout_ticks = 60 * 32768; // 60 秒
  9. *(volatile uint32_t*)(LP_WDT_RWDT_CONFIG0_REG) = timeout_ticks;
  10. // 重新使能写保护
  11. *(volatile uint32_t*)(LP_WDT_RWDT_WPROTECT_REG) = 0x0;
  12. Serial.println("看门狗定时器初始化完成,超时时间为 60 秒。");
  13. }
  14. // 喂狗操作
  15. void feedWatchdog() {
  16. // 解锁写保护
  17. *(volatile uint32_t*)(LP_WDT_RWDT_WPROTECT_REG) = WDT_WKEY;
  18. // 写入任意值喂狗
  19. *(volatile uint32_t*)(LP_WDT_RWDT_FEED_REG) = 0x1;
  20. // 重新使能写保护
  21. *(volatile uint32_t*)(LP_WDT_RWDT_WPROTECT_REG) = 0x0;
  22. //Serial.println("喂狗操作完成...");
  23. }