@@ -912,6 +912,41 @@ struct shell {
912912
913913extern void z_shell_print_stream (const void * user_ctx , const char * data ,
914914 size_t data_len );
915+
916+ /** @brief Internal macro for defining a shell instance.
917+ *
918+ * As it does not create the default shell logging backend it allows to use
919+ * custom approach for integrating logging with shell.
920+ *
921+ * @param[in] _name Instance name.
922+ * @param[in] _prompt Shell default prompt string.
923+ * @param[in] _transport_iface Pointer to the transport interface.
924+ * @param[in] _out_buf Output buffer.
925+ * @param[in] _log_backend Pointer to the log backend instance.
926+ * @param[in] _shell_flag Shell output newline sequence.
927+ */
928+ #define Z_SHELL_DEFINE (_name , _prompt , _transport_iface , _out_buf , _log_backend , _shell_flag ) \
929+ static const struct shell _name; \
930+ static struct shell_ctx UTIL_CAT(_name, _ctx); \
931+ Z_SHELL_HISTORY_DEFINE(_name##_history, CONFIG_SHELL_HISTORY_BUFFER); \
932+ Z_SHELL_FPRINTF_DEFINE(_name##_fprintf, &_name, _out_buf, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
933+ true, z_shell_print_stream); \
934+ LOG_INSTANCE_REGISTER(shell, _name, CONFIG_SHELL_LOG_LEVEL); \
935+ Z_SHELL_STATS_DEFINE(_name); \
936+ static K_KERNEL_STACK_DEFINE(_name##_stack, CONFIG_SHELL_STACK_SIZE); \
937+ static struct k_thread _name##_thread; \
938+ static const STRUCT_SECTION_ITERABLE(shell, _name) = { \
939+ .default_prompt = _prompt, \
940+ .iface = _transport_iface, \
941+ .ctx = &UTIL_CAT(_name, _ctx), \
942+ .history = IS_ENABLED(CONFIG_SHELL_HISTORY) ? &_name##_history : NULL, \
943+ .shell_flag = _shell_flag, \
944+ .fprintf_ctx = &_name##_fprintf, \
945+ .stats = Z_SHELL_STATS_PTR(_name), \
946+ .log_backend = _log_backend, \
947+ LOG_INSTANCE_PTR_INIT(log, shell, _name).name = \
948+ STRINGIFY(_name), .thread = &_name##_thread, .stack = _name##_stack}
949+
915950/**
916951 * @brief Macro for defining a shell instance.
917952 *
@@ -925,37 +960,12 @@ extern void z_shell_print_stream(const void *user_ctx, const char *data,
925960 * message is dropped.
926961 * @param[in] _shell_flag Shell output newline sequence.
927962 */
928- #define SHELL_DEFINE (_name , _prompt , _transport_iface , \
929- _log_queue_size , _log_timeout , _shell_flag ) \
930- static const struct shell _name; \
931- static struct shell_ctx UTIL_CAT(_name, _ctx); \
932- static uint8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \
933- Z_SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, \
934- CONFIG_SHELL_PRINTF_BUFF_SIZE, \
935- _log_queue_size, _log_timeout); \
936- Z_SHELL_HISTORY_DEFINE(_name##_history, CONFIG_SHELL_HISTORY_BUFFER); \
937- Z_SHELL_FPRINTF_DEFINE(_name##_fprintf, &_name, _name##_out_buffer, \
938- CONFIG_SHELL_PRINTF_BUFF_SIZE, \
939- true, z_shell_print_stream); \
940- LOG_INSTANCE_REGISTER(shell, _name, CONFIG_SHELL_LOG_LEVEL); \
941- Z_SHELL_STATS_DEFINE(_name); \
942- static K_KERNEL_STACK_DEFINE(_name##_stack, CONFIG_SHELL_STACK_SIZE); \
943- static struct k_thread _name##_thread; \
944- static const STRUCT_SECTION_ITERABLE(shell, _name) = { \
945- .default_prompt = _prompt, \
946- .iface = _transport_iface, \
947- .ctx = &UTIL_CAT(_name, _ctx), \
948- .history = IS_ENABLED(CONFIG_SHELL_HISTORY) ? \
949- &_name##_history : NULL, \
950- .shell_flag = _shell_flag, \
951- .fprintf_ctx = &_name##_fprintf, \
952- .stats = Z_SHELL_STATS_PTR(_name), \
953- .log_backend = Z_SHELL_LOG_BACKEND_PTR(_name), \
954- LOG_INSTANCE_PTR_INIT(log, shell, _name) \
955- .name = STRINGIFY(_name), \
956- .thread = &_name##_thread, \
957- .stack = _name##_stack \
958- }
963+ #define SHELL_DEFINE (_name , _prompt , _transport_iface , _log_queue_size , _log_timeout , _shell_flag ) \
964+ static uint8_t _name##_out_buffer[CONFIG_SHELL_PRINTF_BUFF_SIZE]; \
965+ Z_SHELL_LOG_BACKEND_DEFINE(_name, _name##_out_buffer, CONFIG_SHELL_PRINTF_BUFF_SIZE, \
966+ _log_queue_size, _log_timeout); \
967+ Z_SHELL_DEFINE(_name, _prompt, _transport_iface, _name##_out_buffer, \
968+ Z_SHELL_LOG_BACKEND_PTR(_name), _shell_flag)
959969
960970/**
961971 * @brief Function for initializing a transport layer and internal shell state.
0 commit comments