Zephyr Project API 4.1.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
23#include <getopt.h>
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
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
145typedef bool (*shell_device_filter_t)(const struct device *dev);
146
160const struct device *shell_device_filter(size_t idx,
161 shell_device_filter_t filter);
162
183const struct device *shell_device_get_binding(const char *name);
184
197typedef int (*shell_cmd_handler)(const struct shell *sh,
198 size_t argc, char **argv);
199
213typedef int (*shell_dict_cmd_handler)(const struct shell *sh, size_t argc,
214 char **argv, void *data);
215
216/* When entries are added to the memory section a padding is applied for
217 * the posix architecture with 64bits builds and x86_64 targets. Adding padding to allow handle data
218 * in the memory section as array.
219 */
220#if (defined(CONFIG_ARCH_POSIX) && defined(CONFIG_64BIT)) || defined(CONFIG_X86_64)
221#define Z_SHELL_STATIC_ENTRY_PADDING 24
222#else
223#define Z_SHELL_STATIC_ENTRY_PADDING 0
224#endif
225
226/*
227 * @brief Shell static command descriptor.
228 */
230 const char *syntax;
231 const char *help;
232 const union shell_cmd_entry *subcmd;
235 uint8_t padding[Z_SHELL_STATIC_ENTRY_PADDING];
236};
237
246 /* @cond INTERNAL_HIDDEN */
247 uint32_t magic;
248 /* @endcond */
249 const char *description;
250 const char *usage;
251};
252
261#define SHELL_STRUCTURED_HELP_MAGIC 0x86D20BC4
262
273static inline bool shell_help_is_structured(const char *help)
274{
275 const struct shell_cmd_help *structured = (const struct shell_cmd_help *)help;
276
277 return structured != NULL && IS_PTR_ALIGNED(structured, struct shell_cmd_help) &&
278 structured->magic == SHELL_STRUCTURED_HELP_MAGIC;
279}
280
281#if defined(CONFIG_SHELL_HELP) || defined(__DOXYGEN__)
305#define SHELL_HELP(_description, _usage) \
306 ((const char *)&(const struct shell_cmd_help){ \
307 .magic = SHELL_STRUCTURED_HELP_MAGIC, \
308 .description = (_description), \
309 .usage = (_usage), \
310 })
311#else
312#define SHELL_HELP(_description, _usage) NULL
313#endif /* CONFIG_SHELL_HELP */
314
330#define SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, \
331 mandatory, optional) \
332 static const struct shell_static_entry UTIL_CAT(_shell_, syntax) = \
333 SHELL_CMD_ARG(syntax, subcmd, help, handler, mandatory, optional); \
334 static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, \
335 UTIL_CAT(shell_cmd_, syntax), shell_root_cmds, \
336 UTIL_CAT(shell_cmd_, syntax) \
337 ) = { \
338 .entry = &UTIL_CAT(_shell_, syntax) \
339 }
340
361#define SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, \
362 mandatory, optional) \
363 COND_CODE_1(\
364 flag, \
365 (\
366 SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, \
367 mandatory, optional) \
368 ), \
369 (\
370 static shell_cmd_handler dummy_##syntax##_handler __unused = \
371 handler;\
372 static const union shell_cmd_entry *dummy_subcmd_##syntax \
373 __unused = subcmd\
374 ) \
375 )
387#define SHELL_CMD_REGISTER(syntax, subcmd, help, handler) \
388 SHELL_CMD_ARG_REGISTER(syntax, subcmd, help, handler, 0, 0)
389
403#define SHELL_COND_CMD_REGISTER(flag, syntax, subcmd, help, handler) \
404 SHELL_COND_CMD_ARG_REGISTER(flag, syntax, subcmd, help, handler, 0, 0)
405
424#define SHELL_STATIC_SUBCMD_SET_CREATE(name, ...) \
425 static const struct shell_static_entry shell_##name[] = { \
426 __VA_ARGS__ \
427 }; \
428 static const union shell_cmd_entry name = { \
429 .entry = shell_##name \
430 }
431
432#define Z_SHELL_UNDERSCORE(x) _##x
433#define Z_SHELL_SUBCMD_NAME(...) \
434 UTIL_CAT(shell_subcmds, MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__))
435#define Z_SHELL_SUBCMD_SECTION_TAG(...) MACRO_MAP_CAT(Z_SHELL_UNDERSCORE, __VA_ARGS__)
436#define Z_SHELL_SUBCMD_SET_SECTION_TAG(x) \
437 Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x)
438#define Z_SHELL_SUBCMD_ADD_SECTION_TAG(x, y) \
439 Z_SHELL_SUBCMD_SECTION_TAG(NUM_VA_ARGS_LESS_1 x, __DEBRACKET x, y)
440
453#define SHELL_SUBCMD_SET_CREATE(_name, _parent) \
454 static const TYPE_SECTION_ITERABLE(struct shell_static_entry, _name, shell_subcmds, \
455 Z_SHELL_SUBCMD_SET_SECTION_TAG(_parent))
456
457
477#define SHELL_SUBCMD_COND_ADD(_flag, _parent, _syntax, _subcmd, _help, _handler, \
478 _mand, _opt) \
479 COND_CODE_1(_flag, \
480 (static const TYPE_SECTION_ITERABLE(struct shell_static_entry, \
481 Z_SHELL_SUBCMD_NAME(__DEBRACKET _parent, _syntax), \
482 shell_subcmds, \
483 Z_SHELL_SUBCMD_ADD_SECTION_TAG(_parent, _syntax)) = \
484 SHELL_EXPR_CMD_ARG(1, _syntax, _subcmd, _help, \
485 _handler, _mand, _opt)\
486 ), \
487 (static shell_cmd_handler dummy_handler_##_syntax __unused = _handler;\
488 static const union shell_cmd_entry dummy_subcmd_##_syntax __unused = { \
489 .entry = (const struct shell_static_entry *)_subcmd\
490 } \
491 ) \
492 )
493
506#define SHELL_SUBCMD_ADD(_parent, _syntax, _subcmd, _help, _handler, _mand, _opt) \
507 SHELL_SUBCMD_COND_ADD(1, _parent, _syntax, _subcmd, _help, _handler, _mand, _opt)
508
513#define SHELL_SUBCMD_SET_END {NULL}
514
521#define SHELL_DYNAMIC_CMD_CREATE(name, get) \
522 static const TYPE_SECTION_ITERABLE(union shell_cmd_entry, name, \
523 shell_dynamic_subcmds, name) = \
524 { \
525 .dynamic_get = get \
526 }
527
541#define SHELL_CMD_ARG(syntax, subcmd, help, handler, mand, opt) \
542 SHELL_EXPR_CMD_ARG(1, syntax, subcmd, help, handler, mand, opt)
543
563#define SHELL_COND_CMD_ARG(flag, syntax, subcmd, help, handler, mand, opt) \
564 SHELL_EXPR_CMD_ARG(IS_ENABLED(flag), syntax, subcmd, help, \
565 handler, mand, opt)
566
586#define SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, \
587 _mand, _opt) \
588 { \
589 .syntax = (_expr) ? (const char *)STRINGIFY(_syntax) : "", \
590 .help = (_expr) ? (const char *)_help : NULL, \
591 .subcmd = (const union shell_cmd_entry *)((_expr) ? \
592 _subcmd : NULL), \
593 .handler = (shell_cmd_handler)((_expr) ? _handler : NULL), \
594 .args = { .mandatory = _mand, .optional = _opt} \
595 }
596
605#define SHELL_CMD(_syntax, _subcmd, _help, _handler) \
606 SHELL_CMD_ARG(_syntax, _subcmd, _help, _handler, 0, 0)
607
620#define SHELL_COND_CMD(_flag, _syntax, _subcmd, _help, _handler) \
621 SHELL_COND_CMD_ARG(_flag, _syntax, _subcmd, _help, _handler, 0, 0)
622
636#define SHELL_EXPR_CMD(_expr, _syntax, _subcmd, _help, _handler) \
637 SHELL_EXPR_CMD_ARG(_expr, _syntax, _subcmd, _help, _handler, 0, 0)
638
639/* Internal macro used for creating handlers for dictionary commands. */
640#define Z_SHELL_CMD_DICT_HANDLER_CREATE(_data, _handler) \
641static int UTIL_CAT(UTIL_CAT(cmd_dict_, UTIL_CAT(_handler, _)), \
642 GET_ARG_N(1, __DEBRACKET _data))( \
643 const struct shell *sh, size_t argc, char **argv) \
644{ \
645 return _handler(sh, argc, argv, \
646 (void *)GET_ARG_N(2, __DEBRACKET _data)); \
647}
648
649/* Internal macro used for creating dictionary commands. */
650#define SHELL_CMD_DICT_CREATE(_data, _handler) \
651 SHELL_CMD_ARG(GET_ARG_N(1, __DEBRACKET _data), NULL, GET_ARG_N(3, __DEBRACKET _data), \
652 UTIL_CAT(UTIL_CAT(cmd_dict_, UTIL_CAT(_handler, _)), \
653 GET_ARG_N(1, __DEBRACKET _data)), 1, 0)
654
688#define SHELL_SUBCMD_DICT_SET_CREATE(_name, _handler, ...) \
689 FOR_EACH_FIXED_ARG(Z_SHELL_CMD_DICT_HANDLER_CREATE, (), \
690 _handler, __VA_ARGS__) \
691 SHELL_STATIC_SUBCMD_SET_CREATE(_name, \
692 FOR_EACH_FIXED_ARG(SHELL_CMD_DICT_CREATE, (,), _handler, __VA_ARGS__), \
693 SHELL_SUBCMD_SET_END \
694 )
695
706
717
723
725 void *context);
726
727
728typedef void (*shell_uninit_cb_t)(const struct shell *sh, int res);
729
736typedef void (*shell_bypass_cb_t)(const struct shell *sh,
737 uint8_t *data,
738 size_t len);
739
740struct shell_transport;
741
758 int (*init)(const struct shell_transport *transport,
759 const void *config,
760 shell_transport_handler_t evt_handler,
761 void *context);
762
770 int (*uninit)(const struct shell_transport *transport);
771
784 int (*enable)(const struct shell_transport *transport,
785 bool blocking_tx);
786
797 int (*write)(const struct shell_transport *transport,
798 const void *data, size_t length, size_t *cnt);
799
810 int (*read)(const struct shell_transport *transport,
811 void *data, size_t length, size_t *cnt);
812
820 void (*update)(const struct shell_transport *transport);
821
822};
823
826 void *ctx;
827};
828
835
836#ifdef CONFIG_SHELL_STATS
837#define Z_SHELL_STATS_DEFINE(_name) static struct shell_stats _name##_stats
838#define Z_SHELL_STATS_PTR(_name) (&(_name##_stats))
839#else
840#define Z_SHELL_STATS_DEFINE(_name)
841#define Z_SHELL_STATS_PTR(_name) NULL
842#endif /* CONFIG_SHELL_STATS */
843
855
856BUILD_ASSERT((sizeof(struct shell_backend_config_flags) == sizeof(uint32_t)),
857 "Structure must fit in 4 bytes");
858
862#define SHELL_DEFAULT_BACKEND_CONFIG_FLAGS \
863{ \
864 .insert_mode = 0, \
865 .echo = 1, \
866 .obscure = IS_ENABLED(CONFIG_SHELL_START_OBSCURED), \
867 .mode_delete = 1, \
868 .use_colors = 1, \
869 .use_vt100 = 1, \
870};
871
882
883BUILD_ASSERT((sizeof(struct shell_backend_ctx_flags) == sizeof(uint32_t)),
884 "Structure must fit in 4 bytes");
885
893
901
909
913struct shell_ctx {
914#if defined(CONFIG_SHELL_PROMPT_CHANGE) && CONFIG_SHELL_PROMPT_CHANGE
916#else
917 const char *prompt;
918#endif
919
925
928
931
936
939
942
943#if defined CONFIG_SHELL_GETOPT
945 struct getopt_state getopt;
946#endif
947
955
958
961
962 volatile union shell_backend_cfg cfg;
963 volatile union shell_backend_ctx ctx;
964
966
971
975};
976
977extern const struct log_backend_api log_backend_shell_api;
978
986
990struct shell {
991 const char *default_prompt;
993 const struct shell_transport *iface;
994 struct shell_ctx *ctx;
997
999
1001
1003
1005
1007
1008 const char *name;
1011};
1012
1013extern void z_shell_print_stream(const void *user_ctx, const char *data,
1014 size_t data_len);
1015
1028#define Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _out_buf, _log_backend, _shell_flag) \
1029 static const struct shell _name; \
1030 static struct shell_ctx UTIL_CAT(_name, _ctx); \
1031 Z_SHELL_HISTORY_DEFINE(_name##_history, CONFIG_SHELL_HISTORY_BUFFER); \
1032 Z_SHELL_FPRINTF_DEFINE(_name##_fprintf, &_name, _out_buf, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
1033 IS_ENABLED(CONFIG_SHELL_PRINTF_AUTOFLUSH), z_shell_print_stream); \
1034 LOG_INSTANCE_REGISTER(shell, _name, CONFIG_SHELL_LOG_LEVEL); \
1035 Z_SHELL_STATS_DEFINE(_name); \
1036 static K_KERNEL_STACK_DEFINE(_name##_stack, CONFIG_SHELL_STACK_SIZE); \
1037 static struct k_thread _name##_thread; \
1038 static const STRUCT_SECTION_ITERABLE(shell, _name) = { \
1039 .default_prompt = _prompt, \
1040 .iface = _transport_iface, \
1041 .ctx = &UTIL_CAT(_name, _ctx), \
1042 .history = IS_ENABLED(CONFIG_SHELL_HISTORY) ? &_name##_history : NULL, \
1043 .shell_flag = _shell_flag, \
1044 .fprintf_ctx = &_name##_fprintf, \
1045 .stats = Z_SHELL_STATS_PTR(_name), \
1046 .log_backend = _log_backend, \
1047 LOG_INSTANCE_PTR_INIT(log, shell, _name).name = \
1048 STRINGIFY(_name), .thread = &_name##_thread, .stack = _name##_stack}
1049
1063#define SHELL_DEFINE(_name, _prompt, _transport_iface, _log_queue_size, _log_timeout, _shell_flag) \
1064 static uint8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \
1065 Z_SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
1066 _log_queue_size, _log_timeout); \
1067 Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _name##_out_buffer, \
1068 Z_SHELL_LOG_BACKEND_PTR(_name), _shell_flag)
1069
1083int shell_init(const struct shell *sh, const void *transport_config,
1084 struct shell_backend_config_flags cfg_flags,
1085 bool log_backend, uint32_t init_log_level);
1086
1093void shell_uninit(const struct shell *sh, shell_uninit_cb_t cb);
1094
1102int shell_start(const struct shell *sh);
1103
1111int shell_stop(const struct shell *sh);
1112
1116#define SHELL_NORMAL SHELL_VT100_COLOR_DEFAULT
1117
1121#define SHELL_INFO SHELL_VT100_COLOR_GREEN
1122
1126#define SHELL_OPTION SHELL_VT100_COLOR_CYAN
1127
1131#define SHELL_WARNING SHELL_VT100_COLOR_YELLOW
1132
1136#define SHELL_ERROR SHELL_VT100_COLOR_RED
1137
1149void __printf_like(3, 4) shell_fprintf_impl(const struct shell *sh, enum shell_vt100_color color,
1150 const char *fmt, ...);
1151
1152#define shell_fprintf(sh, color, fmt, ...) shell_fprintf_impl(sh, color, fmt, ##__VA_ARGS__)
1153
1166void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
1167 const char *fmt, va_list args);
1168
1184void shell_hexdump_line(const struct shell *sh, unsigned int offset,
1185 const uint8_t *data, size_t len);
1186
1194void shell_hexdump(const struct shell *sh, const uint8_t *data, size_t len);
1195
1205#define shell_info(_sh, _ft, ...) \
1206 shell_fprintf_info(_sh, _ft "\n", ##__VA_ARGS__)
1207void __printf_like(2, 3) shell_fprintf_info(const struct shell *sh, const char *fmt, ...);
1208
1218#define shell_print(_sh, _ft, ...) \
1219 shell_fprintf_normal(_sh, _ft "\n", ##__VA_ARGS__)
1220void __printf_like(2, 3) shell_fprintf_normal(const struct shell *sh, const char *fmt, ...);
1221
1231#define shell_warn(_sh, _ft, ...) \
1232 shell_fprintf_warn(_sh, _ft "\n", ##__VA_ARGS__)
1233void __printf_like(2, 3) shell_fprintf_warn(const struct shell *sh, const char *fmt, ...);
1234
1244#define shell_error(_sh, _ft, ...) \
1245 shell_fprintf_error(_sh, _ft "\n", ##__VA_ARGS__)
1246void __printf_like(2, 3) shell_fprintf_error(const struct shell *sh, const char *fmt, ...);
1247
1254void shell_process(const struct shell *sh);
1255
1265int shell_prompt_change(const struct shell *sh, const char *prompt);
1266
1275void shell_help(const struct shell *sh);
1276
1278#define SHELL_CMD_HELP_PRINTED (1)
1279
1297int shell_execute_cmd(const struct shell *sh, const char *cmd);
1298
1310int shell_set_root_cmd(const char *cmd);
1311
1320void shell_set_bypass(const struct shell *sh, shell_bypass_cb_t bypass);
1321
1329bool shell_ready(const struct shell *sh);
1330
1341int shell_insert_mode_set(const struct shell *sh, bool val);
1342
1354int shell_use_colors_set(const struct shell *sh, bool val);
1355
1366int shell_use_vt100_set(const struct shell *sh, bool val);
1367
1378int shell_echo_set(const struct shell *sh, bool val);
1379
1391int shell_obscure_set(const struct shell *sh, bool obscure);
1392
1404int shell_mode_delete_set(const struct shell *sh, bool val);
1405
1413int shell_get_return_value(const struct shell *sh);
1414
1419#ifdef __cplusplus
1420}
1421#endif
1422
1423#ifdef CONFIG_SHELL_CUSTOM_HEADER
1424/* This include must always be at the end of shell.h */
1425#include <zephyr_custom_shell.h>
1426#endif
1427
1428#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
static bool shell_help_is_structured(const char *help)
Check if help string is structured help.
Definition shell.h:273
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:728
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:213
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:724
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:197
void shell_fprintf_error(const struct shell *sh, const char *fmt,...)
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:982
const struct device * shell_device_lookup(size_t idx, const char *prefix)
Get by index a device that matches .
shell_signal
Definition shell.h:902
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.
void shell_set_bypass(const struct shell *sh, shell_bypass_cb_t bypass)
Set bypass callback.
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.
shell_receive_state
Definition shell.h:700
void shell_fprintf_warn(const struct shell *sh, const char *fmt,...)
bool(* shell_device_filter_t)(const struct device *dev)
Filter callback type, for use with shell_device_lookup_filter.
Definition shell.h:145
void(* shell_bypass_cb_t)(const struct shell *sh, uint8_t *data, size_t len)
Bypass callback.
Definition shell.h:736
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.
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.
shell_transport_evt
Shell transport event.
Definition shell.h:719
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.
shell_state
Definition shell.h:710
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:983
@ SHELL_FLAG_OLF_CRLF
Map LF to CRLF on output.
Definition shell.h:984
@ SHELL_SIGNALS
Definition shell.h:907
@ SHELL_SIGNAL_TXDONE
Definition shell.h:906
@ SHELL_SIGNAL_RXRDY
Definition shell.h:903
@ SHELL_SIGNAL_LOG_MSG
Definition shell.h:904
@ SHELL_SIGNAL_KILL
Definition shell.h:905
@ SHELL_RECEIVE_DEFAULT
Definition shell.h:701
@ SHELL_RECEIVE_ESC_SEQ
Definition shell.h:703
@ SHELL_RECEIVE_ESC
Definition shell.h:702
@ SHELL_RECEIVE_TILDE_EXP
Definition shell.h:704
@ SHELL_TRANSPORT_EVT_TX_RDY
Definition shell.h:721
@ SHELL_TRANSPORT_EVT_RX_RDY
Definition shell.h:720
@ SHELL_STATE_UNINITIALIZED
Definition shell.h:711
@ SHELL_STATE_PANIC_MODE_INACTIVE
Panic requested, not supported.
Definition shell.h:715
@ SHELL_STATE_ACTIVE
Definition shell.h:713
@ SHELL_STATE_PANIC_MODE_ACTIVE
Panic activated.
Definition shell.h:714
@ SHELL_STATE_INITIALIZED
Definition shell.h:712
#define NULL
Definition iar_missing_defs.h:20
#define IS_PTR_ALIGNED(ptr, type)
Definition common.h:232
Public kernel APIs.
flags
Definition parser.h:97
#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:510
const char * name
Name of the device instance.
Definition device.h:512
Mutex Structure.
Definition kernel.h:3070
Poll Event.
Definition kernel.h:6092
Definition kernel.h:6068
Thread Structure.
Definition thread.h:262
Logger backend API.
Definition log_backend.h:63
Logger backend structure.
Definition log_backend.h:95
Definition shell.h:847
uint32_t use_vt100
Controls VT100 commands usage in shell.
Definition shell.h:853
uint32_t mode_delete
Operation mode of backspace key.
Definition shell.h:851
uint32_t echo
Controls shell echo.
Definition shell.h:849
uint32_t insert_mode
Controls insert mode for text introduction.
Definition shell.h:848
uint32_t obscure
If echo on, print asterisk instead.
Definition shell.h:850
uint32_t use_colors
Controls colored syntax.
Definition shell.h:852
Definition shell.h:872
uint32_t print_noinit
Print request from not initialized shell.
Definition shell.h:878
uint32_t sync_mode
Shell in synchronous mode.
Definition shell.h:879
uint32_t tx_rdy
Definition shell.h:874
uint32_t handle_log
Shell is handling logger backend.
Definition shell.h:880
uint32_t processing
Shell is executing process function.
Definition shell.h:873
uint32_t last_nl
Last received new line character.
Definition shell.h:876
uint32_t history_exit
Request to exit history mode.
Definition shell.h:875
uint32_t cmd_ctx
Shell is executing command.
Definition shell.h:877
Shell structured help descriptor.
Definition shell.h:245
const char * usage
Command usage string.
Definition shell.h:250
const char * description
Command description.
Definition shell.h:249
Shell instance context.
Definition shell.h:913
const struct shell_static_entry * selected_cmd
New root command.
Definition shell.h:927
shell_uninit_cb_t uninit_cb
Callback called from shell thread context when unitialization is completed just before aborting shell...
Definition shell.h:935
struct shell_vt100_ctx vt100_ctx
VT100 color and cursor position, terminal width.
Definition shell.h:930
const char * prompt
Definition shell.h:917
k_tid_t tid
Definition shell.h:973
char temp_buff[0]
Command temporary buffer.
Definition shell.h:957
char cmd_buff[0]
Command input buffer.
Definition shell.h:954
struct shell_static_entry active_cmd
Currently executed command.
Definition shell.h:924
uint32_t log_level
Definition shell.h:941
volatile union shell_backend_cfg cfg
Definition shell.h:962
uint16_t cmd_tmp_buff_len
Command length in tmp buffer.
Definition shell.h:951
struct k_poll_signal signals[SHELL_SIGNALS]
Definition shell.h:965
enum shell_state state
Internal module state.
Definition shell.h:920
struct k_mutex wr_mtx
Definition shell.h:972
shell_bypass_cb_t bypass
When bypass is set, all incoming data is passed to the callback.
Definition shell.h:938
uint16_t cmd_buff_len
Command length.
Definition shell.h:948
uint16_t cmd_buff_pos
Command buffer cursor position.
Definition shell.h:949
int ret_val
Definition shell.h:974
char printf_buff[0]
Printf buffer size.
Definition shell.h:960
struct k_poll_event events[SHELL_SIGNALS]
Events that should be used only internally by shell thread.
Definition shell.h:970
enum shell_receive_state receive_state
Escape sequence indicator.
Definition shell.h:921
volatile union shell_backend_ctx ctx
Definition shell.h:963
fprintf context
Definition shell_fprintf.h:29
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:229
const union shell_cmd_entry * subcmd
Pointer to subcommand.
Definition shell.h:232
uint8_t padding[0]
Definition shell.h:235
shell_cmd_handler handler
Command handler.
Definition shell.h:233
struct shell_static_args args
Command arguments.
Definition shell.h:234
const char * help
Command help string.
Definition shell.h:231
const char * syntax
Command syntax strings.
Definition shell.h:230
Shell statistics structure.
Definition shell.h:832
atomic_t log_lost_cnt
Lost log counter.
Definition shell.h:833
Unified shell transport interface.
Definition shell.h:746
void(* update)(const struct shell_transport *transport)
Function called in shell thread loop.
Definition shell.h:820
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:758
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:797
int(* uninit)(const struct shell_transport *transport)
Function for uninitializing the shell transport interface.
Definition shell.h:770
int(* enable)(const struct shell_transport *transport, bool blocking_tx)
Function for enabling transport in given TX mode.
Definition shell.h:784
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:810
Definition shell.h:824
void * ctx
Definition shell.h:826
const struct shell_transport_api * api
Definition shell.h:825
Definition shell_types.h:44
Shell instance internals.
Definition shell.h:990
struct k_thread * thread
Definition shell.h:1009
LOG_INSTANCE_PTR_DECLARE(log)
enum shell_flag shell_flag
Definition shell.h:998
const struct shell_log_backend * log_backend
Definition shell.h:1004
struct shell_history * history
Definition shell.h:996
struct shell_stats * stats
Definition shell.h:1002
const char * name
Definition shell.h:1008
const char * default_prompt
shell default prompt.
Definition shell.h:991
const struct shell_fprintf * fprintf_ctx
Definition shell.h:1000
struct shell_ctx * ctx
Internal context.
Definition shell.h:994
const struct shell_transport * iface
Transport interface.
Definition shell.h:993
k_thread_stack_t * stack
Definition shell.h:1010
Misc utilities.
Macros to abstract toolchain specific capabilities.
Definition shell.h:889
atomic_t value
Definition shell.h:890
Definition shell.h:897
uint32_t value
Definition shell.h:898
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