| 49 | } |
| 50 | |
| 51 | static int wdt_sample(int argc, char *argv[]) |
| 52 | { |
| 53 | int ret = RT_EOK; |
| 54 | rt_uint32_t timeleft; |
| 55 | rt_uint32_t timeout = atoi(argv[2]); |
| 56 | |
| 57 | if (argc != 3) |
| 58 | { |
| 59 | _wdt_cmd_print_usage(); |
| 60 | return -RT_ERROR; |
| 61 | } |
| 62 | |
| 63 | if (!rt_strcmp("set_timeout", argv[1])) |
| 64 | { |
| 65 | wdg_dev = rt_device_find(WDT_DEVICE_NAME); |
| 66 | if (!wdg_dev) |
| 67 | { |
| 68 | rt_kprintf("find %s failed!\n", WDT_DEVICE_NAME); |
| 69 | return -RT_ERROR; |
| 70 | } |
| 71 | |
| 72 | ret = rt_device_init(wdg_dev); |
| 73 | if (ret != RT_EOK) |
| 74 | { |
| 75 | rt_kprintf("init %s failed!\n", WDT_DEVICE_NAME); |
| 76 | return -RT_ERROR; |
| 77 | } |
| 78 | |
| 79 | /* Set timeout (Unit:S) */ |
| 80 | ret = rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_SET_TIMEOUT, &timeout); |
| 81 | if (ret != RT_EOK) |
| 82 | { |
| 83 | rt_kprintf("set %s timeout failed!\n", WDT_DEVICE_NAME); |
| 84 | return -RT_ERROR; |
| 85 | } |
| 86 | |
| 87 | /* Get the time when it real effective */ |
| 88 | ret = rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_GET_TIMEOUT, &valid_timeout); |
| 89 | if (ret != RT_EOK) |
| 90 | { |
| 91 | rt_kprintf("start %s failed!\n", WDT_DEVICE_NAME); |
| 92 | return -RT_ERROR; |
| 93 | } |
| 94 | rt_kprintf("valid_timeout = %d S\n", valid_timeout); |
| 95 | |
| 96 | /* Start WDT */ |
| 97 | ret = rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_START, RT_NULL); |
| 98 | if (ret != RT_EOK) |
| 99 | { |
| 100 | rt_kprintf("start %s failed!\n", WDT_DEVICE_NAME); |
| 101 | return -RT_ERROR; |
| 102 | } |
| 103 | |
| 104 | rt_thread_idle_sethook(idle_hook); |
| 105 | |
| 106 | for (;;) |
| 107 | { |
| 108 | rt_thread_mdelay(1000); |
nothing calls this directly
no test coverage detected