Zephyr API Documentation 4.4.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
118
120#define SHELL_CMD_FLAG_REMOTE_ROOT BIT(0)
121
123#define SHELL_CMD_FLAG_REMOTE_SUBCMD BIT(1)
124
140const struct device *shell_device_lookup(size_t idx,
141 const char *prefix);
142
159const struct device *shell_device_lookup_all(size_t idx,
160 const char *prefix);
161
177const struct device *shell_device_lookup_non_ready(size_t idx,
178 const char *prefix);
179
190typedef bool (*shell_device_filter_t)(const struct device *dev);
191
205const struct device *shell_device_filter(size_t idx,
206 shell_device_filter_t filter);
207
228const struct device *shell_device_get_binding(const char *name);
229
245const struct device *shell_device_get_binding_all(const char *name);
246
259typedef int (*shell_cmd_handler)(const struct shell *sh,
260 size_t argc, char **argv);
261
275typedef int (*shell_dict_cmd_handler)(const struct shell *sh, size_t argc,
276 char **argv, void *data);
277
278/* When entries are added to the memory section a padding is applied for
279 * the posix architecture with 64bits builds and x86_64 targets. Adding padding to allow handle data
280 * in the memory section as array.
281 */
282#if (defined(CONFIG_ARCH_POSIX) && defined(CONFIG_64BIT)) || defined(CONFIG_X86_64)
283#define Z_SHELL_STATIC_ENTRY_PADDING 24
284#else
285#define Z_SHELL_STATIC_ENTRY_PADDING 0
286#endif
287
288/*
289 * @brief Shell static command descriptor.
290 */
292 const char *syntax;
293 const char *help;
294 const union shell_cmd_entry *subcmd;
297 uint8_t padding[Z_SHELL_STATIC_ENTRY_PADDING];
298};
299
308 /* @cond INTERNAL_HIDDEN */
309 uint32_t magic;
310 /* @endcond */
311 const char *description;
312 const char *usage;
313};
314
318
323#define SHELL_STRUCTURED_HELP_MAGIC 0x86D20BC4
324
328
335static inline bool shell_help_is_structured(const char *help)
336{
337 const uint32_t magic32 = SHELL_STRUCTURED_HELP_MAGIC;
338 const char *magic = (const char *)&magic32;
339
345 return help != NULL && (magic[0] == help[0]) && (magic[1] == help[1])
346 && (magic[2] == help[2]) && (magic[3] == help[3]);
347}
348
349#if defined(CONFIG_SHELL_HELP) || defined(__DOXYGEN__)
373#define SHELL_HELP(_description, _usage) \
374 ((const char *)&(const struct shell_cmd_help){ \
375 .magic = SHELL_STRUCTURED_HELP_MAGIC, \
376 .description = (_description), \
377 .usage = (_usage), \
378 })
379#else
380#define SHELL_HELP(_description, _usage) NULL
381#endif /* CONFIG_SHELL_HELP */
382
398#define SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, \
399 mandatory, optional) \
400 static const struct shell_static_entry UTIL_CAT(_shell_, syntax) = \
401 SHELL_CMD_ARG(syntax, subcmd, help, handler, mandatory, optional); \
402 static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, \
403 UTIL_CAT(shell_cmd_, syntax), shell_root_cmds, \
404 UTIL_CAT(shell_cmd_, syntax) \
405 ) = { \
406 .entry = &UTIL_CAT(_shell_, syntax) \
407 }
408
429#define SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, \
430 mandatory, optional) \
431 COND_CODE_1(\
432 flag, \
433 (\
434 SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, \
435 mandatory, optional) \
436 ), \
437 (\
438 static shell_cmd_handler dummy_##syntax##_handler __unused = \
439 handler;\
440 static const union shell_cmd_entry *dummy_subcmd_##syntax \
441 __unused = subcmd\
442 ) \
443 )
455#define SHELL_CMD_REGISTER(syntax, subcmd, help, handler) \
456 SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, 0, 0)
457
471#define SHELL_COND_CMD_REGISTER(flag, syntax, subcmd, help, handler) \
472 SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, 0, 0)
473
492#define SHELL_STATIC_SUBCMD_SET_CREATE(name, ...) \
493 static const struct shell_static_entry shell_##name[] = { \
494 __VA_ARGS__ \
495 }; \
496 static const union shell_cmd_entry name = { \
497 .entry = shell_##name \
498 }
499
500#define Z_SHELL_UNDERSCORE(x) _##x
501#define Z_SHELL_SUBCMD_NAME(...) \
502 UTIL_CAT(shell_subcmds, MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__))
503#define Z_SHELL_SUBCMD_SECTION_TAG(...) MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__)
504#define Z_SHELL_SUBCMD_SET_SECTION_TAG(x) \
505 Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x)
506#define Z_SHELL_SUBCMD_ADD_SECTION_TAG(x, y) \
507 Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x, y)
508
520
521#define SHELL_SUBCMD_SET_CREATE(_name, _parent) \
522 static const TYPE_SECTION_ITERABLE(struct shell_static_entry, _name, shell_subcmds, \
523 Z_SHELL_SUBCMD_SET_SECTION_TAG(_parent))
524
525
545#define SHELL_SUBCMD_COND_ADD(_flag, _parent, _syntax, _subcmd, _help, _handler, \
546 _mand, _opt) \
547 COND_CODE_1(_flag, \
548 (static const TYPE_SECTION_ITERABLE(struct shell_static_entry, \
549 Z_SHELL_SUBCMD_NAME(__DEBRACKET _parent, _syntax), \
550 shell_subcmds, \
551 Z_SHELL_SUBCMD_ADD_SECTION_TAG(_parent, _syntax)) = \
552 SHELL_EXPR_CMD_ARG(1, _syntax, _subcmd, _help, \
553 _handler, _mand, _opt, 0, 0)\
554 ), \
555 (static shell_cmd_handler dummy_handler_##_syntax __unused = _handler;\
556 static const union shell_cmd_entry dummy_subcmd_##_syntax __unused = { \
557 .entry = (const struct shell_static_entry *)_subcmd\
558 } \
559 ) \
560 )
561
574#define SHELL_SUBCMD_ADD(_parent, _syntax, _subcmd, _help, _handler, _mand, _opt) \
575 SHELL_SUBCMD_COND_ADD(1, _parent, _syntax, _subcmd, _help, _handler, _mand, _opt)
576
581#define SHELL_SUBCMD_SET_END {0}
582
589#define SHELL_DYNAMIC_CMD_CREATE(name, get) \
590 static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, name, \
591 shell_dynamic_subcmds, name) = \
592 { \
593 .dynamic_get = get \
594 }
595
609#define SHELL_CMD_ARG(syntax, subcmd, help, handler, mand, opt) \
610 SHELL_EXPR_CMD_ARG(1, syntax, subcmd, help, handler, mand, opt, 0, 0)
611
631#define SHELL_COND_CMD_ARG(flag, syntax, subcmd, help, handler, mand, opt) \
632 SHELL_EXPR_CMD_ARG(IS_ENABLED(flag), syntax, subcmd, help, \
633 handler, mand, opt, 0, 0)
634
656#define SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, \
657 _mand, _opt, _remote_cmd, _remote_id) \
658 { \
659 .syntax = (_expr) ? (const char *)STRINGIFY(_syntax) : "", \
660 .help = (_expr) ? (const char *)_help : NULL, \
661 .subcmd = (const union shell_cmd_entry *)((_expr) ? \
662 _subcmd : NULL), \
663 .handler = (shell_cmd_handler)((_expr) ? _handler : NULL), \
664 .args = { .mandatory = _mand, .optional = _opt, \
665 .remote_cmd = _remote_cmd, .remote_id = _remote_id } \
666 }
667
676#define SHELL_CMD(_syntax, _subcmd, _help, _handler) \
677 SHELL_CMD_ARG(_syntax, _subcmd, _help, _handler, 0, 0)
678
691#define SHELL_COND_CMD(_flag, _syntax, _subcmd, _help, _handler) \
692 SHELL_COND_CMD_ARG(_flag, _syntax, _subcmd, _help, _handler, 0, 0)
693
707#define SHELL_EXPR_CMD(_expr, _syntax, _subcmd, _help, _handler) \
708 SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, 0, 0, 0, 0)
709
710/* Internal macro used for creating handlers for dictionary commands. */
711#define Z_SHELL_CMD_DICT_HANDLER_CREATE(_data, _handler) \
712static int UTIL_CAT(UTIL_CAT(cmd_dict_, UTIL_CAT(_handler, _)), \
713 GET_ARG_N(1, __DEBRACKET _data))( \
714 const struct shell *sh, size_t argc, char **argv) \
715{ \
716 return _handler(sh, argc, argv, \
717 (void *)GET_ARG_N(2, __DEBRACKET _data)); \
718}
719
720/* Internal macro used for creating dictionary commands. */
721#define SHELL_CMD_DICT_CREATE(_data, _handler) \
722 SHELL_CMD_ARG(GET_ARG_N(1, __DEBRACKET _data), NULL, GET_ARG_N(3, __DEBRACKET _data), \
723 UTIL_CAT(UTIL_CAT(cmd_dict_, UTIL_CAT(_handler, _)), \
724 GET_ARG_N(1, __DEBRACKET _data)), 1, 0)
725
759#define SHELL_SUBCMD_DICT_SET_CREATE(_name, _handler, ...) \
760 FOR_EACH_FIXED_ARG(Z_SHELL_CMD_DICT_HANDLER_CREATE, (), \
761 _handler, __VA_ARGS__) \
762 SHELL_STATIC_SUBCMD_SET_CREATE(_name, \
763 FOR_EACH_FIXED_ARG(SHELL_CMD_DICT_CREATE, (,), _handler, __VA_ARGS__), \
764 SHELL_SUBCMD_SET_END \
765 )
766
767/* @cond INTERNAL_HIDDEN */
768
773enum shell_receive_state {
774 SHELL_RECEIVE_DEFAULT,
775 SHELL_RECEIVE_ESC,
776 SHELL_RECEIVE_ESC_SEQ,
777 SHELL_RECEIVE_TILDE_EXP
778};
779
783enum shell_state {
784 SHELL_STATE_UNINITIALIZED,
785 SHELL_STATE_INITIALIZED,
786 SHELL_STATE_ACTIVE,
787 SHELL_STATE_PANIC_MODE_ACTIVE,
788 SHELL_STATE_PANIC_MODE_INACTIVE
789};
790
792enum shell_transport_evt {
793 SHELL_TRANSPORT_EVT_RX_RDY,
794 SHELL_TRANSPORT_EVT_TX_RDY
795};
796
797enum shell_readline_state {
798 SHELL_READLINE_INACTIVE,
799 SHELL_READLINE_ACTIVE,
800 SHELL_READLINE_DONE,
801 SHELL_READLINE_CANCELED,
802};
803
804/* @endcond */
805
806typedef void (*shell_transport_handler_t)(enum shell_transport_evt evt,
807 void *context);
808
809
810typedef void (*shell_uninit_cb_t)(const struct shell *sh, int res);
811
818typedef void (*shell_bypass_cb_t)(const struct shell *sh,
819 uint8_t *data,
820 size_t len,
821 void *user_data);
822
823struct shell_transport;
824
841 int (*init)(const struct shell_transport *transport,
842 const void *config,
843 shell_transport_handler_t evt_handler,
844 void *context);
845
853 int (*uninit)(const struct shell_transport *transport);
854
867 int (*enable)(const struct shell_transport *transport,
868 bool blocking_tx);
869
880 int (*write)(const struct shell_transport *transport,
881 const void *data, size_t length, size_t *cnt);
882
893 int (*read)(const struct shell_transport *transport,
894 void *data, size_t length, size_t *cnt);
895
903 void (*update)(const struct shell_transport *transport);
904
905};
906
909 void *ctx;
910};
911
918
919#ifdef CONFIG_SHELL_STATS
920#define Z_SHELL_STATS_DEFINE(_name) static struct shell_stats _name##_stats
921#define Z_SHELL_STATS_PTR(_name) (&(_name##_stats))
922#else
923#define Z_SHELL_STATS_DEFINE(_name)
924#define Z_SHELL_STATS_PTR(_name) NULL
925#endif /* CONFIG_SHELL_STATS */
926
939
940BUILD_ASSERT((sizeof(struct shell_backend_config_flags) == sizeof(uint32_t)),
941 "Structure must fit in 4 bytes");
942
946#define SHELL_DEFAULT_BACKEND_CONFIG_FLAGS \
947{ \
948 .insert_mode = 0, \
949 .echo = 1, \
950 .obscure = IS_ENABLED(CONFIG_SHELL_START_OBSCURED), \
951 .mode_delete = 1, \
952 .use_colors = 1, \
953 .use_vt100 = 1, \
954};
955
967
968BUILD_ASSERT((sizeof(struct shell_backend_ctx_flags) == sizeof(uint32_t)),
969 "Structure must fit in 4 bytes");
970
978
986
993
997struct shell_ctx {
998#if defined(CONFIG_SHELL_PROMPT_CHANGE) && CONFIG_SHELL_PROMPT_CHANGE
1000#else
1001 const char *prompt;
1002#endif
1003
1004 enum shell_state state;
1005 enum shell_receive_state receive_state;
1006
1008 enum shell_readline_state readline_state;
1009
1012
1015
1018
1023
1026
1029
1032
1033#if defined CONFIG_SHELL_GETOPT
1035 struct sys_getopt_state getopt;
1036#endif
1037
1040
1043
1046
1049
1052
1053 volatile union shell_backend_cfg cfg;
1054 volatile union shell_backend_ctx ctx;
1055
1057
1061};
1062
1063extern const struct log_backend_api log_backend_shell_api;
1064
1072
1076struct shell {
1077 const char *default_prompt;
1078
1079 const struct shell_transport *iface;
1080 struct shell_ctx *ctx;
1081
1083
1085
1087
1089
1091
1093
1094 const char *name;
1097};
1098
1099extern void z_shell_print_stream(const void *user_ctx, const char *data,
1100 size_t data_len);
1101
1114#define Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _out_buf, _log_backend, _shell_flag) \
1115 static const struct shell _name; \
1116 static struct shell_ctx UTIL_CAT(_name, _ctx); \
1117 Z_SHELL_HISTORY_DEFINE(_name##_history, CONFIG_SHELL_HISTORY_BUFFER); \
1118 Z_SHELL_FPRINTF_DEFINE(_name##_fprintf, &_name, _out_buf, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
1119 IS_ENABLED(CONFIG_SHELL_PRINTF_AUTOFLUSH), z_shell_print_stream); \
1120 LOG_INSTANCE_REGISTER(shell, _name, CONFIG_SHELL_LOG_LEVEL); \
1121 Z_SHELL_STATS_DEFINE(_name); \
1122 static K_KERNEL_STACK_DEFINE(_name##_stack, CONFIG_SHELL_STACK_SIZE); \
1123 static struct k_thread _name##_thread; \
1124 static const STRUCT_SECTION_ITERABLE(shell, _name) = { \
1125 .default_prompt = _prompt, \
1126 .iface = _transport_iface, \
1127 .ctx = &UTIL_CAT(_name, _ctx), \
1128 .history = IS_ENABLED(CONFIG_SHELL_HISTORY) ? &_name##_history : NULL, \
1129 .shell_flag = _shell_flag, \
1130 .fprintf_ctx = &_name##_fprintf, \
1131 .stats = Z_SHELL_STATS_PTR(_name), \
1132 .log_backend = _log_backend, \
1133 LOG_INSTANCE_PTR_INIT(log, shell, _name).name = \
1134 STRINGIFY(_name), .thread = &_name##_thread, .stack = _name##_stack}
1135
1149#define SHELL_DEFINE(_name, _prompt, _transport_iface, _log_queue_size, _log_timeout, _shell_flag) \
1150 static uint8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \
1151 Z_SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
1152 _log_queue_size, _log_timeout); \
1153 Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _name##_out_buffer, \
1154 Z_SHELL_LOG_BACKEND_PTR(_name), _shell_flag)
1155
1169int shell_init(const struct shell *sh, const void *transport_config,
1170 struct shell_backend_config_flags cfg_flags,
1171 bool log_backend, uint32_t init_log_level);
1172
1179void shell_uninit(const struct shell *sh, shell_uninit_cb_t cb);
1180
1188int shell_start(const struct shell *sh);
1189
1197int shell_stop(const struct shell *sh);
1198
1202#define SHELL_NORMAL SHELL_VT100_COLOR_DEFAULT
1203
1207#define SHELL_INFO SHELL_VT100_COLOR_GREEN
1208
1212#define SHELL_OPTION SHELL_VT100_COLOR_CYAN
1213
1217#define SHELL_WARNING SHELL_VT100_COLOR_YELLOW
1218
1222#define SHELL_ERROR SHELL_VT100_COLOR_RED
1223
1224#ifdef CONFIG_SHELL_REMOTE_CLI
1226#endif
1227
1239void __printf_like(3, 4) shell_fprintf_impl(const struct shell *sh, enum shell_vt100_color color,
1240 const char *fmt, ...);
1241
1242#define shell_fprintf(sh, color, fmt, ...) \
1243 COND_CODE_1(IS_ENABLED(CONFIG_SHELL_REMOTE_CLI), \
1244 (SHELL_REMOTE_CLI_FPRINTF(sh, color, fmt, ##__VA_ARGS__)), \
1245 (shell_fprintf_impl(sh, color, fmt, ##__VA_ARGS__)))
1246
1259void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
1260 const char *fmt, va_list args);
1261
1272void shell_cbpprintf(const struct shell *sh, enum shell_vt100_color color, void *package);
1273
1289void shell_hexdump_line(const struct shell *sh, unsigned int offset,
1290 const uint8_t *data, size_t len);
1291
1299void shell_hexdump(const struct shell *sh, const uint8_t *data, size_t len);
1300
1310#define shell_info(_sh, _ft, ...) shell_fprintf(_sh, SHELL_INFO, _ft "\n", ##__VA_ARGS__)
1311
1321#define shell_fprintf_info(_sh, _ft, ...) shell_fprintf(_sh, SHELL_INFO, _ft, ##__VA_ARGS__)
1322
1332#define shell_print(_sh, _ft, ...) shell_fprintf_normal(_sh, _ft "\n", ##__VA_ARGS__)
1333
1343#define shell_fprintf_normal(_sh, _ft, ...) shell_fprintf(_sh, SHELL_NORMAL, _ft, ##__VA_ARGS__)
1344
1354#define shell_warn(_sh, _ft, ...) shell_fprintf_warn(_sh, _ft "\n", ##__VA_ARGS__)
1355
1365#define shell_fprintf_warn(_sh, _ft, ...) shell_fprintf(_sh, SHELL_WARNING, _ft, ##__VA_ARGS__)
1366
1376#define shell_error(_sh, _ft, ...) shell_fprintf_error(_sh, _ft "\n", ##__VA_ARGS__)
1377
1387#define shell_fprintf_error(_sh, _ft, ...) shell_fprintf(_sh, SHELL_ERROR, _ft, ##__VA_ARGS__)
1388
1395void shell_process(const struct shell *sh);
1396
1406int shell_prompt_change(const struct shell *sh, const char *prompt);
1407
1416#ifdef CONFIG_SHELL_HELP
1417void shell_help(const struct shell *sh);
1418#else
1419static inline void shell_help(const struct shell *sh)
1420{
1421}
1422#endif /* CONFIG_SHELL_HELP */
1423
1425#define SHELL_CMD_HELP_PRINTED (1)
1426
1444int shell_execute_cmd(const struct shell *sh, const char *cmd);
1445
1457int shell_set_root_cmd(const char *cmd);
1458
1468void shell_set_bypass(const struct shell *sh, shell_bypass_cb_t bypass, void *user_data);
1469
1477bool shell_ready(const struct shell *sh);
1478
1489int shell_insert_mode_set(const struct shell *sh, bool val);
1490
1502int shell_use_colors_set(const struct shell *sh, bool val);
1503
1514int shell_use_vt100_set(const struct shell *sh, bool val);
1515
1526int shell_echo_set(const struct shell *sh, bool val);
1527
1539int shell_obscure_set(const struct shell *sh, bool obscure);
1540
1552int shell_mode_delete_set(const struct shell *sh, bool val);
1553
1561int shell_get_return_value(const struct shell *sh);
1562
1584int shell_readline(const struct shell *sh, uint8_t *buf, size_t len, k_timeout_t timeout);
1585
1589
1590#ifdef __cplusplus
1591}
1592#endif
1593
1594#ifdef CONFIG_SHELL_CUSTOM_HEADER
1595/* This include must always be at the end of shell.h */
1596#include <zephyr_custom_shell.h>
1597#endif
1598
1599#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:335
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:810
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:275
#define shell_fprintf(sh, color, fmt,...)
Definition shell.h:1242
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:806
int shell_mode_delete_set(const struct shell *sh, bool val)
Allow application to control whether the delete key backspaces or deletes.
int(* shell_cmd_handler)(const struct shell *sh, size_t argc, char **argv)
Shell command handler prototype.
Definition shell.h:259
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:1068
const struct device * shell_device_lookup(size_t idx, const char *prefix)
Get by index a device that matches .
shell_signal
Definition shell.h:987
void shell_cbpprintf(const struct shell *sh, enum shell_vt100_color color, void *package)
Function which formats cbprintf package and streams it to the shell.
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.
static void shell_help(const struct shell *sh)
Prints the current command help.
Definition shell.h:1419
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:190
int shell_execute_cmd(const struct shell *sh, const char *cmd)
Execute command.
void(* shell_bypass_cb_t)(const struct shell *sh, uint8_t *data, size_t len, void *user_data)
Bypass callback.
Definition shell.h:818
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:1069
@ SHELL_FLAG_OLF_CRLF
Map LF to CRLF on output.
Definition shell.h:1070
@ SHELL_SIGNAL_TXDONE
Definition shell.h:991
@ SHELL_SIGNAL_RXRDY
Definition shell.h:988
@ SHELL_SIGNAL_LOG_MSG
Definition shell.h:989
@ SHELL_SIGNAL_KILL
Definition shell.h:990
#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 history.
Shell backend.
APIs for the remote shell client.
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:2651
Semaphore structure.
Definition kernel.h:3663
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:930
uint32_t use_vt100
Controls VT100 commands usage in shell.
Definition shell.h:936
uint32_t mode_delete
Operation mode of backspace key.
Definition shell.h:934
uint32_t echo
Controls shell echo.
Definition shell.h:932
uint32_t insert_mode
Controls insert mode for text introduction.
Definition shell.h:931
uint32_t obscure
If echo on, print asterisk instead.
Definition shell.h:933
uint32_t use_colors
Controls colored syntax.
Definition shell.h:935
Definition shell.h:956
uint32_t print_noinit
Print request from not initialized shell.
Definition shell.h:962
uint32_t sync_mode
Shell in synchronous mode.
Definition shell.h:963
uint32_t tx_rdy
Definition shell.h:959
uint32_t handle_log
Shell is handling logger backend.
Definition shell.h:964
uint32_t processing
Shell is executing process function.
Definition shell.h:958
uint32_t last_nl
Last received new line character.
Definition shell.h:957
uint32_t history_exit
Request to exit history mode.
Definition shell.h:960
uint32_t cmd_ctx
Shell is executing command.
Definition shell.h:961
Shell structured help descriptor.
Definition shell.h:307
const char * usage
Command usage string.
Definition shell.h:312
const char * description
Command description.
Definition shell.h:311
Shell instance context.
Definition shell.h:997
const struct shell_static_entry * selected_cmd
New root command.
Definition shell.h:1014
shell_uninit_cb_t uninit_cb
Callback called from shell thread context when unitialization is completed just before aborting shell...
Definition shell.h:1022
struct k_event signal_event
Definition shell.h:1056
void * bypass_user_data
When bypass is set, this user data pointer is passed to the callback.
Definition shell.h:1028
struct shell_vt100_ctx vt100_ctx
VT100 color and cursor position, terminal width.
Definition shell.h:1017
const char * prompt
Definition shell.h:1001
k_tid_t tid
Definition shell.h:1059
char temp_buff[0]
Command temporary buffer.
Definition shell.h:1048
char cmd_buff[0]
Command input buffer.
Definition shell.h:1045
struct shell_static_entry active_cmd
Currently executed command.
Definition shell.h:1011
uint32_t log_level
Definition shell.h:1031
volatile union shell_backend_cfg cfg
Definition shell.h:1053
uint16_t cmd_tmp_buff_len
Command length in tmp buffer.
Definition shell.h:1041
enum shell_state state
Internal module state.
Definition shell.h:1004
uint16_t cmd_tmp_buff_pos
Command buffer cursor position in tmp buffer.
Definition shell.h:1042
shell_bypass_cb_t bypass
When bypass is set, all incoming data is passed to the callback.
Definition shell.h:1025
uint16_t cmd_buff_len
Command length.
Definition shell.h:1038
uint16_t cmd_buff_pos
Command buffer cursor position.
Definition shell.h:1039
int ret_val
Definition shell.h:1060
char printf_buff[0]
Printf buffer size.
Definition shell.h:1051
enum shell_receive_state receive_state
Escape sequence indicator.
Definition shell.h:1005
volatile union shell_backend_ctx ctx
Definition shell.h:1054
struct k_sem lock_sem
Definition shell.h:1058
enum shell_readline_state readline_state
Field tracking the readline state for user input.
Definition shell.h:1008
Definition shell_history.h:27
Shell log backend instance structure (RO data).
Definition shell_log_backend.h:42
Definition shell.h:112
uint16_t remote_id
Remote connection id; valid only if remote_cmd is non-zero.
Definition shell.h:116
uint16_t remote_cmd
Remote shell command type; non-zero for remote shell.
Definition shell.h:115
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:291
const union shell_cmd_entry * subcmd
Pointer to subcommand.
Definition shell.h:294
uint8_t padding[0]
Definition shell.h:297
shell_cmd_handler handler
Command handler.
Definition shell.h:295
struct shell_static_args args
Command arguments.
Definition shell.h:296
const char * help
Command help string.
Definition shell.h:293
const char * syntax
Command syntax strings.
Definition shell.h:292
Shell statistics structure.
Definition shell.h:915
atomic_t log_lost_cnt
Lost log counter.
Definition shell.h:916
Unified shell transport interface.
Definition shell.h:829
void(* update)(const struct shell_transport *transport)
Function called in shell thread loop.
Definition shell.h:903
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:841
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:880
int(* uninit)(const struct shell_transport *transport)
Function for uninitializing the shell transport interface.
Definition shell.h:853
int(* enable)(const struct shell_transport *transport, bool blocking_tx)
Function for enabling transport in given TX mode.
Definition shell.h:867
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:893
Definition shell.h:907
void * ctx
Definition shell.h:909
const struct shell_transport_api * api
Definition shell.h:908
Definition shell_types.h:44
Shell instance internals.
Definition shell.h:1076
struct k_thread * thread
Definition shell.h:1095
LOG_INSTANCE_PTR_DECLARE(log)
enum shell_flag shell_flag
Definition shell.h:1084
const struct shell_log_backend * log_backend
Definition shell.h:1090
struct shell_history * history
Definition shell.h:1082
struct shell_stats * stats
Definition shell.h:1088
const char * name
Definition shell.h:1094
const char * default_prompt
shell default prompt.
Definition shell.h:1077
const struct shell_fprintf * fprintf_ctx
Definition shell.h:1086
struct shell_ctx * ctx
Internal context.
Definition shell.h:1080
const struct shell_transport * iface
Transport interface.
Definition shell.h:1079
k_thread_stack_t * stack
Definition shell.h:1096
Definition sys_getopt.h:16
Misc utilities.
Macros to abstract toolchain specific capabilities.
Definition shell.h:974
atomic_t value
Definition shell.h:975
struct shell_backend_config_flags flags
Definition shell.h:976
Definition shell.h:982
struct shell_backend_ctx_flags flags
Definition shell.h:984
uint32_t value
Definition shell.h:983
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