shell: backends: uart: add public function to access smp shell data

`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 <ycsin@meta.com>
This commit is contained in:
Yong Cong Sin 2023-11-15 17:51:46 +08:00 committed by Carles Cufí
commit 72fea5df56
3 changed files with 22 additions and 4 deletions

View file

@ -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
@ -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

View file

@ -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);

View file

@ -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);
@ -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));