Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
shell.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef SHELL_H__
8#define SHELL_H__
9
10#include <zephyr/kernel.h>
17#include <zephyr/logging/log.h>
19#include <zephyr/sys/util.h>
20#include <zephyr/toolchain.h>
21
22#if defined CONFIG_SHELL_GETOPT
24#endif
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#ifndef CONFIG_SHELL_PROMPT_BUFF_SIZE
31#define CONFIG_SHELL_PROMPT_BUFF_SIZE 0
32#endif
33
34#ifndef CONFIG_SHELL_CMD_BUFF_SIZE
35#define CONFIG_SHELL_CMD_BUFF_SIZE 0
36#endif
37
38#ifndef CONFIG_SHELL_PRINTF_BUFF_SIZE
39#define CONFIG_SHELL_PRINTF_BUFF_SIZE 0
40#endif
41
42#ifndef CONFIG_SHELL_HISTORY_BUFFER
43#define CONFIG_SHELL_HISTORY_BUFFER 0
44#endif
45
46#define Z_SHELL_CMD_ROOT_LVL (0u)
47
48#define SHELL_HEXDUMP_BYTES_IN_LINE 16
49
61#define SHELL_OPT_ARG_RAW (0xFE)
62
66#define SHELL_OPT_ARG_CHECK_SKIP (0xFF)
67
72#define SHELL_OPT_ARG_MAX (0xFD)
73
82
84
96typedef void (*shell_dynamic_get)(size_t idx,
97 struct shell_static_entry *entry);
98
109
110struct shell;
111
116
132const struct device *shell_device_lookup(size_t idx,
133 const char *prefix);
134
151const struct device *shell_device_lookup_all(size_t idx,
152 const char *prefix);
153
169const struct device *shell_device_lookup_non_ready(size_t idx,
170 const char *prefix);
171
182typedef bool (*shell_device_filter_t)(const struct device *dev);
183
197const struct device *shell_device_filter(size_t idx,
198 shell_device_filter_t filter);
199
220const struct device *shell_device_get_binding(const char *name);
221
237const struct device *shell_device_get_binding_all(const char *name);
238
251typedef int (*shell_cmd_handler)(const struct shell *sh,
252 size_t argc, char **argv);
253
267typedef int (*shell_dict_cmd_handler)(const struct shell *sh, size_t argc,
268 char **argv, void *data);
269
270/* When entries are added to the memory section a padding is applied for
271 * the posix architecture with 64bits builds and x86_64 targets. Adding padding to allow handle data
272 * in the memory section as array.
273 */
274#if (defined(CONFIG_ARCH_POSIX) && defined(CONFIG_64BIT)) || defined(CONFIG_X86_64)
275#define Z_SHELL_STATIC_ENTRY_PADDING 24
276#else
277#define Z_SHELL_STATIC_ENTRY_PADDING 0
278#endif
279
280/*
281 * @brief Shell static command descriptor.
282 */
284 const char *syntax;
285 const char *help;
286 const union shell_cmd_entry *subcmd;
289 uint8_t padding[Z_SHELL_STATIC_ENTRY_PADDING];
290};
291
300 /* @cond INTERNAL_HIDDEN */
301 uint32_t magic;
302 /* @endcond */
303 const char *description;
304 const char *usage;
305};
306
310
315#define SHELL_STRUCTURED_HELP_MAGIC 0x86D20BC4
316
320
327static inline bool shell_help_is_structured(const char *help)
328{
329 const uint32_t magic32 = SHELL_STRUCTURED_HELP_MAGIC;
330 const char *magic = (const char *)&magic32;
331
337 return help != NULL && (magic[0] == help[0]) && (magic[1] == help[1])
338 && (magic[2] == help[2]) && (magic[3] == help[3]);
339}
340
341#if defined(CONFIG_SHELL_HELP) || defined(__DOXYGEN__)
365#define SHELL_HELP(_description, _usage) \
366 ((const char *)&(const struct shell_cmd_help){ \
367 .magic = SHELL_STRUCTURED_HELP_MAGIC, \
368 .description = (_description), \
369 .usage = (_usage), \
370 })
371#else
372#define SHELL_HELP(_description, _usage) NULL
373#endif /* CONFIG_SHELL_HELP */
374
390#define SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, \
391 mandatory, optional) \
392 static const struct shell_static_entry UTIL_CAT(_shell_, syntax) = \
393 SHELL_CMD_ARG(syntax, subcmd, help, handler, mandatory, optional); \
394 static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, \
395 UTIL_CAT(shell_cmd_, syntax), shell_root_cmds, \
396 UTIL_CAT(shell_cmd_, syntax) \
397 ) = { \
398 .entry = &UTIL_CAT(_shell_, syntax) \
399 }
400
421#define SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, \
422 mandatory, optional) \
423 COND_CODE_1(\
424 flag, \
425 (\
426 SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, \
427 mandatory, optional) \
428 ), \
429 (\
430 static shell_cmd_handler dummy_##syntax##_handler __unused = \
431 handler;\
432 static const union shell_cmd_entry *dummy_subcmd_##syntax \
433 __unused = subcmd\
434 ) \
435 )
447#define SHELL_CMD_REGISTER(syntax, subcmd, help, handler) \
448 SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, 0, 0)
449
463#define SHELL_COND_CMD_REGISTER(flag, syntax, subcmd, help, handler) \
464 SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, 0, 0)
465
484#define SHELL_STATIC_SUBCMD_SET_CREATE(name, ...) \
485 static const struct shell_static_entry shell_##name[] = { \
486 __VA_ARGS__ \
487 }; \
488 static const union shell_cmd_entry name = { \
489 .entry = shell_##name \
490 }
491
492#define Z_SHELL_UNDERSCORE(x) _##x
493#define Z_SHELL_SUBCMD_NAME(...) \
494 UTIL_CAT(shell_subcmds, MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__))
495#define Z_SHELL_SUBCMD_SECTION_TAG(...) MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__)
496#define Z_SHELL_SUBCMD_SET_SECTION_TAG(x) \
497 Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x)
498#define Z_SHELL_SUBCMD_ADD_SECTION_TAG(x, y) \
499 Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x, y)
500
512
513#define SHELL_SUBCMD_SET_CREATE(_name, _parent) \
514 static const TYPE_SECTION_ITERABLE(struct shell_static_entry, _name, shell_subcmds, \
515 Z_SHELL_SUBCMD_SET_SECTION_TAG(_parent))
516
517
537#define SHELL_SUBCMD_COND_ADD(_flag, _parent, _syntax, _subcmd, _help, _handler, \
538 _mand, _opt) \
539 COND_CODE_1(_flag, \
540 (static const TYPE_SECTION_ITERABLE(struct shell_static_entry, \
541 Z_SHELL_SUBCMD_NAME(__DEBRACKET _parent, _syntax), \
542 shell_subcmds, \
543 Z_SHELL_SUBCMD_ADD_SECTION_TAG(_parent, _syntax)) = \
544 SHELL_EXPR_CMD_ARG(1, _syntax, _subcmd, _help, \
545 _handler, _mand, _opt)\
546 ), \
547 (static shell_cmd_handler dummy_handler_##_syntax __unused = _handler;\
548 static const union shell_cmd_entry dummy_subcmd_##_syntax __unused = { \
549 .entry = (const struct shell_static_entry *)_subcmd\
550 } \
551 ) \
552 )
553
566#define SHELL_SUBCMD_ADD(_parent, _syntax, _subcmd, _help, _handler, _mand, _opt) \
567 SHELL_SUBCMD_COND_ADD(1, _parent, _syntax, _subcmd, _help, _handler, _mand, _opt)
568
573#define SHELL_SUBCMD_SET_END {0}
574
581#define SHELL_DYNAMIC_CMD_CREATE(name, get) \
582 static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, name, \
583 shell_dynamic_subcmds, name) = \
584 { \
585 .dynamic_get = get \
586 }
587
601#define SHELL_CMD_ARG(syntax, subcmd, help, handler, mand, opt) \
602 SHELL_EXPR_CMD_ARG(1, syntax, subcmd, help, handler, mand, opt)
603
623#define SHELL_COND_CMD_ARG(flag, syntax, subcmd, help, handler, mand, opt) \
624 SHELL_EXPR_CMD_ARG(IS_ENABLED(flag), syntax, subcmd, help, \
625 handler, mand, opt)
626
646#define SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, \
647 _mand, _opt) \
648 { \
649 .syntax = (_expr) ? (const char *)STRINGIFY(_syntax) : "", \
650 .help = (_expr) ? (const char *)_help : NULL, \
651 .subcmd = (const union shell_cmd_entry *)((_expr) ? \
652 _subcmd : NULL), \
653 .handler = (shell_cmd_handler)((_expr) ? _handler : NULL), \
654 .args = { .mandatory = _mand, .optional = _opt} \
655 }
656
665#define SHELL_CMD(_syntax, _subcmd, _help, _handler) \
666 SHELL_CMD_ARG(_syntax, _subcmd, _help, _handler, 0, 0)
667
680#define SHELL_COND_CMD(_flag, _syntax, _subcmd, _help, _handler) \
681 SHELL_COND_CMD_ARG(_flag, _syntax, _subcmd, _help, _handler, 0, 0)
682
696#define SHELL_EXPR_CMD(_expr, _syntax, _subcmd, _help, _handler) \
697 SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, 0, 0)
698
699/* Internal macro used for creating handlers for dictionary commands. */
700#define Z_SHELL_CMD_DICT_HANDLER_CREATE(_data, _handler) \
701static int UTIL_CAT(UTIL_CAT(cmd_dict_, UTIL_CAT(_handler, _)), \
702 GET_ARG_N(1, __DEBRACKET _data))( \
703 const struct shell *sh, size_t argc, char **argv) \
704{ \
705 return _handler(sh, argc, argv, \
706 (void *)GET_ARG_N(2, __DEBRACKET _data)); \
707}
708
709/* Internal macro used for creating dictionary commands. */
710#define SHELL_CMD_DICT_CREATE(_data, _handler) \
711 SHELL_CMD_ARG(GET_ARG_N(1, __DEBRACKET _data), NULL, GET_ARG_N(3, __DEBRACKET _data), \
712 UTIL_CAT(UTIL_CAT(cmd_dict_, UTIL_CAT(_handler, _)), \
713 GET_ARG_N(1, __DEBRACKET _data)), 1, 0)
714
748#define SHELL_SUBCMD_DICT_SET_CREATE(_name, _handler, ...) \
749 FOR_EACH_FIXED_ARG(Z_SHELL_CMD_DICT_HANDLER_CREATE, (), \
750 _handler, __VA_ARGS__) \
751 SHELL_STATIC_SUBCMD_SET_CREATE(_name, \
752 FOR_EACH_FIXED_ARG(SHELL_CMD_DICT_CREATE, (,), _handler, __VA_ARGS__), \
753 SHELL_SUBCMD_SET_END \
754 )
755
756/* @cond INTERNAL_HIDDEN */
757
762enum shell_receive_state {
763 SHELL_RECEIVE_DEFAULT,
764 SHELL_RECEIVE_ESC,
765 SHELL_RECEIVE_ESC_SEQ,
766 SHELL_RECEIVE_TILDE_EXP
767};
768
772enum shell_state {
773 SHELL_STATE_UNINITIALIZED,
774 SHELL_STATE_INITIALIZED,
775 SHELL_STATE_ACTIVE,
776 SHELL_STATE_PANIC_MODE_ACTIVE,
777 SHELL_STATE_PANIC_MODE_INACTIVE
778};
779
781enum shell_transport_evt {
782 SHELL_TRANSPORT_EVT_RX_RDY,
783 SHELL_TRANSPORT_EVT_TX_RDY
784};
785
786enum shell_readline_state {
787 SHELL_READLINE_INACTIVE,
788 SHELL_READLINE_ACTIVE,
789 SHELL_READLINE_DONE,
790 SHELL_READLINE_CANCELED,
791};
792
793/* @endcond */
794
795typedef void (*shell_transport_handler_t)(enum shell_transport_evt evt,
796 void *context);
797
798
799typedef void (*shell_uninit_cb_t)(const struct shell *sh, int res);
800
807typedef void (*shell_bypass_cb_t)(const struct shell *sh,
808 uint8_t *data,
809 size_t len,
810 void *user_data);
811
812struct shell_transport;
813
830 int (*init)(const struct shell_transport *transport,
831 const void *config,
832 shell_transport_handler_t evt_handler,
833 void *context);
834
842 int (*uninit)(const struct shell_transport *transport);
843
856 int (*enable)(const struct shell_transport *transport,
857 bool blocking_tx);
858
869 int (*write)(const struct shell_transport *transport,
870 const void *data, size_t length, size_t *cnt);
871
882 int (*read)(const struct shell_transport *transport,
883 void *data, size_t length, size_t *cnt);
884
892 void (*update)(const struct shell_transport *transport);
893
894};
895
898 void *ctx;
899};
900
907
908#ifdef CONFIG_SHELL_STATS
909#define Z_SHELL_STATS_DEFINE(_name) static struct shell_stats _name##_stats
910#define Z_SHELL_STATS_PTR(_name) (&(_name##_stats))
911#else
912#define Z_SHELL_STATS_DEFINE(_name)
913#define Z_SHELL_STATS_PTR(_name) NULL
914#endif /* CONFIG_SHELL_STATS */
915
927
928BUILD_ASSERT((sizeof(struct shell_backend_config_flags) == sizeof(uint32_t)),
929 "Structure must fit in 4 bytes");
930
934#define SHELL_DEFAULT_BACKEND_CONFIG_FLAGS \
935{ \
936 .insert_mode = 0, \
937 .echo = 1, \
938 .obscure = IS_ENABLED(CONFIG_SHELL_START_OBSCURED), \
939 .mode_delete = 1, \
940 .use_colors = 1, \
941 .use_vt100 = 1, \
942};
943
954
955BUILD_ASSERT((sizeof(struct shell_backend_ctx_flags) == sizeof(uint32_t)),
956 "Structure must fit in 4 bytes");
957
965
973
980
984struct shell_ctx {
985#if defined(CONFIG_SHELL_PROMPT_CHANGE) && CONFIG_SHELL_PROMPT_CHANGE
987#else
988 const char *prompt;
989#endif
990
991 enum shell_state state;
992 enum shell_receive_state receive_state;
993
995 enum shell_readline_state readline_state;
996
999
1002
1005
1010
1013
1016
1019
1020#if defined CONFIG_SHELL_GETOPT
1022 struct sys_getopt_state getopt;
1023#endif
1024
1027
1030
1033
1036
1039
1040 volatile union shell_backend_cfg cfg;
1041 volatile union shell_backend_ctx ctx;
1042
1044
1048};
1049
1050extern const struct log_backend_api log_backend_shell_api;
1051
1059
1063struct shell {
1064 const char *default_prompt;
1065
1066 const struct shell_transport *iface;
1067 struct shell_ctx *ctx;
1068
1070
1072
1074
1076
1078
1080
1081 const char *name;
1084};
1085
1086extern void z_shell_print_stream(const void *user_ctx, const char *data,
1087 size_t data_len);
1088
1101#define Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _out_buf, _log_backend, _shell_flag) \
1102 static const struct shell _name; \
1103 static struct shell_ctx UTIL_CAT(_name, _ctx); \
1104 Z_SHELL_HISTORY_DEFINE(_name##_history, CONFIG_SHELL_HISTORY_BUFFER); \
1105 Z_SHELL_FPRINTF_DEFINE(_name##_fprintf, &_name, _out_buf, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
1106 IS_ENABLED(CONFIG_SHELL_PRINTF_AUTOFLUSH), z_shell_print_stream); \
1107 LOG_INSTANCE_REGISTER(shell, _name, CONFIG_SHELL_LOG_LEVEL); \
1108 Z_SHELL_STATS_DEFINE(_name); \
1109 static K_KERNEL_STACK_DEFINE(_name##_stack, CONFIG_SHELL_STACK_SIZE); \
1110 static struct k_thread _name##_thread; \
1111 static const STRUCT_SECTION_ITERABLE(shell, _name) = { \
1112 .default_prompt = _prompt, \
1113 .iface = _transport_iface, \
1114 .ctx = &UTIL_CAT(_name, _ctx), \
1115 .history = IS_ENABLED(CONFIG_SHELL_HISTORY) ? &_name##_history : NULL, \
1116 .shell_flag = _shell_flag, \
1117 .fprintf_ctx = &_name##_fprintf, \
1118 .stats = Z_SHELL_STATS_PTR(_name), \
1119 .log_backend = _log_backend, \
1120 LOG_INSTANCE_PTR_INIT(log, shell, _name).name = \
1121 STRINGIFY(_name), .thread = &_name##_thread, .stack = _name##_stack}
1122
1136#define SHELL_DEFINE(_name, _prompt, _transport_iface, _log_queue_size, _log_timeout, _shell_flag) \
1137 static uint8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \
1138 Z_SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
1139 _log_queue_size, _log_timeout); \
1140 Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _name##_out_buffer, \
1141 Z_SHELL_LOG_BACKEND_PTR(_name), _shell_flag)
1142
1156int shell_init(const struct shell *sh, const void *transport_config,
1157 struct shell_backend_config_flags cfg_flags,
1158 bool log_backend, uint32_t init_log_level);
1159
1166void shell_uninit(const struct shell *sh, shell_uninit_cb_t cb);
1167
1175int shell_start(const struct shell *sh);
1176
1184int shell_stop(const struct shell *sh);
1185
1189#define SHELL_NORMAL SHELL_VT100_COLOR_DEFAULT
1190
1194#define SHELL_INFO SHELL_VT100_COLOR_GREEN
1195
1199#define SHELL_OPTION SHELL_VT100_COLOR_CYAN
1200
1204#define SHELL_WARNING SHELL_VT100_COLOR_YELLOW
1205
1209#define SHELL_ERROR SHELL_VT100_COLOR_RED
1210
1222void __printf_like(3, 4) shell_fprintf_impl(const struct shell *sh, enum shell_vt100_color color,
1223 const char *fmt, ...);
1224
1225#define shell_fprintf(sh, color, fmt, ...) shell_fprintf_impl(sh, color, fmt, ##__VA_ARGS__)
1226
1239void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
1240 const char *fmt, va_list args);
1241
1257void shell_hexdump_line(const struct shell *sh, unsigned int offset,
1258 const uint8_t *data, size_t len);
1259
1267void shell_hexdump(const struct shell *sh, const uint8_t *data, size_t len);
1268
1278#define shell_info(_sh, _ft, ...) \
1279 shell_fprintf_info(_sh, _ft "\n", ##__VA_ARGS__)
1280void __printf_like(2, 3) shell_fprintf_info(const struct shell *sh, const char *fmt, ...);
1281
1291#define shell_print(_sh, _ft, ...) \
1292 shell_fprintf_normal(_sh, _ft "\n", ##__VA_ARGS__)
1293void __printf_like(2, 3) shell_fprintf_normal(const struct shell *sh, const char *fmt, ...);
1294
1304#define shell_warn(_sh, _ft, ...) \
1305 shell_fprintf_warn(_sh, _ft "\n", ##__VA_ARGS__)
1306void __printf_like(2, 3) shell_fprintf_warn(const struct shell *sh, const char *fmt, ...);
1307
1317#define shell_error(_sh, _ft, ...) \
1318 shell_fprintf_error(_sh, _ft "\n", ##__VA_ARGS__)
1319void __printf_like(2, 3) shell_fprintf_error(const struct shell *sh, const char *fmt, ...);
1320
1327void shell_process(const struct shell *sh);
1328
1338int shell_prompt_change(const struct shell *sh, const char *prompt);
1339
1348void shell_help(const struct shell *sh);
1349
1351#define SHELL_CMD_HELP_PRINTED (1)
1352
1370int shell_execute_cmd(const struct shell *sh, const char *cmd);
1371
1383int shell_set_root_cmd(const char *cmd);
1384
1394void shell_set_bypass(const struct shell *sh, shell_bypass_cb_t bypass, void *user_data);
1395
1403bool shell_ready(const struct shell *sh);
1404
1415int shell_insert_mode_set(const struct shell *sh, bool val);
1416
1428int shell_use_colors_set(const struct shell *sh, bool val);
1429
1440int shell_use_vt100_set(const struct shell *sh, bool val);
1441
1452int shell_echo_set(const struct shell *sh, bool val);
1453
1465int shell_obscure_set(const struct shell *sh, bool obscure);
1466
1478int shell_mode_delete_set(const struct shell *sh, bool val);
1479
1487int shell_get_return_value(const struct shell *sh);
1488
1510int shell_readline(const struct shell *sh, uint8_t *buf, size_t len, k_timeout_t timeout);
1511
1515
1516#ifdef __cplusplus
1517}
1518#endif
1519
1520#ifdef CONFIG_SHELL_CUSTOM_HEADER
1521/* This include must always be at the end of shell.h */
1522#include <zephyr_custom_shell.h>
1523#endif
1524
1525#endif /* SHELL_H__ */
struct z_thread_stack_element k_thread_stack_t
Typedef of struct z_thread_stack_element.
Definition arch_interface.h:46
long atomic_t
Definition atomic_types.h:15
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
int shell_readline(const struct shell *sh, uint8_t *buf, size_t len, k_timeout_t timeout)
Read a line of input from the shell.
static bool shell_help_is_structured(const char *help)
Check if help string is structured help.
Definition shell.h:327
void shell_uninit(const struct shell *sh, shell_uninit_cb_t cb)
Uninitializes the transport layer and the internal shell state.
void(* shell_uninit_cb_t)(const struct shell *sh, int res)
Definition shell.h:799
void shell_hexdump_line(const struct shell *sh, unsigned int offset, const uint8_t *data, size_t len)
Print a line of data in hexadecimal format.
int(* shell_dict_cmd_handler)(const struct shell *sh, size_t argc, char **argv, void *data)
Shell dictionary command handler prototype.
Definition shell.h:267
#define shell_fprintf(sh, color, fmt,...)
Definition shell.h:1225
int shell_prompt_change(const struct shell *sh, const char *prompt)
Change displayed shell prompt.
void(* shell_transport_handler_t)(enum shell_transport_evt evt, void *context)
Definition shell.h:795
int shell_mode_delete_set(const struct shell *sh, bool val)
Allow application to control whether the delete key backspaces or deletes.
void shell_fprintf_info(const struct shell *sh, const char *fmt,...)
int(* shell_cmd_handler)(const struct shell *sh, size_t argc, char **argv)
Shell command handler prototype.
Definition shell.h:251
void shell_fprintf_error(const struct shell *sh, const char *fmt,...)
void shell_set_bypass(const struct shell *sh, shell_bypass_cb_t bypass, void *user_data)
Set bypass callback.
int shell_get_return_value(const struct shell *sh)
Retrieve return value of most recently executed shell command.
shell_flag
Flags for setting shell output newline sequence.
Definition shell.h:1055
const struct device * shell_device_lookup(size_t idx, const char *prefix)
Get by index a device that matches .
shell_signal
Definition shell.h:974
void shell_fprintf_normal(const struct shell *sh, const char *fmt,...)
void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color, const char *fmt, va_list args)
vprintf-like function which sends formatted data stream to the shell.
int shell_set_root_cmd(const char *cmd)
Set root command for all shell instances.
bool shell_ready(const struct shell *sh)
Get shell readiness to execute commands.
int shell_use_colors_set(const struct shell *sh, bool val)
Allow application to control whether terminal output uses colored syntax.
void shell_process(const struct shell *sh)
Process function, which should be executed when data is ready in the transport interface.
const struct device * shell_device_get_binding(const char *name)
Get a device reference from its device::name field or label.
int shell_use_vt100_set(const struct shell *sh, bool val)
Allow application to control whether terminal is using vt100 commands.
void shell_fprintf_impl(const struct shell *sh, enum shell_vt100_color color, const char *fmt,...)
printf-like function which sends formatted data stream to the shell.
int shell_obscure_set(const struct shell *sh, bool obscure)
Allow application to control whether user input is obscured with asterisks – useful for implementing ...
int shell_init(const struct shell *sh, const void *transport_config, struct shell_backend_config_flags cfg_flags, bool log_backend, uint32_t init_log_level)
Function for initializing a transport layer and internal shell state.
const struct device * shell_device_lookup_all(size_t idx, const char *prefix)
Get by index a device that matches .
const struct device * shell_device_get_binding_all(const char *name)
Get a device reference from its device::name field or label.
void shell_fprintf_warn(const struct shell *sh, const char *fmt,...)
const struct device * shell_device_lookup_non_ready(size_t idx, const char *prefix)
Get by index a non-initialized device that matches .
bool(* shell_device_filter_t)(const struct device *dev)
Filter callback type, for use with shell_device_lookup_filter.
Definition shell.h:182
int shell_execute_cmd(const struct shell *sh, const char *cmd)
Execute command.
void shell_help(const struct shell *sh)
Prints the current command help.
void(* shell_bypass_cb_t)(const struct shell *sh, uint8_t *data, size_t len, void *user_data)
Bypass callback.
Definition shell.h:807
int shell_stop(const struct shell *sh)
Function for stopping shell processing.
int shell_start(const struct shell *sh)
Function for starting shell processing.
int shell_echo_set(const struct shell *sh, bool val)
Allow application to control whether user input is echoed back.
const struct log_backend_api log_backend_shell_api
const struct device * shell_device_filter(size_t idx, shell_device_filter_t filter)
Get a device by index and filter.
void shell_hexdump(const struct shell *sh, const uint8_t *data, size_t len)
Print data in hexadecimal format.
int shell_insert_mode_set(const struct shell *sh, bool val)
Allow application to control text insert mode.
void(* shell_dynamic_get)(size_t idx, struct shell_static_entry *entry)
Shell dynamic command descriptor.
Definition shell.h:96
@ SHELL_FLAG_CRLF_DEFAULT
Do not map CR or LF.
Definition shell.h:1056
@ SHELL_FLAG_OLF_CRLF
Map LF to CRLF on output.
Definition shell.h:1057
@ SHELL_SIGNAL_TXDONE
Definition shell.h:978
@ SHELL_SIGNAL_RXRDY
Definition shell.h:975
@ SHELL_SIGNAL_LOG_MSG
Definition shell.h:976
@ SHELL_SIGNAL_KILL
Definition shell.h:977
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define NULL
Definition iar_missing_defs.h:20
#define BUILD_ASSERT(EXPR, MSG...)
Definition llvm.h:51
struct k_thread * k_tid_t
Definition thread.h:383
Public kernel APIs.
#define CONFIG_SHELL_PROMPT_BUFF_SIZE
Definition shell.h:31
#define CONFIG_SHELL_CMD_BUFF_SIZE
Definition shell.h:35
#define CONFIG_SHELL_PRINTF_BUFF_SIZE
Definition shell.h:39
shell_vt100_color
Definition shell_types.h:14
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const char * name
Name of the device instance.
Definition device.h:515
Event Structure.
Definition kernel.h:2631
Semaphore structure.
Definition kernel.h:3607
Thread Structure.
Definition thread.h:259
Kernel timeout type.
Definition clock.h:65
Logger backend API.
Definition log_backend.h:63
Logger backend structure.
Definition log_backend.h:95
Definition shell.h:919
uint32_t use_vt100
Controls VT100 commands usage in shell.
Definition shell.h:925
uint32_t mode_delete
Operation mode of backspace key.
Definition shell.h:923
uint32_t echo
Controls shell echo.
Definition shell.h:921
uint32_t insert_mode
Controls insert mode for text introduction.
Definition shell.h:920
uint32_t obscure
If echo on, print asterisk instead.
Definition shell.h:922
uint32_t use_colors
Controls colored syntax.
Definition shell.h:924
Definition shell.h:944
uint32_t print_noinit
Print request from not initialized shell.
Definition shell.h:950
uint32_t sync_mode
Shell in synchronous mode.
Definition shell.h:951
uint32_t tx_rdy
Definition shell.h:946
uint32_t handle_log
Shell is handling logger backend.
Definition shell.h:952
uint32_t processing
Shell is executing process function.
Definition shell.h:945
uint32_t last_nl
Last received new line character.
Definition shell.h:948
uint32_t history_exit
Request to exit history mode.
Definition shell.h:947
uint32_t cmd_ctx
Shell is executing command.
Definition shell.h:949
Shell structured help descriptor.
Definition shell.h:299
const char * usage
Command usage string.
Definition shell.h:304
const char * description
Command description.
Definition shell.h:303
Shell instance context.
Definition shell.h:984
const struct shell_static_entry * selected_cmd
New root command.
Definition shell.h:1001
shell_uninit_cb_t uninit_cb
Callback called from shell thread context when unitialization is completed just before aborting shell...
Definition shell.h:1009
struct k_event signal_event
Definition shell.h:1043
void * bypass_user_data
When bypass is set, this user data pointer is passed to the callback.
Definition shell.h:1015
struct shell_vt100_ctx vt100_ctx
VT100 color and cursor position, terminal width.
Definition shell.h:1004
const char * prompt
Definition shell.h:988
k_tid_t tid
Definition shell.h:1046
char temp_buff[0]
Command temporary buffer.
Definition shell.h:1035
char cmd_buff[0]
Command input buffer.
Definition shell.h:1032
struct shell_static_entry active_cmd
Currently executed command.
Definition shell.h:998
uint32_t log_level
Definition shell.h:1018
volatile union shell_backend_cfg cfg
Definition shell.h:1040
uint16_t cmd_tmp_buff_len
Command length in tmp buffer.
Definition shell.h:1028
enum shell_state state
Internal module state.
Definition shell.h:991
uint16_t cmd_tmp_buff_pos
Command buffer cursor position in tmp buffer.
Definition shell.h:1029
shell_bypass_cb_t bypass
When bypass is set, all incoming data is passed to the callback.
Definition shell.h:1012
uint16_t cmd_buff_len
Command length.
Definition shell.h:1025
uint16_t cmd_buff_pos
Command buffer cursor position.
Definition shell.h:1026
int ret_val
Definition shell.h:1047
char printf_buff[0]
Printf buffer size.
Definition shell.h:1038
enum shell_receive_state receive_state
Escape sequence indicator.
Definition shell.h:992
volatile union shell_backend_ctx ctx
Definition shell.h:1041
struct k_sem lock_sem
Definition shell.h:1045
enum shell_readline_state readline_state
Field tracking the readline state for user input.
Definition shell.h:995
Definition shell_history.h:21
Shell log backend instance structure (RO data).
Definition shell_log_backend.h:36
Definition shell.h:112
uint8_t mandatory
Number of mandatory arguments.
Definition shell.h:113
uint8_t optional
Number of optional arguments.
Definition shell.h:114
Definition shell.h:283
const union shell_cmd_entry * subcmd
Pointer to subcommand.
Definition shell.h:286
uint8_t padding[0]
Definition shell.h:289
shell_cmd_handler handler
Command handler.
Definition shell.h:287
struct shell_static_args args
Command arguments.
Definition shell.h:288
const char * help
Command help string.
Definition shell.h:285
const char * syntax
Command syntax strings.
Definition shell.h:284
Shell statistics structure.
Definition shell.h:904
atomic_t log_lost_cnt
Lost log counter.
Definition shell.h:905
Unified shell transport interface.
Definition shell.h:818
void(* update)(const struct shell_transport *transport)
Function called in shell thread loop.
Definition shell.h:892
int(* init)(const struct shell_transport *transport, const void *config, shell_transport_handler_t evt_handler, void *context)
Function for initializing the shell transport interface.
Definition shell.h:830
int(* write)(const struct shell_transport *transport, const void *data, size_t length, size_t *cnt)
Function for writing data to the transport interface.
Definition shell.h:869
int(* uninit)(const struct shell_transport *transport)
Function for uninitializing the shell transport interface.
Definition shell.h:842
int(* enable)(const struct shell_transport *transport, bool blocking_tx)
Function for enabling transport in given TX mode.
Definition shell.h:856
int(* read)(const struct shell_transport *transport, void *data, size_t length, size_t *cnt)
Function for reading data from the transport interface.
Definition shell.h:882
Definition shell.h:896
void * ctx
Definition shell.h:898
const struct shell_transport_api * api
Definition shell.h:897
Definition shell_types.h:44
Shell instance internals.
Definition shell.h:1063
struct k_thread * thread
Definition shell.h:1082
LOG_INSTANCE_PTR_DECLARE(log)
enum shell_flag shell_flag
Definition shell.h:1071
const struct shell_log_backend * log_backend
Definition shell.h:1077
struct shell_history * history
Definition shell.h:1069
struct shell_stats * stats
Definition shell.h:1075
const char * name
Definition shell.h:1081
const char * default_prompt
shell default prompt.
Definition shell.h:1064
const struct shell_fprintf * fprintf_ctx
Definition shell.h:1073
struct shell_ctx * ctx
Internal context.
Definition shell.h:1067
const struct shell_transport * iface
Transport interface.
Definition shell.h:1066
k_thread_stack_t * stack
Definition shell.h:1083
Definition sys_getopt.h:16
Misc utilities.
Macros to abstract toolchain specific capabilities.
Definition shell.h:961
atomic_t value
Definition shell.h:962
struct shell_backend_config_flags flags
Definition shell.h:963
Definition shell.h:969
struct shell_backend_ctx_flags flags
Definition shell.h:971
uint32_t value
Definition shell.h:970
Shell command descriptor.
Definition shell.h:102
const struct shell_static_entry * entry
Pointer to array of static commands.
Definition shell.h:107
shell_dynamic_get dynamic_get
Pointer to function returning dynamic commands.
Definition shell.h:104