1 #include <stdint.h>
2 #include <stdio.h>
3 #include <aos/errno.h>
4 #if AOS_COMP_CLI
5 #include "aos/cli.h"
6 #endif
7 #include <vfsdev/wdg_dev.h>
8 #include <aos/driver/wdg.h>
9 
vfs_wdg_test(int count,int period)10 int vfs_wdg_test(int count, int period)
11 {
12     int ret = 0;
13     int fd = 0;
14 
15     fd = open("/dev/wdg0", 0);
16     printf("open wdg %s, fd:%d\r\n", fd >= 0 ? "success" : "fail", fd);
17 
18     if (fd >= 0) {
19         while (count--) {
20             ret = ioctl(fd, IOC_WDG_RELOAD, 0);
21             printf("wdg reload %s, ret:%d\r\n", ret ? "fail" : "succeed", ret);
22             usleep(period * 1000);
23         }
24         close(fd);
25         ret = 0;
26     } else {
27         ret = -EIO;
28     }
29 
30     printf("wdg test done\r\n");
31     return ret;
32 }
33 
wdg_reload_test(int32_t argc,char ** argv)34 static void wdg_reload_test(int32_t argc, char **argv)
35 {
36     int ret = 0;
37     int count = argc > 1 ? atoi(argv[1]) : 10;
38     int period = argc > 2 ? atoi(argv[2]) : 200;
39 
40     printf("watchdog comp reload test start!\r\n");
41     printf("watchdog comp reload test count:%d, period:%d ms\r\n", count, period);
42 
43     ret = vfs_wdg_test(count, period);
44     if (!ret) {
45         printf("watchdog comp reload test success!\r\n");
46     } else {
47          printf("watchdog comp reload test failed, ret:%d\r\n", ret);
48     }
49 
50     return;
51 }
52 
53 #if CONFIG_U_WDG_CORE
aos_wdg_reload_test(int32_t argc,char ** argv)54 static void aos_wdg_reload_test(int32_t argc, char **argv)
55 {
56     int ret = 0;
57     aos_status_t status = 0;
58     int count = argc > 1 ? atoi(argv[1]) : 10;
59     int period = argc > 2 ? atoi(argv[2]) : 200;
60     wdg_dev_handle_t wdg = NULL;
61 
62     printf("watchdog comp reload test start!\r\n");
63     printf("watchdog comp reload test count:%d, period:%d ms\r\n", count, period);
64 
65     wdg = aos_wdg_open(0, 1000);
66     if (!wdg) {
67         printf("aos_wdg_open fails\r\n");
68         return;
69     }
70 
71     status = aos_wdg_start(wdg);
72     if (status) {
73         printf("aos_wdg_start fails, status:%d\r\n", status);
74         goto out;
75     }
76 
77     aos_msleep(500);
78     status = aos_wdg_feed(wdg);
79     if (status) {
80         printf("aos_wdg_feed fails, status:%d\r\n", status);
81         goto out;
82     }
83 
84     status = aos_wdg_stop(wdg);
85     if (status) {
86         printf("aos_wdg_feed fails, status:%d\r\n", status);
87         goto out;
88     }
89 
90     status = aos_wdg_timeout_set(wdg, 2000);
91     if (status) {
92         printf("aos_wdg_feed fails, status:%d\r\n", status);
93         goto out;
94     }
95 
96     status = aos_wdg_start(wdg);
97     if (status) {
98         printf("aos_wdg_feed fails, status:%d\r\n", status);
99         goto out;
100     }
101 
102     aos_msleep(3000);
103     status = aos_wdg_feed(wdg);
104     if (status) {
105         printf("aos_wdg_feed fails, status:%d\r\n", status);
106         goto out;
107     }
108 
109     status = aos_wdg_stop(wdg);
110     if (status) {
111         printf("aos_wdg_feed fails, status:%d\r\n", status);
112         goto out;
113     }
114 
115 out:
116     status = aos_wdg_close(wdg);
117     if (status) {
118         printf("aos_wdg_feed fails, status:%d\r\n", status);
119         return;
120     }
121 
122     return;
123 }
124 #endif
125 
126 #if AOS_COMP_CLI
127 /* reg args: fun, cmd, description*/
128 ALIOS_CLI_CMD_REGISTER(wdg_reload_test, wdg_reload, reset watchdog operation example)
129 #if CONFIG_U_WDG_CORE
130 ALIOS_CLI_CMD_REGISTER(aos_wdg_reload_test, aos_wdg_reload, reset watchdog operation example)
131 #endif
132 #endif