2015-09-28 22:49:14 +08:00
|
|
|
/* shell.h - Shell header */
|
2015-04-28 16:37:33 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-28 16:37:33 +08:00
|
|
|
*/
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-07-31 21:16:29 +08:00
|
|
|
|
|
|
|
struct device;
|
|
|
|
|
2015-07-06 18:22:48 +08:00
|
|
|
/** @brief Callback called when command is entered.
|
2015-06-17 21:34:18 +08:00
|
|
|
*
|
|
|
|
* @param argc Number of parameters passed.
|
|
|
|
* @param argv Array of option strings. First option is always command name.
|
2016-05-19 18:57:15 +08:00
|
|
|
*
|
|
|
|
* @return 0 in case of success or negative value in case of error.
|
2015-06-17 21:34:18 +08:00
|
|
|
*/
|
2016-05-19 18:57:15 +08:00
|
|
|
typedef int (*shell_cmd_function_t)(int argc, char *argv[]);
|
2015-04-28 16:37:33 +08:00
|
|
|
|
2015-08-28 17:24:13 +08:00
|
|
|
struct shell_cmd {
|
|
|
|
const char *cmd_name;
|
2015-11-05 21:03:24 +08:00
|
|
|
shell_cmd_function_t cb;
|
2016-05-17 19:33:00 +08:00
|
|
|
const char *help;
|
2015-08-28 17:24:13 +08:00
|
|
|
};
|
|
|
|
|
2017-05-22 22:41:16 +08:00
|
|
|
/** @brief Callback to get the current prompt.
|
|
|
|
*
|
|
|
|
* @returns Current prompt string.
|
|
|
|
*/
|
|
|
|
typedef const char *(*shell_prompt_function_t)(void);
|
2016-07-31 21:16:29 +08:00
|
|
|
|
|
|
|
struct shell_module {
|
|
|
|
const char *module_name;
|
|
|
|
const struct shell_cmd *commands;
|
2017-05-22 22:41:16 +08:00
|
|
|
shell_prompt_function_t prompt;
|
2016-07-31 21:16:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-24 02:25:47 +08:00
|
|
|
* @brief Kernel Shell API
|
|
|
|
* @defgroup _shell_api_functions Shell API Functions
|
2016-07-31 21:16:29 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @def SHELL_REGISTER
|
|
|
|
*
|
|
|
|
* @brief Create shell_module object and set it up for boot time initialization.
|
|
|
|
*
|
|
|
|
* @details This macro defines a shell_module object that is automatically
|
|
|
|
* configured by the kernel during system initialization.
|
|
|
|
*
|
2017-05-22 22:41:16 +08:00
|
|
|
* @param _name Module name to be entered in shell console.
|
|
|
|
* @param _commands Array of commands to register.
|
|
|
|
* Shell array entries must be packed to calculate array size correctly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @def SHELL_REGISTER_WITH_PROMPT
|
|
|
|
*
|
|
|
|
* @brief Create shell_module object and set it up for boot time initialization.
|
2016-07-31 21:16:29 +08:00
|
|
|
*
|
2017-05-22 22:41:16 +08:00
|
|
|
* @details This macro defines a shell_module object that is automatically
|
|
|
|
* configured by the kernel during system initialization, in addition to that
|
|
|
|
* this also enables setting a custom prompt handler when the module is
|
|
|
|
* selected.
|
|
|
|
*
|
|
|
|
* @param _name Module name to be entered in shell console.
|
|
|
|
* @param _commands Array of commands to register.
|
2016-07-31 21:16:29 +08:00
|
|
|
* Shell array entries must be packed to calculate array size correctly.
|
2017-05-22 22:41:16 +08:00
|
|
|
* @param _prompt Optional prompt handler to be set when module is selected.
|
2016-07-31 21:16:29 +08:00
|
|
|
*/
|
2016-12-24 03:06:46 +08:00
|
|
|
#ifdef CONFIG_CONSOLE_SHELL
|
2017-05-22 22:41:16 +08:00
|
|
|
#define SHELL_REGISTER(_name, _commands) \
|
|
|
|
SHELL_REGISTER_WITH_PROMPT(_name, _commands, NULL)
|
|
|
|
|
|
|
|
#define SHELL_REGISTER_WITH_PROMPT(_name, _commands, _prompt) \
|
2016-07-31 21:16:29 +08:00
|
|
|
\
|
2017-05-22 22:41:16 +08:00
|
|
|
static struct shell_module (__shell__name) __used \
|
2016-07-31 21:16:29 +08:00
|
|
|
__attribute__((__section__(".shell_"))) = { \
|
2017-05-22 22:41:16 +08:00
|
|
|
.module_name = _name, \
|
|
|
|
.commands = _commands, \
|
|
|
|
.prompt = _prompt \
|
2016-07-31 21:16:29 +08:00
|
|
|
}
|
|
|
|
#else
|
2017-05-22 22:41:16 +08:00
|
|
|
#define SHELL_REGISTER(_name, _commands)
|
|
|
|
#define SHELL_REGISTER_WITH_PROMPT(_name, _commands, _prompt)
|
2016-07-31 21:16:29 +08:00
|
|
|
#endif
|
|
|
|
|
2015-07-06 18:22:48 +08:00
|
|
|
/** @brief Initialize shell with optional prompt, NULL in case no prompt is
|
2015-06-17 21:34:18 +08:00
|
|
|
* needed.
|
2015-04-28 16:37:33 +08:00
|
|
|
*
|
2015-06-17 21:34:18 +08:00
|
|
|
* @param prompt Prompt to be printed on serial console.
|
2015-04-28 16:37:33 +08:00
|
|
|
*/
|
2016-07-31 21:16:29 +08:00
|
|
|
void shell_init(const char *prompt);
|
2015-09-28 22:49:14 +08:00
|
|
|
|
|
|
|
/** @brief Optionally register an app default cmd handler.
|
|
|
|
*
|
2016-07-31 21:16:29 +08:00
|
|
|
* @param handler To be called if no cmd found in cmds registered with
|
|
|
|
* shell_init.
|
2015-09-28 22:49:14 +08:00
|
|
|
*/
|
2015-11-05 21:03:24 +08:00
|
|
|
void shell_register_app_cmd_handler(shell_cmd_function_t handler);
|
2015-09-28 22:49:14 +08:00
|
|
|
|
2015-12-04 19:10:36 +08:00
|
|
|
/** @brief Optionally register a custom prompt callback.
|
|
|
|
*
|
|
|
|
* @param handler To be called to get the current prompt.
|
|
|
|
*/
|
|
|
|
void shell_register_prompt_handler(shell_prompt_function_t handler);
|
2016-01-23 01:38:49 +08:00
|
|
|
|
2016-07-31 21:16:29 +08:00
|
|
|
/** @brief Optionally register a default module, to eliminate typing it in
|
|
|
|
* shell console or for backwards compatibility.
|
|
|
|
*
|
|
|
|
* @param name Module name.
|
|
|
|
*/
|
|
|
|
void shell_register_default_module(const char *name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-12-24 03:06:46 +08:00
|
|
|
#ifdef CONFIG_CONSOLE_SHELL
|
2016-07-31 21:16:29 +08:00
|
|
|
int shell_run(struct device *dev);
|
|
|
|
#else
|
2016-12-11 14:07:30 +08:00
|
|
|
static inline int shell_run(struct device *dev)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-07-31 21:16:29 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|