• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Beken Corporation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 
17 #include <os/os.h>
18 #include "cli.h"
19 #include <driver/wdt.h>
20 #include <bk_wdt.h>
21 
cli_wdt_help(void)22 static void cli_wdt_help(void)
23 {
24 	CLI_LOGI("wdt_driver init\n");
25 	CLI_LOGI("wdt_driver deinit\n");
26 	CLI_LOGI("wdt start [timeout]\n");
27 	CLI_LOGI("wdt stop\n");
28 	CLI_LOGI("wdt feed\n");
29 }
30 
cli_wdt_driver_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)31 static void cli_wdt_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
32 {
33 	if (argc < 2) {
34 		cli_wdt_help();
35 		return;
36 	}
37 
38 	if (os_strcmp(argv[1], "init") == 0) {
39 		BK_LOG_ON_ERR(bk_wdt_driver_init());
40 		CLI_LOGI("wdt driver init\n");
41 	} else if (os_strcmp(argv[1], "deinit") == 0) {
42 		BK_LOG_ON_ERR(bk_wdt_driver_deinit());
43 		CLI_LOGI("wdt driver deinit\n");
44 	} else {
45 		cli_wdt_help();
46 		return;
47 	}
48 }
49 
cli_wdt_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)50 static void cli_wdt_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
51 {
52 	if (argc < 2) {
53 		cli_wdt_help();
54 		return;
55 	}
56 
57 	if (os_strcmp(argv[1], "start") == 0) {
58 		uint32_t timeout = os_strtoul(argv[2], NULL, 10);
59 		BK_LOG_ON_ERR(bk_wdt_start(timeout));
60 		CLI_LOGI("wdt start, timeout=%d\n", timeout);
61 	} else if (os_strcmp(argv[1], "stop") == 0) {
62 		BK_LOG_ON_ERR(bk_wdt_stop());
63 		CLI_LOGI("wdt stop\n");
64 	}else if (os_strcmp(argv[1], "feed") == 0) {
65 		BK_LOG_ON_ERR(bk_wdt_feed());
66 		CLI_LOGI("wdt feed\n");
67 	}else if (os_strcmp(argv[1], "disable") == 0) {
68 		extern void wdt_debug_disable(void);
69 		wdt_debug_disable();
70 		bk_wdt_stop();
71 		bk_task_wdt_stop();
72 		CLI_LOGI("wdt debug disabled\n");
73 	}else if (os_strcmp(argv[1], "enable") == 0) {
74 		extern void wdt_debug_enable(void);
75 		extern void wdt_init(void);
76 		wdt_debug_enable();
77 		wdt_init();
78 		CLI_LOGI("wdt debug enabled\n");
79 	}else if (os_strcmp(argv[1], "while") == 0) {
80 		GLOBAL_INT_DECLARATION();
81 		GLOBAL_INT_DISABLE();
82 		CLI_LOGI("wdt enter while1\n");
83 		while(1);
84 		GLOBAL_INT_RESTORE();
85 	} else {
86 		cli_wdt_help();
87 		return;
88 	}
89 }
90 
91 #define WDT_CMD_CNT (sizeof(s_wdt_commands) / sizeof(struct cli_command))
92 static const struct cli_command s_wdt_commands[] = {
93 	{"wdt_driver", "{init|deinit}", cli_wdt_driver_cmd},
94 	{"wdt", "wdt {start|stop|feed} [...]", cli_wdt_cmd}
95 };
96 
cli_wdt_init(void)97 int cli_wdt_init(void)
98 {
99 	BK_LOG_ON_ERR(bk_wdt_driver_init());
100 	return cli_register_commands(s_wdt_commands, WDT_CMD_CNT);
101 }
102 
103