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
12
13#ifndef ZEPHYR_INCLUDE_SHELL_SHELL_H_
14#define ZEPHYR_INCLUDE_SHELL_SHELL_H_
15
16#include <zephyr/kernel.h>
23#include <zephyr/logging/log.h>
25#include <zephyr/sys/util.h>
26#include <zephyr/toolchain.h>
27
28#if defined CONFIG_SHELL_GETOPT
30#endif
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
37#ifndef CONFIG_SHELL_PROMPT_BUFF_SIZE
38#define CONFIG_SHELL_PROMPT_BUFF_SIZE 0
39#endif
40
41#ifndef CONFIG_SHELL_CMD_BUFF_SIZE
42#define CONFIG_SHELL_CMD_BUFF_SIZE 0
43#endif
44
45#ifndef CONFIG_SHELL_PRINTF_BUFF_SIZE
46#define CONFIG_SHELL_PRINTF_BUFF_SIZE 0
47#endif
48
49#ifndef CONFIG_SHELL_HISTORY_BUFFER
50#define CONFIG_SHELL_HISTORY_BUFFER 0
51#endif
52
53#define Z_SHELL_CMD_ROOT_LVL (0u)
54
55#define SHELL_HEXDUMP_BYTES_IN_LINE 16
57
65
77#define SHELL_OPT_ARG_RAW (0xFE)
78
82#define SHELL_OPT_ARG_CHECK_SKIP (0xFF)
83
88#define SHELL_OPT_ARG_MAX (0xFD)
89
91
103typedef void (*shell_dynamic_get)(size_t idx,
104 struct shell_static_entry *entry);
105
116
117struct shell;
118
126
128#define SHELL_CMD_FLAG_REMOTE_ROOT BIT(0)
129
131#define SHELL_CMD_FLAG_REMOTE_SUBCMD BIT(1)
132
148const struct device *shell_device_lookup(size_t idx,
149 const char *prefix);
150
167const struct device *shell_device_lookup_all(size_t idx,
168 const char *prefix);
169
185const struct device *shell_device_lookup_non_ready(size_t idx,
186 const char *prefix);
187
198typedef bool (*shell_device_filter_t)(const struct device *dev);
199
213const struct device *shell_device_filter(size_t idx,
214 shell_device_filter_t filter);
215
236const struct device *shell_device_get_binding(const char *name);
237
253const struct device *shell_device_get_binding_all(const char *name);
254
267typedef int (*shell_cmd_handler)(const struct shell *sh,
268 size_t argc, char **argv);
269
283typedef int (*shell_dict_cmd_handler)(const struct shell *sh, size_t argc,
284 char **argv, void *data);
285
286/* When entries are added to the memory section a padding is applied for
287 * the posix architecture with 64bits builds and x86_64 targets. Adding padding to allow handle data
288 * in the memory section as array.
289 */
290#if (defined(CONFIG_ARCH_POSIX) && defined(CONFIG_64BIT)) || defined(CONFIG_X86_64)
291#define Z_SHELL_STATIC_ENTRY_PADDING 24
292#else
293#define Z_SHELL_STATIC_ENTRY_PADDING 0
294#endif
295
300 const char *syntax;
301 const char *help;
302 const union shell_cmd_entry *subcmd;
306 uint8_t padding[Z_SHELL_STATIC_ENTRY_PADDING];
308};
309
319 uint32_t magic;
321 const char *description;
322 const char *usage;
323};
324
328
333#define SHELL_STRUCTURED_HELP_MAGIC 0x86D20BC4
334
338
345static inline bool shell_help_is_structured(const char *help)
346{
347 const uint32_t magic32 = SHELL_STRUCTURED_HELP_MAGIC;
348 const char *magic = (const char *)&magic32;
349
355 return help != NULL && (magic[0] == help[0]) && (magic[1] == help[1])
356 && (magic[2] == help[2]) && (magic[3] == help[3]);
357}
358
359#if defined(CONFIG_SHELL_HELP) || defined(__DOXYGEN__)
383#define SHELL_HELP(_description, _usage) \
384 ((const char *)&(const struct shell_cmd_help){ \
385 .magic = SHELL_STRUCTURED_HELP_MAGIC, \
386 .description = (_description), \
387 .usage = (_usage), \
388 })
389#else
390#define SHELL_HELP(_description, _usage) NULL
391#endif /* CONFIG_SHELL_HELP */
392
408#define SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, \
409 mandatory, optional) \
410 static const struct shell_static_entry UTIL_CAT(_shell_, syntax) = \
411 SHELL_CMD_ARG(syntax, subcmd, help, handler, mandatory, optional); \
412 static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, \
413 UTIL_CAT(shell_cmd_, syntax), shell_root_cmds, \
414 UTIL_CAT(shell_cmd_, syntax) \
415 ) = { \
416 .entry = &UTIL_CAT(_shell_, syntax) \
417 }
418
439#define SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, \
440 mandatory, optional) \
441 COND_CODE_1(\
442 flag, \
443 (\
444 SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, \
445 mandatory, optional) \
446 ), \
447 (\
448 static shell_cmd_handler dummy_##syntax##_handler __unused = \
449 handler;\
450 static const union shell_cmd_entry *dummy_subcmd_##syntax \
451 __unused = subcmd\
452 ) \
453 )
465#define SHELL_CMD_REGISTER(syntax, subcmd, help, handler) \
466 SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, 0, 0)
467
481#define SHELL_COND_CMD_REGISTER(flag, syntax, subcmd, help, handler) \
482 SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, 0, 0)
483
502#define SHELL_STATIC_SUBCMD_SET_CREATE(name, ...) \
503 static const struct shell_static_entry shell_##name[] = { \
504 __VA_ARGS__ \
505 }; \
506 static const union shell_cmd_entry name = { \
507 .entry = shell_##name \
508 }
509
510#define Z_SHELL_UNDERSCORE(x) _##x
511#define Z_SHELL_SUBCMD_NAME(...) \
512 UTIL_CAT(shell_subcmds, MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__))
513#define Z_SHELL_SUBCMD_SECTION_TAG(...) MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__)
514#define Z_SHELL_SUBCMD_SET_SECTION_TAG(x) \
515 Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x)
516#define Z_SHELL_SUBCMD_ADD_SECTION_TAG(x, y) \
517 Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x, y)
518
530
531#define SHELL_SUBCMD_SET_CREATE(_name, _parent) \
532 static const TYPE_SECTION_ITERABLE(struct shell_static_entry, _name, shell_subcmds, \
533 Z_SHELL_SUBCMD_SET_SECTION_TAG(_parent))
534
535
555#define SHELL_SUBCMD_COND_ADD(_flag, _parent, _syntax, _subcmd, _help, _handler, \
556 _mand, _opt) \
557 COND_CODE_1(_flag, \
558 (static const TYPE_SECTION_ITERABLE(struct shell_static_entry, \
559 Z_SHELL_SUBCMD_NAME(__DEBRACKET _parent, _syntax), \
560 shell_subcmds, \
561 Z_SHELL_SUBCMD_ADD_SECTION_TAG(_parent, _syntax)) = \
562 SHELL_EXPR_CMD_ARG(1, _syntax, _subcmd, _help, \
563 _handler, _mand, _opt, 0, 0)\
564 ), \
565 (static shell_cmd_handler dummy_handler_##_syntax __unused = _handler;\
566 static const union shell_cmd_entry dummy_subcmd_##_syntax __unused = { \
567 .entry = (const struct shell_static_entry *)_subcmd\
568 } \
569 ) \
570 )
571
584#define SHELL_SUBCMD_ADD(_parent, _syntax, _subcmd, _help, _handler, _mand, _opt) \
585 SHELL_SUBCMD_COND_ADD(1, _parent, _syntax, _subcmd, _help, _handler, _mand, _opt)
586
591#define SHELL_SUBCMD_SET_END {0}
592
599#define SHELL_DYNAMIC_CMD_CREATE(name, get) \
600 static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, name, \
601 shell_dynamic_subcmds, name) = \
602 { \
603 .dynamic_get = get \
604 }
605
619#define SHELL_CMD_ARG(syntax, subcmd, help, handler, mand, opt) \
620 SHELL_EXPR_CMD_ARG(1, syntax, subcmd, help, handler, mand, opt, 0, 0)
621
641#define SHELL_COND_CMD_ARG(flag, syntax, subcmd, help, handler, mand, opt) \
642 SHELL_EXPR_CMD_ARG(IS_ENABLED(flag), syntax, subcmd, help, \
643 handler, mand, opt, 0, 0)
644
666#define SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, \
667 _mand, _opt, _remote_cmd, _remote_id) \
668 { \
669 .syntax = (_expr) ? (const char *)STRINGIFY(_syntax) : "", \
670 .help = (_expr) ? (const char *)_help : NULL, \
671 .subcmd = (const union shell_cmd_entry *)((_expr) ? \
672 _subcmd : NULL), \
673 .handler = (shell_cmd_handler)((_expr) ? _handler : NULL), \
674 .args = { .mandatory = _mand, .optional = _opt, \
675 .remote_cmd = _remote_cmd, .remote_id = _remote_id } \
676 }
677
686#define SHELL_CMD(_syntax, _subcmd, _help, _handler) \
687 SHELL_CMD_ARG(_syntax, _subcmd, _help, _handler, 0, 0)
688
701#define SHELL_COND_CMD(_flag, _syntax, _subcmd, _help, _handler) \
702 SHELL_COND_CMD_ARG(_flag, _syntax, _subcmd, _help, _handler, 0, 0)
703
717#define SHELL_EXPR_CMD(_expr, _syntax, _subcmd, _help, _handler) \
718 SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, 0, 0, 0, 0)
719
721
722/* Internal macro used for creating handlers for dictionary commands. */
723#define Z_SHELL_CMD_DICT_HANDLER_CREATE(_data, _handler) \
724static int UTIL_CAT(UTIL_CAT(cmd_dict_, UTIL_CAT(_handler, _)), \
725 GET_ARG_N(1, __DEBRACKET _data))( \
726 const struct shell *sh, size_t argc, char **argv) \
727{ \
728 return _handler(sh, argc, argv, \
729 (void *)GET_ARG_N(2, __DEBRACKET _data)); \
730}
731
732/* Internal macro used for creating dictionary commands. */
733#define SHELL_CMD_DICT_CREATE(_data, _handler) \
734 SHELL_CMD_ARG(GET_ARG_N(1, __DEBRACKET _data), NULL, GET_ARG_N(3, __DEBRACKET _data), \
735 UTIL_CAT(UTIL_CAT(cmd_dict_, UTIL_CAT(_handler, _)), \
736 GET_ARG_N(1, __DEBRACKET _data)), 1, 0)
737
739
773#define SHELL_SUBCMD_DICT_SET_CREATE(_name, _handler, ...) \
774 FOR_EACH_FIXED_ARG(Z_SHELL_CMD_DICT_HANDLER_CREATE, (), \
775 _handler, __VA_ARGS__) \
776 SHELL_STATIC_SUBCMD_SET_CREATE(_name, \
777 FOR_EACH_FIXED_ARG(SHELL_CMD_DICT_CREATE, (,), _handler, __VA_ARGS__), \
778 SHELL_SUBCMD_SET_END \
779 )
780
782
787enum shell_receive_state {
788 SHELL_RECEIVE_DEFAULT,
789 SHELL_RECEIVE_ESC,
790 SHELL_RECEIVE_ESC_SEQ,
791 SHELL_RECEIVE_TILDE_EXP
792};
793
797enum shell_state {
798 SHELL_STATE_UNINITIALIZED,
799 SHELL_STATE_INITIALIZED,
800 SHELL_STATE_ACTIVE,
801 SHELL_STATE_PANIC_MODE_ACTIVE,
802 SHELL_STATE_PANIC_MODE_INACTIVE
803};
804
806enum shell_transport_evt {
807 SHELL_TRANSPORT_EVT_RX_RDY,
808 SHELL_TRANSPORT_EVT_TX_RDY
809};
810
811enum shell_readline_state {
812 SHELL_READLINE_INACTIVE,
813 SHELL_READLINE_ACTIVE,
814 SHELL_READLINE_DONE,
815 SHELL_READLINE_CANCELED,
816};
817
819
831typedef void (*shell_transport_handler_t)(enum shell_transport_evt evt,
832 void *context);
833
844typedef void (*shell_uninit_cb_t)(const struct shell *sh, int res);
845
852typedef void (*shell_bypass_cb_t)(const struct shell *sh,
853 uint8_t *data,
854 size_t len,
855 void *user_data);
856
857struct shell_transport;
858
875 int (*init)(const struct shell_transport *transport,
876 const void *config,
877 shell_transport_handler_t evt_handler,
878 void *context);
879
887 int (*uninit)(const struct shell_transport *transport);
888
901 int (*enable)(const struct shell_transport *transport,
902 bool blocking_tx);
903
914 int (*write)(const struct shell_transport *transport,
915 const void *data, size_t length, size_t *cnt);
916
927 int (*read)(const struct shell_transport *transport,
928 void *data, size_t length, size_t *cnt);
929
937 void (*update)(const struct shell_transport *transport);
938
939};
940
949 const struct shell_transport_api *api;
950 void *ctx;
951};
952
954
958struct shell_stats {
959 atomic_t log_lost_cnt;
960};
961
962#ifdef CONFIG_SHELL_STATS
963#define Z_SHELL_STATS_DEFINE(_name) static struct shell_stats _name##_stats
964#define Z_SHELL_STATS_PTR(_name) (&(_name##_stats))
965#else
966#define Z_SHELL_STATS_DEFINE(_name)
967#define Z_SHELL_STATS_PTR(_name) NULL
968#endif /* CONFIG_SHELL_STATS */
969
973struct shell_backend_config_flags {
974 uint32_t insert_mode :1;
975 uint32_t echo :1;
976 uint32_t obscure :1;
977 uint32_t mode_delete :1;
978 uint32_t use_colors :1;
979 uint32_t use_vt100 :1;
980 uint32_t _reserved :26;
981};
982
983BUILD_ASSERT((sizeof(struct shell_backend_config_flags) == sizeof(uint32_t)),
984 "Structure must fit in 4 bytes");
985
989#define SHELL_DEFAULT_BACKEND_CONFIG_FLAGS \
990{ \
991 .insert_mode = 0, \
992 .echo = 1, \
993 .obscure = IS_ENABLED(CONFIG_SHELL_START_OBSCURED), \
994 .mode_delete = 1, \
995 .use_colors = 1, \
996 .use_vt100 = 1, \
997};
998
999struct shell_backend_ctx_flags {
1000 uint32_t last_nl :8;
1001 uint32_t processing :1;
1002 uint32_t tx_rdy :1;
1003 uint32_t history_exit :1;
1004 uint32_t cmd_ctx :1;
1005 uint32_t print_noinit :1;
1006 uint32_t sync_mode :1;
1007 uint32_t handle_log :1;
1008 uint32_t _reserved :17;
1009};
1010
1011BUILD_ASSERT((sizeof(struct shell_backend_ctx_flags) == sizeof(uint32_t)),
1012 "Structure must fit in 4 bytes");
1013
1017union shell_backend_cfg {
1018 atomic_t value;
1019 struct shell_backend_config_flags flags;
1020};
1021
1025union shell_backend_ctx {
1026 uint32_t value;
1027 struct shell_backend_ctx_flags flags;
1028};
1029
1030enum shell_signal {
1031 SHELL_SIGNAL_RXRDY = BIT(0),
1032 SHELL_SIGNAL_LOG_MSG = BIT(1),
1033 SHELL_SIGNAL_KILL = BIT(2),
1034 SHELL_SIGNAL_TXDONE = BIT(3),
1035};
1036
1038
1044#if defined(CONFIG_SHELL_PROMPT_CHANGE) && CONFIG_SHELL_PROMPT_CHANGE
1045 char prompt[CONFIG_SHELL_PROMPT_BUFF_SIZE];
1046#else
1047 const char *prompt;
1048#endif
1049
1050 enum shell_state state;
1051 enum shell_receive_state receive_state;
1052
1054 enum shell_readline_state readline_state;
1055
1057 const char *readline_prompt;
1058
1060 struct shell_static_entry active_cmd;
1061
1063 const struct shell_static_entry *selected_cmd;
1064
1066 struct shell_vt100_ctx vt100_ctx;
1067
1071 shell_uninit_cb_t uninit_cb;
1072
1074 shell_bypass_cb_t bypass;
1075
1077 void *bypass_user_data;
1078
1080 uint32_t log_level;
1081
1082#if defined CONFIG_SHELL_GETOPT
1084 struct sys_getopt_state getopt;
1085#endif
1086
1087 uint16_t cmd_buff_len;
1088 uint16_t cmd_buff_pos;
1089
1090 uint16_t cmd_tmp_buff_len;
1091 uint16_t cmd_tmp_buff_pos;
1092
1094 char cmd_buff[CONFIG_SHELL_CMD_BUFF_SIZE];
1095
1097 char temp_buff[CONFIG_SHELL_CMD_BUFF_SIZE];
1098
1100 char printf_buff[CONFIG_SHELL_PRINTF_BUFF_SIZE];
1101
1102 volatile union shell_backend_cfg cfg;
1103 volatile union shell_backend_ctx ctx;
1104
1105 struct k_event signal_event;
1106
1107 struct k_sem lock_sem;
1108 k_tid_t tid;
1109 int ret_val;
1111};
1112
1114extern const struct log_backend_api log_backend_shell_api;
1116
1124
1128struct shell {
1130 const char *default_prompt;
1131
1132 const struct shell_transport *iface;
1133 struct shell_ctx *ctx;
1134
1135 struct shell_history *history;
1136
1137 const enum shell_flag shell_flag;
1138
1139 const struct shell_fprintf *fprintf_ctx;
1140
1141 struct shell_stats *stats;
1142
1143 const struct shell_log_backend *log_backend;
1144
1146
1147 const char *name;
1148 struct k_thread *thread;
1149 k_thread_stack_t *stack;
1151};
1152
1153extern void z_shell_print_stream(const void *user_ctx, const char *data,
1154 size_t data_len);
1155
1168#define Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _out_buf, _log_backend, _shell_flag) \
1169 static const struct shell _name; \
1170 static struct shell_ctx UTIL_CAT(_name, _ctx); \
1171 Z_SHELL_HISTORY_DEFINE(_name##_history, CONFIG_SHELL_HISTORY_BUFFER); \
1172 Z_SHELL_FPRINTF_DEFINE(_name##_fprintf, &_name, _out_buf, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
1173 IS_ENABLED(CONFIG_SHELL_PRINTF_AUTOFLUSH), z_shell_print_stream); \
1174 LOG_INSTANCE_REGISTER(shell, _name, CONFIG_SHELL_LOG_LEVEL); \
1175 Z_SHELL_STATS_DEFINE(_name); \
1176 static K_KERNEL_STACK_DEFINE(_name##_stack, CONFIG_SHELL_STACK_SIZE); \
1177 static struct k_thread _name##_thread; \
1178 static const STRUCT_SECTION_ITERABLE(shell, _name) = { \
1179 .default_prompt = _prompt, \
1180 .iface = _transport_iface, \
1181 .ctx = &UTIL_CAT(_name, _ctx), \
1182 .history = IS_ENABLED(CONFIG_SHELL_HISTORY) ? &_name##_history : NULL, \
1183 .shell_flag = _shell_flag, \
1184 .fprintf_ctx = &_name##_fprintf, \
1185 .stats = Z_SHELL_STATS_PTR(_name), \
1186 .log_backend = _log_backend, \
1187 LOG_INSTANCE_PTR_INIT(log, shell, _name).name = \
1188 STRINGIFY(_name), .thread = &_name##_thread, .stack = _name##_stack}
1189
1203#define SHELL_DEFINE(_name, _prompt, _transport_iface, _log_queue_size, _log_timeout, _shell_flag) \
1204 static uint8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \
1205 Z_SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
1206 _log_queue_size, _log_timeout); \
1207 Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _name##_out_buffer, \
1208 Z_SHELL_LOG_BACKEND_PTR(_name), _shell_flag)
1209
1223int shell_init(const struct shell *sh, const void *transport_config,
1224 struct shell_backend_config_flags cfg_flags,
1225 bool log_backend, uint32_t init_log_level);
1226
1233void shell_uninit(const struct shell *sh, shell_uninit_cb_t cb);
1234
1242int shell_start(const struct shell *sh);
1243
1251int shell_stop(const struct shell *sh);
1252
1256#define SHELL_NORMAL SHELL_VT100_COLOR_DEFAULT
1257
1261#define SHELL_INFO SHELL_VT100_COLOR_GREEN
1262
1266#define SHELL_OPTION SHELL_VT100_COLOR_CYAN
1267
1271#define SHELL_WARNING SHELL_VT100_COLOR_YELLOW
1272
1276#define SHELL_ERROR SHELL_VT100_COLOR_RED
1277
1278#ifdef CONFIG_SHELL_REMOTE_CLI
1280#endif
1281
1283void __printf_like(3, 4) shell_fprintf_impl(const struct shell *sh, enum shell_vt100_color color,
1284 const char *fmt, ...);
1286
1299#define shell_fprintf(sh, color, fmt, ...) \
1300 COND_CODE_1(IS_ENABLED(CONFIG_SHELL_REMOTE_CLI), \
1301 (SHELL_REMOTE_CLI_FPRINTF(sh, color, fmt, ##__VA_ARGS__)), \
1302 (shell_fprintf_impl(sh, color, fmt, ##__VA_ARGS__)))
1303
1316void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
1317 const char *fmt, va_list args);
1318
1329void shell_cbpprintf(const struct shell *sh, enum shell_vt100_color color, void *package);
1330
1346void shell_hexdump_line(const struct shell *sh, unsigned int offset,
1347 const uint8_t *data, size_t len);
1348
1356void shell_hexdump(const struct shell *sh, const uint8_t *data, size_t len);
1357
1367#define shell_info(_sh, _ft, ...) shell_fprintf(_sh, SHELL_INFO, _ft "\n", ##__VA_ARGS__)
1368
1378#define shell_fprintf_info(_sh, _ft, ...) shell_fprintf(_sh, SHELL_INFO, _ft, ##__VA_ARGS__)
1379
1389#define shell_print(_sh, _ft, ...) shell_fprintf_normal(_sh, _ft "\n", ##__VA_ARGS__)
1390
1400#define shell_fprintf_normal(_sh, _ft, ...) shell_fprintf(_sh, SHELL_NORMAL, _ft, ##__VA_ARGS__)
1401
1411#define shell_warn(_sh, _ft, ...) shell_fprintf_warn(_sh, _ft "\n", ##__VA_ARGS__)
1412
1422#define shell_fprintf_warn(_sh, _ft, ...) shell_fprintf(_sh, SHELL_WARNING, _ft, ##__VA_ARGS__)
1423
1433#define shell_error(_sh, _ft, ...) shell_fprintf_error(_sh, _ft "\n", ##__VA_ARGS__)
1434
1444#define shell_fprintf_error(_sh, _ft, ...) shell_fprintf(_sh, SHELL_ERROR, _ft, ##__VA_ARGS__)
1445
1452void shell_process(const struct shell *sh);
1453
1463int shell_prompt_change(const struct shell *sh, const char *prompt);
1464
1473#ifdef CONFIG_SHELL_HELP
1474void shell_help(const struct shell *sh);
1475#else
1476static inline void shell_help(const struct shell *sh)
1477{
1478 ARG_UNUSED(sh);
1479}
1480#endif /* CONFIG_SHELL_HELP */
1481
1483#define SHELL_CMD_HELP_PRINTED (1)
1484
1502int shell_execute_cmd(const struct shell *sh, const char *cmd);
1503
1515int shell_set_root_cmd(const char *cmd);
1516
1526void shell_set_bypass(const struct shell *sh, shell_bypass_cb_t bypass, void *user_data);
1527
1535bool shell_ready(const struct shell *sh);
1536
1547int shell_insert_mode_set(const struct shell *sh, bool val);
1548
1560int shell_use_colors_set(const struct shell *sh, bool val);
1561
1572int shell_use_vt100_set(const struct shell *sh, bool val);
1573
1584int shell_echo_set(const struct shell *sh, bool val);
1585
1597int shell_obscure_set(const struct shell *sh, bool obscure);
1598
1610int shell_mode_delete_set(const struct shell *sh, bool val);
1611
1619int shell_get_return_value(const struct shell *sh);
1620
1632void shell_readline_prompt_set(const struct shell *sh, const char *prompt);
1633
1659int shell_readline(const struct shell *sh, uint8_t *buf, size_t len, k_timeout_t timeout);
1660
1664
1665#ifdef __cplusplus
1666}
1667#endif
1668
1669#ifdef CONFIG_SHELL_CUSTOM_HEADER
1670/* This include must always be at the end of shell.h */
1671#include <zephyr_custom_shell.h>
1672#endif
1673
1674#endif /* ZEPHYR_INCLUDE_SHELL_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
Atomic integer variable.
Definition atomic_types.h:31
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:345
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)
Shell uninitialization completion callback.
Definition shell.h:844
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:283
#define shell_fprintf(sh, color, fmt,...)
printf-like function which sends formatted data stream to the shell.
Definition shell.h:1299
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)
Shell transport event handler callback.
Definition shell.h:831
int shell_mode_delete_set(const struct shell *sh, bool val)
Allow application to control whether the delete key backspaces or deletes.
void shell_readline_prompt_set(const struct shell *sh, const char *prompt)
Set a prompt string for the next shell_readline call.
int(* shell_cmd_handler)(const struct shell *sh, size_t argc, char **argv)
Shell command handler prototype.
Definition shell.h:267
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:1120
const struct device * shell_device_lookup(size_t idx, const char *prefix)
Get by index a device that matches .
shell_vt100_color
Text colors available for shell output.
Definition shell_types.h:27
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.
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:1476
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:198
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:852
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 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:103
@ SHELL_FLAG_CRLF_DEFAULT
Do not map CR or LF.
Definition shell.h:1121
@ SHELL_FLAG_OLF_CRLF
Map LF to CRLF on output.
Definition shell.h:1122
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
Public kernel APIs.
#define LOG_INSTANCE_PTR_DECLARE(_name)
Declare a logger instance pointer in the module structure.
Definition log_instance.h:133
flags
Definition parser.h:97
state
Definition parser_state.h:29
Header file for the shell formatted output helpers.
Header file for the shell command history.
Header file for the shell log backend.
APIs for the remote shell client.
Header file for the shell string conversion helpers.
Header file for the shell terminal types and colors.
#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:2689
Semaphore structure.
Definition kernel.h:3702
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
Shell structured help descriptor.
Definition shell.h:317
const char * usage
Command usage string.
Definition shell.h:322
const char * description
Command description.
Definition shell.h:321
Shell instance context.
Definition shell.h:1042
Argument count constraints and remote routing for a shell command.
Definition shell.h:120
uint16_t remote_id
Remote connection id; valid only if remote_cmd is non-zero.
Definition shell.h:124
uint16_t remote_cmd
Remote shell command type; non-zero for remote shell.
Definition shell.h:123
uint8_t mandatory
Number of mandatory arguments.
Definition shell.h:121
uint8_t optional
Number of optional arguments.
Definition shell.h:122
Shell static command descriptor.
Definition shell.h:299
const union shell_cmd_entry * subcmd
Pointer to subcommand.
Definition shell.h:302
shell_cmd_handler handler
Command handler.
Definition shell.h:303
struct shell_static_args args
Command arguments.
Definition shell.h:304
const char * help
Command help string.
Definition shell.h:301
const char * syntax
Command syntax strings.
Definition shell.h:300
Unified shell transport interface.
Definition shell.h:863
void(* update)(const struct shell_transport *transport)
Function called in shell thread loop.
Definition shell.h:937
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:875
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:914
int(* uninit)(const struct shell_transport *transport)
Function for uninitializing the shell transport interface.
Definition shell.h:887
int(* enable)(const struct shell_transport *transport, bool blocking_tx)
Function for enabling transport in given TX mode.
Definition shell.h:901
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:927
Shell transport instance.
Definition shell.h:948
void * ctx
Transport instance context.
Definition shell.h:950
const struct shell_transport_api * api
Transport backend operations.
Definition shell.h:949
Shell instance internals.
Definition shell.h:1128
Definition sys_getopt.h:16
Iterable sections helpers.
Misc utilities.
struct k_thread * k_tid_t
Definition thread.h:383
Macros to abstract toolchain specific capabilities.
Shell command descriptor.
Definition shell.h:109
const struct shell_static_entry * entry
Pointer to array of static commands.
Definition shell.h:114
shell_dynamic_get dynamic_get
Pointer to function returning dynamic commands.
Definition shell.h:111