1 Preface
The shell can deal with subsystems, and subsystems can provide many interfaces for external settings and read information.
Below is the kconfig configuration of the shell, the use of the shell, and how to create a new shell command.
It can be said that the shell is a glimpse of the core of the pipeline, with this pipeline can make development more than a multiplier.
There are times when you need to add commands to develop and debug your requirements.
2 Shell-related configuration
CONFIG_CONSOLE_SHELL是Shell子系统的开关,打开某一个模块的Shell,比如NET可以通过
Config_net_shell=y.
The enable of the submodule must be based on Config_console_shell.
If you want to add a shell configuration, you need to add an option to Kconfig in the corresponding submodule in the case of enable Config_console_shell.
3 Add a shell command
Add a shell command with the following steps.
1. Add an option that must, of course, define theCONFIG_CONSOLE_SHELL情况下才有效。
2. SHELL_REGISTER
register a new command, including the command name and callback function.
Shell command structure:
struct shell_cmd { constChar *cmd_name;--------------- subcommand name shell_cmd_ Function_t CB;------------ subcommand callback constChar * help;---------------- --- sub-command help Information };
3.1 Kernel command of the daytime
The kernel command provides access to the
#ifDefined (config_init_stacks)Static intShell_cmd_stack (intargcChar*argv[]) {K_call_stacks_analyze (); return 0;}#endifstruct Shell_cmdKernel_commands[] ={-----------------------------------------struct-body array of type Shell_cmd { "Version", Shell_cmd_version, "Show kernel version" },-------------------- { "Uptime", Shell_cmd_uptime,"Show system uptime in milliseconds" }, { "Cycles", Shell_cmd_cycles,"Show system Hardware cycles" },#ifDefined (config_object_tracing) && defined (config_thread_monitor) { "Tasks", Shell_cmd_tasks,"Show running Tasks" },#endif#ifDefined (config_init_stacks) { "Stacks", Shell_cmd_stack,"Show System Stacks" },#endif{null, NULL, NULL}}; Shell_register (Shell_kernel, kernel_commands);--------------------------------- Register the shell with the Shell_register command , the handler function is kernel_commands.
4 Shell-related APIs
Located in Shell API Functions.
Shell subsystem Initialization sys_init (Shell_run, Application, Config_kernel_init_priority_default) (SHELL_SERVICE.C).
#defineShell_prompt "Shell>"intShell_run (structDevice *Dev) {arg_unused (dev); Shell_init (shell_prompt); return 0;} Sys_init (Shell_run, Application, config_kernel_init_priority_default);---------------Shell subsystem initialization voidShell_init (Const Char*str) {K_fifo_init (&cmds_queue); K_fifo_init (&avail_queue); Line_queue_init (); Prompt= str? Str:""; K_thread_create (&shell_thread, Stack, STACKSIZE, shell, NULL, NULL,--------------- Create a shell thread to process the shell command NULL, K_prio _coop (7),0, k_no_wait); /*Register Serial Console Handler*/#ifdef config_uart_console uart_register_input (&avail_queue, &cmds_queue, completion);#endif#ifdef config_telnet_console telnet_register_input (&avail_queue, &cmds_queue, completion);#endif}
Zephyr's Shell