Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
shell_uart.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
12
13#ifndef ZEPHYR_INCLUDE_SHELL_SHELL_UART_H_
14#define ZEPHYR_INCLUDE_SHELL_SHELL_UART_H_
15
18#include <zephyr/shell/shell.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
25extern const struct shell_transport_api shell_uart_transport_api;
26
27#ifndef CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE
28#define CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE 0
29#endif
30
31#ifndef CONFIG_SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE
32#define CONFIG_SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE 0
33#endif
34
35#ifndef CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_COUNT
36#define CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_COUNT 0
37#endif
38
39#ifndef CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_SIZE
40#define CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_SIZE 0
41#endif
42
43#define ASYNC_RX_BUF_SIZE (CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_COUNT * \
44 (CONFIG_SHELL_BACKEND_SERIAL_ASYNC_RX_BUFFER_SIZE + \
45 UART_ASYNC_RX_BUF_OVERHEAD))
46
47struct shell_uart_common {
48 const struct device *dev;
50 void *context;
51 bool blocking_tx;
52#ifdef CONFIG_MCUMGR_TRANSPORT_SHELL
53 struct smp_shell_data smp;
54#endif /* CONFIG_MCUMGR_TRANSPORT_SHELL */
55};
56
57struct shell_uart_int_driven {
58 struct shell_uart_common common;
59 struct ring_buf tx_ringbuf;
60 struct ring_buf rx_ringbuf;
61 uint8_t tx_buf[CONFIG_SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE];
62 uint8_t rx_buf[CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE];
63 struct k_timer dtr_timer;
64 atomic_t tx_busy;
65};
66
67struct shell_uart_async {
68 struct shell_uart_common common;
69 struct k_sem sem;
70 struct k_spinlock lock;
71 struct uart_async_rx async_rx;
72 struct uart_async_rx_config async_rx_config;
73 atomic_t pending_rx_req;
74 volatile bool rx_enabled;
75 bool shell_enabled;
76 uint8_t rx_data[ASYNC_RX_BUF_SIZE];
77};
78
79struct shell_uart_polling {
80 struct shell_uart_common common;
81 struct ring_buf rx_ringbuf;
82 uint8_t rx_buf[CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE];
83 struct k_timer rx_timer;
84};
85
86#ifdef CONFIG_SHELL_BACKEND_SERIAL_API_POLLING
87#define SHELL_UART_STRUCT struct shell_uart_polling
88#elif defined(CONFIG_SHELL_BACKEND_SERIAL_API_ASYNC)
89#define SHELL_UART_STRUCT struct shell_uart_async
90#else
91#define SHELL_UART_STRUCT struct shell_uart_int_driven
92#endif
94
101
108#define SHELL_UART_DEFINE(_name, ...) \
109 static SHELL_UART_STRUCT _name##_shell_uart; \
110 struct shell_transport _name = { \
111 .api = &shell_uart_transport_api, \
112 .ctx = (struct shell_telnet *)&_name##_shell_uart, \
113 }
114
124
131
133
134#ifdef __cplusplus
135}
136#endif
137
138#endif /* ZEPHYR_INCLUDE_SHELL_SHELL_UART_H_ */
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
void(* shell_transport_handler_t)(enum shell_transport_evt evt, void *context)
Shell transport event handler callback.
Definition shell.h:831
struct smp_shell_data * shell_uart_smp_shell_data_get_ptr(void)
This function provides pointer to the smp shell data of the UART shell transport.
const struct shell * shell_backend_uart_get_ptr(void)
This function provides pointer to the shell UART backend instance.
Header file for the shell subsystem.
Shell transport for the mcumgr SMP protocol.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Unified shell transport interface.
Definition shell.h:864
Shell instance internals.
Definition shell.h:1129
Data used by SMP shell.
Definition smp_shell.h:33
Helper module for receiving using UART Asynchronous API.