File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 1919#include <rtthread.h>
2020#include <rtdevice.h>
2121
22- #define IWDG_DEVICE_NAME "iwg " /* 看门狗设备名称 */
22+ #define IWDG_DEVICE_NAME "wdt " /* 看门狗设备名称 */
2323
2424static rt_device_t wdg_dev ; /* 看门狗设备句柄 */
2525
@@ -33,7 +33,7 @@ static void idle_hook(void)
3333static int iwdg_sample (int argc , char * argv [])
3434{
3535 rt_err_t ret = RT_EOK ;
36- rt_uint32_t timeout = 1000 ; /* 溢出时间 */
36+ rt_uint32_t timeout = 10 ; /* 溢出时间 10 秒 */
3737 char device_name [RT_NAME_MAX ];
3838
3939 /* 判断命令行参数是否给定了设备名称 */
@@ -50,21 +50,27 @@ static int iwdg_sample(int argc, char *argv[])
5050 if (!wdg_dev )
5151 {
5252 rt_kprintf ("find %s failed!\n" , device_name );
53- return RT_ERROR ;
53+ return - RT_ERROR ;
5454 }
5555 /* 初始化设备 */
5656 ret = rt_device_init (wdg_dev );
5757 if (ret != RT_EOK )
5858 {
5959 rt_kprintf ("initialize %s failed!\n" , device_name );
60- return RT_ERROR ;
60+ return - RT_ERROR ;
6161 }
6262 /* 设置看门狗溢出时间 */
6363 ret = rt_device_control (wdg_dev , RT_DEVICE_CTRL_WDT_SET_TIMEOUT , & timeout );
6464 if (ret != RT_EOK )
6565 {
6666 rt_kprintf ("set %s timeout failed!\n" , device_name );
67- return RT_ERROR ;
67+ return - RT_ERROR ;
68+ }
69+ ret = rt_device_control (wdg_dev , RT_DEVICE_CTRL_WDT_START , RT_NULL );
70+ if (ret != RT_EOK )
71+ {
72+ rt_kprintf ("start %s failed!\n" , device_name );
73+ return - RT_ERROR ;
6874 }
6975 /* 设置空闲线程回调函数 */
7076 rt_thread_idle_sethook (idle_hook );
You can’t perform that action at this time.
0 commit comments