Skip to content

Shell threadless #3056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions include/zephyr/shell/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -822,11 +822,10 @@
};

enum shell_signal {
SHELL_SIGNAL_RXRDY,
SHELL_SIGNAL_LOG_MSG,
SHELL_SIGNAL_KILL,
SHELL_SIGNAL_TXDONE, /* TXDONE must be last one before SHELL_SIGNALS */
SHELL_SIGNALS
SHELL_SIGNAL_RXRDY = BIT(0),
SHELL_SIGNAL_LOG_MSG = BIT(1),
SHELL_SIGNAL_KILL = BIT(2),
SHELL_SIGNAL_TXDONE = BIT(3),
};

/**
Expand Down Expand Up @@ -884,15 +883,11 @@
volatile union shell_backend_cfg cfg;
volatile union shell_backend_ctx ctx;

struct k_poll_signal signals[SHELL_SIGNALS];

/** Events that should be used only internally by shell thread.
* Event for SHELL_SIGNAL_TXDONE is initialized but unused.
*/
struct k_poll_event events[SHELL_SIGNALS];

struct k_mutex wr_mtx;
#if CONFIG_MULTITHREADING
struct k_event signal_event;
struct k_sem lock_sem;
k_tid_t tid;
#endif
int ret_val;
};

Expand Down Expand Up @@ -928,13 +923,29 @@
LOG_INSTANCE_PTR_DECLARE(log);

const char *name;

#if CONFIG_MULTITHREADING
struct k_thread *thread;
k_thread_stack_t *stack;
#endif
};

extern void z_shell_print_stream(const void *user_ctx, const char *data,
size_t data_len);

#if CONFIG_MULTITHREADING
#define Z_SHELL_THREAD_DEFINE(_name) \
static K_KERNEL_STACK_DEFINE(_name##_stack, CONFIG_SHELL_STACK_SIZE); \
static struct k_thread _name##_thread

#define Z_SHELL_THREAD_INIT(_name) \
.thread = &_name##_thread, \
.stack = _name##_stack,
#else

Check notice on line 944 in include/zephyr/shell/shell.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/shell/shell.h:944 -#define Z_SHELL_THREAD_INIT(_name) \ - .thread = &_name##_thread, \ - .stack = _name##_stack, +#define Z_SHELL_THREAD_INIT(_name) .thread = &_name##_thread, .stack = _name##_stack,
#define Z_SHELL_THREAD_DEFINE(_name)
#define Z_SHELL_THREAD_INIT(_name)
#endif

/** @brief Internal macro for defining a shell instance.
*
* As it does not create the default shell logging backend it allows to use
Expand All @@ -955,8 +966,7 @@
IS_ENABLED(CONFIG_SHELL_PRINTF_AUTOFLUSH), z_shell_print_stream); \
LOG_INSTANCE_REGISTER(shell, _name, CONFIG_SHELL_LOG_LEVEL); \
Z_SHELL_STATS_DEFINE(_name); \
static K_KERNEL_STACK_DEFINE(_name##_stack, CONFIG_SHELL_STACK_SIZE); \
static struct k_thread _name##_thread; \
Z_SHELL_THREAD_DEFINE(_name); \
static const STRUCT_SECTION_ITERABLE(shell, _name) = { \
.default_prompt = _prompt, \
.iface = _transport_iface, \
Expand All @@ -966,9 +976,10 @@
.fprintf_ctx = &_name##_fprintf, \
.stats = Z_SHELL_STATS_PTR(_name), \
.log_backend = _log_backend, \
LOG_INSTANCE_PTR_INIT(log, shell, _name).name = \
STRINGIFY(_name), .thread = &_name##_thread, .stack = _name##_stack}
LOG_INSTANCE_PTR_INIT(log, shell, _name).name = STRINGIFY(_name), \
Z_SHELL_THREAD_INIT(_name) \
}

Check notice on line 982 in include/zephyr/shell/shell.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/shell/shell.h:982 - LOG_INSTANCE_PTR_INIT(log, shell, _name).name = STRINGIFY(_name), \ - Z_SHELL_THREAD_INIT(_name) \ - } + LOG_INSTANCE_PTR_INIT(log, shell, _name).name = \ + STRINGIFY(_name), Z_SHELL_THREAD_INIT(_name)}
/**
* @brief Macro for defining a shell instance.
*
Expand Down
12 changes: 11 additions & 1 deletion subsys/shell/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
menuconfig SHELL
bool "Shell"
imply LOG_RUNTIME_FILTERING
select POLL
select EVENTS if MULTITHREADING

if SHELL

Expand Down Expand Up @@ -326,6 +326,16 @@ config SHELL_CUSTOM_HEADER
extension of the shell APIs at the macro level. Please use cautiously!
The internal shell API may change in future releases.

config SHELL_TX_TIMEOUT_MS
int "Shell TX timeout in milliseconds"
default 500 if SHELL_LOG_BACKEND
default 50
help
The timeout in milliseconds for the shell TX mutex. This is used to
prevent deadlocks when called from other than the shell's processing thread.
When using the shell log backend, the timeout should be longer to avoid
timeouts due to log processing. A value of 0 means no timeout.

source "subsys/shell/modules/Kconfig"

endif # SHELL
Loading
Loading