#include "watchdog.h" #include "string.h" #include "ac780x.h" #include "ac780x_wdg.h" #include "ac780x_wdg_reg.h" #include "ac780x_gpio.h" //#include "wdg_sample.h" #define WDG_Timeout(n) (n * APB_BUS_FREQ) #define WDG_CLK(n) (APB_BUS_FREQ * n -1) /** * WDGCallback * * @param[in] wparam: reserved * @param[in] lparam: reserved * @return 0: success, other: error * * @brief Watchdog IRQ callback function * 中断服务仅有128个总线时钟(时间极短),然后MCU会被复位 */ void WDGCallback(void *device, uint32_t wpara, uint32_t lpara) { return; } void Watchdog_Init(void) { #ifdef WATCHDOG_ENABLE uint32_t tmpTimeoutValue = WDG_CLK(WATCHDOG_TIMEOUT); // (119999999+1)/24000000 = 5s(时钟为48M) WDG_ConfigType WDGConfig; memset(&WDGConfig,0,sizeof(WDGConfig)); WDGConfig.clockSource = WDG_CLOCK_APB; //0 is 24MHz clk source WDGConfig.WDGEn = ENABLE; WDGConfig.interruptEn = ENABLE; //使能中断,延迟128个总线时钟后复位,可在128总线时钟内执行中断例程 //若需要超时立即复位,禁能中断即可 WDGConfig.prescalerEn = DISABLE; //0:disable 256 pre, 1:enable 256 pre WDGConfig.updateEn = ENABLE; //if update is 0,can't do any setting WDGConfig.windowEn = DISABLE; //window mode watchdog WDGConfig.timeoutValue = tmpTimeoutValue; //time = pre*timeout/clk source WDGConfig.windowValue = NULL; WDGConfig.callBack = WDGCallback; //设置中断回调 WDG_Init(&WDGConfig); WDG_Feed(); #endif } void Watchdog_Feed(void) { #ifdef WATCHDOG_ENABLE WDG_Feed(); //刷新看门狗 #endif }