watchdog.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "watchdog.h"
  2. #include "string.h"
  3. #include "ac780x.h"
  4. #include "ac780x_wdg.h"
  5. #include "ac780x_wdg_reg.h"
  6. #include "ac780x_gpio.h"
  7. //#include "wdg_sample.h"
  8. #define WDG_Timeout(n) (n * APB_BUS_FREQ)
  9. #define WDG_CLK(n) (APB_BUS_FREQ * n -1)
  10. /**
  11. * WDGCallback
  12. *
  13. * @param[in] wparam: reserved
  14. * @param[in] lparam: reserved
  15. * @return 0: success, other: error
  16. *
  17. * @brief Watchdog IRQ callback function
  18. * 中断服务仅有128个总线时钟(时间极短),然后MCU会被复位
  19. */
  20. void WDGCallback(void *device, uint32_t wpara, uint32_t lpara)
  21. {
  22. return;
  23. }
  24. void Watchdog_Init(void)
  25. {
  26. #ifdef WATCHDOG_ENABLE
  27. uint32_t tmpTimeoutValue = WDG_CLK(WATCHDOG_TIMEOUT); // (119999999+1)/24000000 = 5s(时钟为48M)
  28. WDG_ConfigType WDGConfig;
  29. memset(&WDGConfig,0,sizeof(WDGConfig));
  30. WDGConfig.clockSource = WDG_CLOCK_APB; //0 is 24MHz clk source
  31. WDGConfig.WDGEn = ENABLE;
  32. WDGConfig.interruptEn = ENABLE; //使能中断,延迟128个总线时钟后复位,可在128总线时钟内执行中断例程
  33. //若需要超时立即复位,禁能中断即可
  34. WDGConfig.prescalerEn = DISABLE; //0:disable 256 pre, 1:enable 256 pre
  35. WDGConfig.updateEn = ENABLE; //if update is 0,can't do any setting
  36. WDGConfig.windowEn = DISABLE; //window mode watchdog
  37. WDGConfig.timeoutValue = tmpTimeoutValue; //time = pre*timeout/clk source
  38. WDGConfig.windowValue = NULL;
  39. WDGConfig.callBack = WDGCallback; //设置中断回调
  40. WDG_Init(&WDGConfig);
  41. WDG_Feed();
  42. #endif
  43. }
  44. void Watchdog_Feed(void)
  45. {
  46. #ifdef WATCHDOG_ENABLE
  47. WDG_Feed(); //刷新看门狗
  48. #endif
  49. }