1.添加头文件
#include <ti/drivers/Watchdog.h>
#include <ti/drivers/watchdog/WatchdogCC26XX.h>
2.定义初始化函数
void WatchDog_Init(void)
{
Watchdog_init();
Watchdog_Params_init(¶ms);
params.callbackFxn = watchdogCallback;
params.resetMode = Watchdog_RESET_ON;
params.debugStallMode = Watchdog_DEBUG_STALL_ON;
handle = Watchdog_open(Board_WATCHDOG0, ¶ms);
// set timeout period to 100 ms
tickValue = Watchdog_convertMsToTicks(handle, 2000);
Watchdog_setReload(handle, tickValue);
Watchdog_close(handle);
// UserLog_Printf("WatchDog_Init successful!\r\n");
}
3.定义重载函数
void WatchDog_Rest(void)
{
Watchdog_clear(handle);
// UserLog_Printf("Watchdog_clear successful!\r\n");
}
注意:
在系统初始化中调用 WatchDog_Init函数,这里设置看门狗复位时间为2S
应保证在系统看门狗到期之前调用WatchDog_Rest函数,保证正常运行下,程序不会因为看门狗到期而复位。