Zephyr Project API 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
853typedef void (*shell_bypass_cb_t)(const struct shell *sh,
854 uint8_t *data,
855 size_t len,
856 void *user_data);
857
858struct shell_transport;
859
876 int (*init)(const struct shell_transport *transport,
877 const void *config,
878 shell_transport_handler_t evt_handler,
879 void *context);
880
888 int (*uninit)(const struct shell_transport *transport);
889
902 int (*enable)(const struct shell_transport *transport,
903 bool blocking_tx);
904
915 int (*write)(const struct shell_transport *transport,
916 const void *data, size_t length, size_t *cnt);
917
928 int (*read)(const struct shell_transport *transport,
929 void *data, size_t length, size_t *cnt);
930
938 void (*update)(const struct shell_transport *transport);
939
940};
941
950 const struct shell_transport_api *api;
951 void *ctx;
952};
953
955
959struct shell_stats {
960 atomic_t log_lost_cnt;
961};
962
963#ifdef CONFIG_SHELL_STATS
964#define Z_SHELL_STATS_DEFINE(_name) static struct shell_stats _name##_stats
965#define Z_SHELL_STATS_PTR(_name) (&(_name##_stats))
966#else
967#define Z_SHELL_STATS_DEFINE(_name)
968#define Z_SHELL_STATS_PTR(_name) NULL
969#endif /* CONFIG_SHELL_STATS */
970
974struct shell_backend_config_flags {
975 uint32_t insert_mode :1;
976 uint32_t echo :1;
977 uint32_t obscure :1;
978 uint32_t mode_delete :1;
979 uint32_t use_colors :1;
980 uint32_t use_vt100 :1;
981 uint32_t _reserved :26;
982};
983
984BUILD_ASSERT((sizeof(struct shell_backend_config_flags) == sizeof(uint32_t)),
985 "Structure must fit in 4 bytes");
986
990#define SHELL_DEFAULT_BACKEND_CONFIG_FLAGS \
991{ \
992 .insert_mode = 0, \
993 .echo = 1, \
994 .obscure = IS_ENABLED(CONFIG_SHELL_START_OBSCURED), \
995 .mode_delete = 1, \
996 .use_colors = 1, \
997 .use_vt100 = 1, \
998};
999
1000struct shell_backend_ctx_flags {
1001 uint32_t last_nl :8;
1002 uint32_t processing :1;
1003 uint32_t tx_rdy :1;
1004 uint32_t history_exit :1;
1005 uint32_t cmd_ctx :1;
1006 uint32_t print_noinit :1;
1007 uint32_t sync_mode :1;
1008 uint32_t handle_log :1;
1009 uint32_t _reserved :17;
1010};
1011
1012BUILD_ASSERT((sizeof(struct shell_backend_ctx_flags) == sizeof(uint32_t)),
1013 "Structure must fit in 4 bytes");
1014
1018union shell_backend_cfg {
1019 atomic_t value;
1020 struct shell_backend_config_flags flags;
1021};
1022
1026union shell_backend_ctx {
1027 uint32_t value;
1028 struct shell_backend_ctx_flags flags;
1029};
1030
1031enum shell_signal {
1032 SHELL_SIGNAL_RXRDY = BIT(0),
1033 SHELL_SIGNAL_LOG_MSG = BIT(1),
1034 SHELL_SIGNAL_KILL = BIT(2),
1035 SHELL_SIGNAL_TXDONE = BIT(3),
1036};
1037
1039
1045#if defined(CONFIG_SHELL_PROMPT_CHANGE) && CONFIG_SHELL_PROMPT_CHANGE
1046 char prompt[CONFIG_SHELL_PROMPT_BUFF_SIZE];
1047#else
1048 const char *prompt;
1049#endif
1050
1051 enum shell_state state;
1052 enum shell_receive_state receive_state;
1053
1055 enum shell_readline_state readline_state;
1056
1058 const char *readline_prompt;
1059
1061 struct shell_static_entry active_cmd;
1062
1064 const struct shell_static_entry *selected_cmd;
1065
1067 struct shell_vt100_ctx vt100_ctx;
1068
1072 shell_uninit_cb_t uninit_cb;
1073
1075 shell_bypass_cb_t bypass;
1076
1078 void *bypass_user_data;
1079
1081 uint32_t log_level;
1082
1083#if defined CONFIG_SHELL_GETOPT
1085 struct sys_getopt_state getopt;
1086#endif
1087
1088 uint16_t cmd_buff_len;
1089 uint16_t cmd_buff_pos;
1090
1091 uint16_t cmd_tmp_buff_len;
1092 uint16_t cmd_tmp_buff_pos;
1093
1095 char cmd_buff[CONFIG_SHELL_CMD_BUFF_SIZE];
1096
1098 char temp_buff[CONFIG_SHELL_CMD_BUFF_SIZE];
1099
1101 char printf_buff[CONFIG_SHELL_PRINTF_BUFF_SIZE];
1102
1103 volatile union shell_backend_cfg cfg;
1104 volatile union shell_backend_ctx ctx;
1105
1106 struct k_event signal_event;
1107
1108 struct k_sem lock_sem;
1109 k_tid_t tid;
1110 int ret_val;
1112};
1113
1115extern const struct log_backend_api log_backend_shell_api;
1117
1125
1129struct shell {
1131 const char *default_prompt;
1132
1133 const struct shell_transport *iface;
1134 struct shell_ctx *ctx;
1135
1136 struct shell_history *history;
1137
1138 const enum shell_flag shell_flag;
1139
1140 const struct shell_fprintf *fprintf_ctx;
1141
1142 struct shell_stats *stats;
1143
1144 const struct shell_log_backend *log_backend;
1145
1147
1148 const char *name;
1149 struct k_thread *thread;
1150 k_thread_stack_t *stack;
1152};
1153
1154extern void z_shell_print_stream(const void *user_ctx, const char *data,
1155 size_t data_len);
1156
1169#define Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _out_buf, _log_backend, _shell_flag) \
1170 static const struct shell _name; \
1171 static struct shell_ctx UTIL_CAT(_name, _ctx); \
1172 Z_SHELL_HISTORY_DEFINE(_name##_history, CONFIG_SHELL_HISTORY_BUFFER); \
1173 Z_SHELL_FPRINTF_DEFINE(_name##_fprintf, &_name, _out_buf, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
1174 IS_ENABLED(CONFIG_SHELL_PRINTF_AUTOFLUSH), z_shell_print_stream); \
1175 LOG_INSTANCE_REGISTER(shell, _name, CONFIG_SHELL_LOG_LEVEL); \
1176 Z_SHELL_STATS_DEFINE(_name); \
1177 static K_KERNEL_STACK_DEFINE(_name##_stack, CONFIG_SHELL_STACK_SIZE); \
1178 static struct k_thread _name##_thread; \
1179 static const STRUCT_SECTION_ITERABLE(shell, _name) = { \
1180 .default_prompt = _prompt, \
1181 .iface = _transport_iface, \
1182 .ctx = &UTIL_CAT(_name, _ctx), \
1183 .history = IS_ENABLED(CONFIG_SHELL_HISTORY) ? &_name##_history : NULL, \
1184 .shell_flag = _shell_flag, \
1185 .fprintf_ctx = &_name##_fprintf, \
1186 .stats = Z_SHELL_STATS_PTR(_name), \
1187 .log_backend = _log_backend, \
1188 LOG_INSTANCE_PTR_INIT(log, shell, _name).name = \
1189 STRINGIFY(_name), .thread = &_name##_thread, .stack = _name##_stack}
1190
1204#define SHELL_DEFINE(_name, _prompt, _transport_iface, _log_queue_size, _log_timeout, _shell_flag) \
1205 static uint8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \
1206 Z_SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
1207 _log_queue_size, _log_timeout); \
1208 Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _name##_out_buffer, \
1209 Z_SHELL_LOG_BACKEND_PTR(_name), _shell_flag)
1210
1224int shell_init(const struct shell *sh, const void *transport_config,
1225 struct shell_backend_config_flags cfg_flags,
1226 bool log_backend, uint32_t init_log_level);
1227
1234void shell_uninit(const struct shell *sh, shell_uninit_cb_t cb);
1235
1243int shell_start(const struct shell *sh);
1244
1252int shell_stop(const struct shell *sh);
1253
1257#define SHELL_NORMAL SHELL_VT100_COLOR_DEFAULT
1258
1262#define SHELL_INFO SHELL_VT100_COLOR_GREEN
1263
1267#define SHELL_OPTION SHELL_VT100_COLOR_CYAN
1268
1272#define SHELL_WARNING SHELL_VT100_COLOR_YELLOW
1273
1277#define SHELL_ERROR SHELL_VT100_COLOR_RED
1278
1279#ifdef CONFIG_SHELL_REMOTE_CLI
1281#endif
1282
1284void __printf_like(3, 4) shell_fprintf_impl(const struct shell *sh, enum shell_vt100_color color,
1285 const char *fmt, ...);
1287
1300#define shell_fprintf(sh, color, fmt, ...) \
1301 COND_CODE_1(IS_ENABLED(CONFIG_SHELL_REMOTE_CLI), \
1302 (SHELL_REMOTE_CLI_FPRINTF(sh, color, fmt, ##__VA_ARGS__)), \
1303 (shell_fprintf_impl(sh, color, fmt, ##__VA_ARGS__)))
1304
1317void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
1318 const char *fmt, va_list args);
1319
1330void shell_cbpprintf(const struct shell *sh, enum shell_vt100_color color, void *package);
1331
1347void shell_hexdump_line(const struct shell *sh, unsigned int offset,
1348 const uint8_t *data, size_t len);
1349
1357void shell_hexdump(const struct shell *sh, const uint8_t *data, size_t len);
1358
1368#define shell_info(_sh, _ft, ...) shell_fprintf(_sh, SHELL_INFO, _ft "\n", ##__VA_ARGS__)
1369
1379#define shell_fprintf_info(_sh, _ft, ...) shell_fprintf(_sh, SHELL_INFO, _ft, ##__VA_ARGS__)
1380
1390#define shell_print(_sh, _ft, ...) shell_fprintf_normal(_sh, _ft "\n", ##__VA_ARGS__)
1391
1401#define shell_fprintf_normal(_sh, _ft, ...) shell_fprintf(_sh, SHELL_NORMAL, _ft, ##__VA_ARGS__)
1402
1412#define shell_warn(_sh, _ft, ...) shell_fprintf_warn(_sh, _ft "\n", ##__VA_ARGS__)
1413
1423#define shell_fprintf_warn(_sh, _ft, ...) shell_fprintf(_sh, SHELL_WARNING, _ft, ##__VA_ARGS__)
1424
1434#define shell_error(_sh, _ft, ...) shell_fprintf_error(_sh, _ft "\n", ##__VA_ARGS__)
1435
1445#define shell_fprintf_error(_sh, _ft, ...) shell_fprintf(_sh, SHELL_ERROR, _ft, ##__VA_ARGS__)
1446
1453void shell_process(const struct shell *sh);
1454
1464int shell_prompt_change(const struct shell *sh, const char *prompt);
1465
1474#ifdef CONFIG_SHELL_HELP
1475void shell_help(const struct shell *sh);
1476#else
1477static inline void shell_help(const struct shell *sh)
1478{
1479 ARG_UNUSED(sh);
1480}
1481#endif /* CONFIG_SHELL_HELP */
1482
1484#define SHELL_CMD_HELP_PRINTED (1)
1485
1503int shell_execute_cmd(const struct shell *sh, const char *cmd);
1504
1516int shell_set_root_cmd(const char *cmd);
1517
1527void shell_set_bypass(const struct shell *sh, shell_bypass_cb_t bypass, void *user_data);
1528
1536bool shell_ready(const struct shell *sh);
1537
1548int shell_insert_mode_set(const struct shell *sh, bool val);
1549
1561int shell_use_colors_set(const struct shell *sh, bool val);
1562
1573int shell_use_vt100_set(const struct shell *sh, bool val);
1574
1585int shell_echo_set(const struct shell *sh, bool val);
1586
1598int shell_obscure_set(const struct shell *sh, bool obscure);
1599
1611int shell_mode_delete_set(const struct shell *sh, bool val);
1612
1620int shell_get_return_value(const struct shell *sh);
1621
1633void shell_readline_prompt_set(const struct shell *sh, const char *prompt);
1634
1660int shell_readline(const struct shell *sh, uint8_t *buf, size_t len, k_timeout_t timeout);
1661
1665
1666#ifdef __cplusplus
1667}
1668#endif
1669
1670#ifdef CONFIG_SHELL_CUSTOM_HEADER
1671/* This include must always be at the end of shell.h */
1672#include <zephyr_custom_shell.h>
1673#endif
1674
1675#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
#define LOG_INSTANCE_PTR_DECLARE(_name)
Declare a logger instance pointer in the module structure.
Definition log_instance.h:154
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:1300
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:1121
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:1477
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_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:853
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:1122
@ SHELL_FLAG_OLF_CRLF
Map LF to CRLF on output.
Definition shell.h:1123
#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.
Header file for the logging subsystem.
Header file for log instance registration.
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:2777
Semaphore structure.
Definition kernel.h:3798
Thread Structure.
Definition thread.h:259
Kernel timeout type.
Definition clock.h:65
Logger backend API.
Definition log_backend.h:74
Logger backend structure.
Definition log_backend.h:118
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:1043
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:864
void(* update)(const struct shell_transport *transport)
Function called in shell thread loop.
Definition shell.h:938
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:876
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:915
int(* uninit)(const struct shell_transport *transport)
Function for uninitializing the shell transport interface.
Definition shell.h:888
int(* enable)(const struct shell_transport *transport, bool blocking_tx)
Function for enabling transport in given TX mode.
Definition shell.h:902
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:928
Shell transport instance.
Definition shell.h:949
void * ctx
Transport instance context.
Definition shell.h:951
const struct shell_transport_api * api
Transport backend operations.
Definition shell.h:950
Shell instance internals.
Definition shell.h:1129
Definition sys_getopt.h:16
Iterable sections helpers.
Misc utilities.
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