Skip to content

Commit

Permalink
shell: backends: uart: add public function to access smp shell data
Browse files Browse the repository at this point in the history
`smp_shell_input_timeout_handler`. Create a public function in
the `shell_uart.c` for it to get the pointer to the
`smp_shell_data` and fix the compilation error.

Signed-off-by: Yong Cong Sin <[email protected]>
  • Loading branch information
ycsin authored and carlescufi committed Nov 15, 2023
1 parent 287b30e commit 72fea5d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions include/zephyr/shell/shell_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef SHELL_UART_H__
#define SHELL_UART_H__

#include <zephyr/mgmt/mcumgr/transport/smp_shell.h>
#include <zephyr/shell/shell.h>

#ifdef __cplusplus
Expand All @@ -23,6 +24,13 @@ extern "C" {
*/
const struct shell *shell_backend_uart_get_ptr(void);

/**
* @brief This function provides pointer to the smp shell data of the UART shell transport.
*
* @returns Pointer to the smp shell data.
*/
struct smp_shell_data *shell_uart_smp_shell_data_get_ptr(void);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 1 addition & 4 deletions subsys/mgmt/mcumgr/transport/src/smp_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ enum smp_shell_mcumgr_state {
};

#ifdef CONFIG_MCUMGR_TRANSPORT_SHELL_INPUT_TIMEOUT
extern struct shell_transport shell_transport_uart;

static void smp_shell_input_timeout_handler(struct k_timer *timer)
{
ARG_UNUSED(timer);
struct shell_uart *sh_uart = (struct shell_uart *)shell_transport_uart.ctx;
struct smp_shell_data *const data = &sh_uart->ctrl_blk->smp;
struct smp_shell_data *const data = shell_uart_smp_shell_data_get_ptr();

atomic_clear_bit(&data->esc_state, ESC_MCUMGR_PKT_1);
atomic_clear_bit(&data->esc_state, ESC_MCUMGR_PKT_2);
Expand Down
13 changes: 13 additions & 0 deletions subsys/shell/backends/shell_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ static int read(const struct shell_transport *transport,
#ifdef CONFIG_MCUMGR_TRANSPORT_SHELL
static void update(const struct shell_transport *transport)
{
/*
* This is dependent on the fact that `struct shell_uart_common`
* is always the first member, regardless of the UART configuration
*/
struct shell_uart_common *sh_uart = (struct shell_uart_common *)transport->ctx;

smp_shell_process(&sh_uart->smp);
Expand Down Expand Up @@ -583,6 +587,15 @@ SHELL_DEFINE(shell_uart, CONFIG_SHELL_PROMPT_UART, &shell_transport_uart,
CONFIG_SHELL_BACKEND_SERIAL_LOG_MESSAGE_QUEUE_TIMEOUT,
SHELL_FLAG_OLF_CRLF);

#ifdef CONFIG_MCUMGR_TRANSPORT_SHELL
struct smp_shell_data *shell_uart_smp_shell_data_get_ptr(void)
{
struct shell_uart_common *common = (struct shell_uart_common *)shell_transport_uart.ctx;

return &common->smp;
}
#endif

static int enable_shell_uart(void)
{
const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_shell_uart));
Expand Down

0 comments on commit 72fea5d

Please sign in to comment.