zephyr/include/shell/shell_uart.h
Krzysztof Chruscinski af973ca1e9 shell: enable UART backend without interrupts
Currently shell UART backend is interrupt driven if UART driver
is interrupt driven. That can be limitation if one instance
wants to use interrupts but shell UART should not.

Added option to shell uart to be able to control use of
interrupts. By default interrupts are enabled if driver
supports it.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-21 22:41:21 -05:00

90 lines
2.6 KiB
C

/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef SHELL_UART_H__
#define SHELL_UART_H__
#include <shell/shell.h>
#include <ring_buffer.h>
#include <atomic.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const struct shell_transport_api shell_uart_transport_api;
/** @brief Shell UART transport instance control block (RW data). */
struct shell_uart_ctrl_blk {
struct device *dev;
shell_transport_handler_t handler;
void *context;
atomic_t tx_busy;
bool blocking;
};
#ifdef CONFIG_SHELL_BACKEND_SERIAL_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_SHELL_BACKEND_SERIAL_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_SHELL_BACKEND_SERIAL_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 \
}
/**
* @brief This function provides pointer to shell uart backend instance.
*
* Function returns pointer to the shell uart instance. This instance can be
* next used with shell_execute_cmd function in order to test commands behavior.
*
* @returns Pointer to the shell instance.
*/
const struct shell *shell_backend_uart_get_ptr(void);
#ifdef __cplusplus
}
#endif
#endif /* SHELL_UART_H__ */