shell: shell_uart: add ring_buffers and interrupt support
Improved RX path to use ring buffer for incoming data instead of single byte buffer. Improved TX path to use ring buffer. Added support for asynchronous UART API (interrupts). Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
79095099bb
commit
4962618e5f
4 changed files with 238 additions and 38 deletions
|
@ -8,6 +8,8 @@
|
|||
#define SHELL_UART_H__
|
||||
|
||||
#include <shell/shell.h>
|
||||
#include <ring_buffer.h>
|
||||
#include <atomic.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -15,17 +17,56 @@ extern "C" {
|
|||
|
||||
extern const struct shell_transport_api shell_uart_transport_api;
|
||||
|
||||
struct shell_uart {
|
||||
/** @brief Shell UART transport instance control block (RW data). */
|
||||
struct shell_uart_ctrl_blk {
|
||||
struct device *dev;
|
||||
shell_transport_handler_t handler;
|
||||
struct k_timer timer;
|
||||
void *context;
|
||||
u8_t rx[1];
|
||||
size_t rx_cnt;
|
||||
atomic_t tx_busy;
|
||||
bool blocking;
|
||||
};
|
||||
|
||||
#define SHELL_UART_DEFINE(_name) \
|
||||
static struct shell_uart _name##_shell_uart; \
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
#define UART_SHELL_TX_RINGBUF_DECLARE(_name, _size) \
|
||||
RING_BUF_DECLARE(_name##_tx_ringbuf, _size)
|
||||
|
||||
#define UART_SHELL_TX_BUF_DECLARE(_name) \
|
||||
u8_t _name##_txbuf[SHELL_UART_TX_BUF_SIZE]
|
||||
|
||||
#define UART_SHELL_RX_TIMER_DECLARE(_name) /* Empty */
|
||||
|
||||
#define UART_SHELL_TX_RINGBUF_PTR(_name) (&_name##_tx_ringbuf)
|
||||
|
||||
#define UART_SHELL_RX_TIMER_PTR(_name) NULL
|
||||
|
||||
#else /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
#define UART_SHELL_TX_RINGBUF_DECLARE(_name, _size) /* Empty */
|
||||
#define UART_SHELL_TX_BUF_DECLARE(_name) /* Empty */
|
||||
#define UART_SHELL_RX_TIMER_DECLARE(_name) static struct k_timer _name##_timer
|
||||
#define UART_SHELL_TX_RINGBUF_PTR(_name) NULL
|
||||
#define UART_SHELL_RX_TIMER_PTR(_name) (&_name##_timer)
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
|
||||
/** @brief Shell UART transport instance structure. */
|
||||
struct shell_uart {
|
||||
struct shell_uart_ctrl_blk *ctrl_blk;
|
||||
struct k_timer *timer;
|
||||
struct ring_buf *tx_ringbuf;
|
||||
struct ring_buf *rx_ringbuf;
|
||||
};
|
||||
|
||||
/** @brief Macro for creating shell UART transport instance. */
|
||||
#define SHELL_UART_DEFINE(_name, _tx_ringbuf_size, _rx_ringbuf_size) \
|
||||
static struct shell_uart_ctrl_blk _name##_ctrl_blk; \
|
||||
UART_SHELL_RX_TIMER_DECLARE(_name); \
|
||||
UART_SHELL_TX_RINGBUF_DECLARE(_name, _tx_ringbuf_size); \
|
||||
RING_BUF_DECLARE(_name##_rx_ringbuf, _rx_ringbuf_size); \
|
||||
static const struct shell_uart _name##_shell_uart = { \
|
||||
.ctrl_blk = &_name##_ctrl_blk, \
|
||||
.timer = UART_SHELL_RX_TIMER_PTR(_name), \
|
||||
.tx_ringbuf = UART_SHELL_TX_RINGBUF_PTR(_name), \
|
||||
.rx_ringbuf = &_name##_rx_ringbuf, \
|
||||
}; \
|
||||
struct shell_transport _name = { \
|
||||
.api = &shell_uart_transport_api, \
|
||||
.ctx = (struct shell_uart *)&_name##_shell_uart \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue