示例代码
WDT
示例演示了WDT喂狗功能,工程路径:SDK_Folder\projects\peripheral\aon_wdt\app_aon_wdt_reset。
示例工程流程图
首先初始化WDT模块,设置喂狗时间最大间隔2s内,alarm为1s,当1s未喂狗,将产生中断进行提示喂狗,2s未喂狗,将复位系统。示例工程每300 ms喂狗一次,喂狗10次。喂完后,1s将产生中断,2s将复位系统。
初始化参数
app_aon_wdt_params_t s_params;
#if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR551X)
s_params.init.counter = 32768 * 2 - 1;
s_params.init.alarm_counter = 0x1F;
#else
s_params.init.counter = 2000;
s_params.init.alarm_counter = 1000;
#endif
app_aon_wdt_init(&s_params, app_aon_wdt_evt_handler);
- counter:2s不进行喂狗,系统将复位
- alarm_counter:闹钟值,当计数值递减到该值,会产生中断
重要函数
- 初始化WDT
app_aon_wdt_init(&s_params, app_aon_wdt_evt_handler)
s_params初始化参数结构体,app_aon_wdt_evt_handler回调函数。
- 喂狗
app_aon_wdt_refresh()
Counter将重新计数。
测试验证
连接开发板到PC端,打开串口助手,连接串口,查看串口日志。可以看到10次正常喂狗,10次以后未进行正常喂狗开始复位系统。
[15:37:17.554]
0th feed dog.
[15:37:17.856]
1th feed dog.
[15:37:18.159]
2th feed dog.
[15:37:18.460]
3th feed dog.
[15:37:18.763]
4th feed dog.
[15:37:19.065]
5th feed dog.
[15:37:19.368]
6th feed dog.
[15:37:19.670]
7th feed dog.
[15:37:19.971]
8th feed dog.
[15:37:20.274]
9th feed dog.
System will reset.