cli.h
浏览该文件的文档.
1 
6 #ifndef AOS_CLI_H
7 #define AOS_CLI_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
17 /* This struct is used to define the cli cmd format */
18 typedef void (*cmd_fun_t)(char *outbuf, int len, int argc, char **argv);
19 
21 {
22  const char *name;
23  const char *help;
24  cmd_fun_t function;
25 };
26 
27 #define SECTION(x) __attribute__((section(x)))
28 #define USED __attribute__((used))
29 
30 typedef int (*cli_region_func)(int argc, char **argv);
31 
32 /* cli region table */
33 struct cli_region
34 {
35  const char *name; /* the name of cli cmd*/
36  const char *desc; /* description of cli cmd */
37  cli_region_func func; /* the cli function */
38 };
39 
40 #define ALIOS_CLI_CMD_REGISTER(name, cmd, desc) \
41  const char __clisym_##cmd##_name[] SECTION(".rodata") = #cmd; \
42  const char __clisym_##cmd##_desc[] SECTION(".rodata") = #desc; \
43  static void name##_stub(char *buf, int len, int argc, char **argv) \
44  { \
45  name(argc, argv); \
46  } \
47  USED const struct cli_region __clisym_##cmd SECTION("CliRegion") = \
48  { \
49  __clisym_##cmd##_name, \
50  __clisym_##cmd##_desc, \
51  (cli_region_func)&name##_stub};
52 
53 
60 int aos_cli_init(void);
61 
70 int aos_cli_register_command(const struct cli_command *cmd);
71 
80 int aos_cli_unregister_command(const struct cli_command *cmd);
81 
91 int aos_cli_register_commands(const struct cli_command *cmds, int num);
92 
102 int aos_cli_unregister_commands(const struct cli_command *cmds, int num);
103 
111 int aos_cli_printf(const char *fmt, ...);
112 
119 int aos_cli_suspend(void);
120 
127 int aos_cli_resume(void);
128 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif /* AOS_CLI_H */
138 
int aos_cli_register_command(const struct cli_command *cmd)
This function register a command with the command-line interface
int aos_cli_init(void)
Initialize the CLI module
int aos_cli_suspend(void)
Suspend cli task
int aos_cli_resume(void)
Resume cli task
void(* cmd_fun_t)(char *outbuf, int len, int argc, char **argv)
Definition: cli.h:18
int aos_cli_unregister_commands(const struct cli_command *cmds, int num)
This function unregisters multi CLI commands
int(* cli_region_func)(int argc, char **argv)
Definition: cli.h:30
int aos_cli_printf(const char *fmt,...)
use aos_cli_printf instead of printf in cli cmd
int aos_cli_register_commands(const struct cli_command *cmds, int num)
This function register multi CLI commands
int aos_cli_unregister_command(const struct cli_command *cmd)
This function unregister a command from the command-line interface
const char * name
Definition: cli.h:22
const char * help
Definition: cli.h:23
Definition: cli.h:34
const char * desc
Definition: cli.h:36
const char * name
Definition: cli.h:35
cli_region_func func
Definition: cli.h:37