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>
This commit is contained in:
parent
9cf8b3cd20
commit
af973ca1e9
3 changed files with 16 additions and 17 deletions
|
@ -26,7 +26,7 @@ struct shell_uart_ctrl_blk {
|
||||||
bool blocking;
|
bool blocking;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
#ifdef CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN
|
||||||
#define UART_SHELL_TX_RINGBUF_DECLARE(_name, _size) \
|
#define UART_SHELL_TX_RINGBUF_DECLARE(_name, _size) \
|
||||||
RING_BUF_DECLARE(_name##_tx_ringbuf, _size)
|
RING_BUF_DECLARE(_name##_tx_ringbuf, _size)
|
||||||
|
|
||||||
|
@ -39,13 +39,13 @@ struct shell_uart_ctrl_blk {
|
||||||
|
|
||||||
#define UART_SHELL_RX_TIMER_PTR(_name) NULL
|
#define UART_SHELL_RX_TIMER_PTR(_name) NULL
|
||||||
|
|
||||||
#else /* CONFIG_UART_INTERRUPT_DRIVEN */
|
#else /* CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN */
|
||||||
#define UART_SHELL_TX_RINGBUF_DECLARE(_name, _size) /* Empty */
|
#define UART_SHELL_TX_RINGBUF_DECLARE(_name, _size) /* Empty */
|
||||||
#define UART_SHELL_TX_BUF_DECLARE(_name) /* 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_RX_TIMER_DECLARE(_name) static struct k_timer _name##_timer
|
||||||
#define UART_SHELL_TX_RINGBUF_PTR(_name) NULL
|
#define UART_SHELL_TX_RINGBUF_PTR(_name) NULL
|
||||||
#define UART_SHELL_RX_TIMER_PTR(_name) (&_name##_timer)
|
#define UART_SHELL_RX_TIMER_PTR(_name) (&_name##_timer)
|
||||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
#endif /* CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN */
|
||||||
|
|
||||||
/** @brief Shell UART transport instance structure. */
|
/** @brief Shell UART transport instance structure. */
|
||||||
struct shell_uart {
|
struct shell_uart {
|
||||||
|
|
|
@ -25,16 +25,15 @@ config SHELL_BACKEND_SERIAL
|
||||||
if SHELL_BACKEND_SERIAL
|
if SHELL_BACKEND_SERIAL
|
||||||
|
|
||||||
# Internal config to enable UART interrupts if supported.
|
# Internal config to enable UART interrupts if supported.
|
||||||
config SHELL_BACKEND_SERIAL_FORCE_INTERRUPTS
|
config SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN
|
||||||
bool
|
bool "Interrupt driven"
|
||||||
default y
|
default y if UART_INTERRUPT_DRIVEN
|
||||||
depends on SERIAL_SUPPORT_INTERRUPT
|
depends on SERIAL_SUPPORT_INTERRUPT
|
||||||
imply UART_INTERRUPT_DRIVEN
|
|
||||||
|
|
||||||
config SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE
|
config SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE
|
||||||
int "Set TX ring buffer size"
|
int "Set TX ring buffer size"
|
||||||
default 8
|
default 8
|
||||||
depends on UART_INTERRUPT_DRIVEN
|
depends on SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN
|
||||||
help
|
help
|
||||||
If UART is utilizing DMA transfers then increasing ring buffer size
|
If UART is utilizing DMA transfers then increasing ring buffer size
|
||||||
increases transfers length and reduces number of interrupts.
|
increases transfers length and reduces number of interrupts.
|
||||||
|
@ -52,7 +51,7 @@ config SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE
|
||||||
config SHELL_BACKEND_SERIAL_RX_POLL_PERIOD
|
config SHELL_BACKEND_SERIAL_RX_POLL_PERIOD
|
||||||
int "RX polling period (in milliseconds)"
|
int "RX polling period (in milliseconds)"
|
||||||
default 10
|
default 10
|
||||||
depends on !UART_INTERRUPT_DRIVEN
|
depends on !SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN
|
||||||
help
|
help
|
||||||
Determines how often UART is polled for RX byte.
|
Determines how often UART is polled for RX byte.
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ SHELL_UART_DEFINE(shell_transport_uart,
|
||||||
SHELL_DEFINE(shell_uart, "uart:~$ ", &shell_transport_uart, 10,
|
SHELL_DEFINE(shell_uart, "uart:~$ ", &shell_transport_uart, 10,
|
||||||
SHELL_FLAG_OLF_CRLF);
|
SHELL_FLAG_OLF_CRLF);
|
||||||
|
|
||||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
#ifdef CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN
|
||||||
static void uart_rx_handle(const struct shell_uart *sh_uart)
|
static void uart_rx_handle(const struct shell_uart *sh_uart)
|
||||||
{
|
{
|
||||||
u8_t *data;
|
u8_t *data;
|
||||||
|
@ -99,11 +99,11 @@ static void uart_callback(void *user_data)
|
||||||
uart_tx_handle(sh_uart);
|
uart_tx_handle(sh_uart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
#endif /* CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN */
|
||||||
|
|
||||||
static void uart_irq_init(const struct shell_uart *sh_uart)
|
static void uart_irq_init(const struct shell_uart *sh_uart)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
#ifdef CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN
|
||||||
struct device *dev = sh_uart->ctrl_blk->dev;
|
struct device *dev = sh_uart->ctrl_blk->dev;
|
||||||
|
|
||||||
uart_irq_callback_user_data_set(dev, uart_callback, (void *)sh_uart);
|
uart_irq_callback_user_data_set(dev, uart_callback, (void *)sh_uart);
|
||||||
|
@ -137,7 +137,7 @@ static int init(const struct shell_transport *transport,
|
||||||
sh_uart->ctrl_blk->handler = evt_handler;
|
sh_uart->ctrl_blk->handler = evt_handler;
|
||||||
sh_uart->ctrl_blk->context = context;
|
sh_uart->ctrl_blk->context = context;
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN)) {
|
if (IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN)) {
|
||||||
uart_irq_init(sh_uart);
|
uart_irq_init(sh_uart);
|
||||||
} else {
|
} else {
|
||||||
k_timer_init(sh_uart->timer, timer_handler, NULL);
|
k_timer_init(sh_uart->timer, timer_handler, NULL);
|
||||||
|
@ -160,10 +160,10 @@ static int enable(const struct shell_transport *transport, bool blocking)
|
||||||
sh_uart->ctrl_blk->blocking = blocking;
|
sh_uart->ctrl_blk->blocking = blocking;
|
||||||
|
|
||||||
if (blocking) {
|
if (blocking) {
|
||||||
if (!IS_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN)) {
|
if (!IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN)) {
|
||||||
k_timer_stop(sh_uart->timer);
|
k_timer_stop(sh_uart->timer);
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
#ifdef CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN
|
||||||
uart_irq_rx_disable(sh_uart->ctrl_blk->dev);
|
uart_irq_rx_disable(sh_uart->ctrl_blk->dev);
|
||||||
uart_irq_tx_disable(sh_uart->ctrl_blk->dev);
|
uart_irq_tx_disable(sh_uart->ctrl_blk->dev);
|
||||||
#endif
|
#endif
|
||||||
|
@ -178,7 +178,7 @@ static void irq_write(const struct shell_uart *sh_uart, const void *data,
|
||||||
*cnt = ring_buf_put(sh_uart->tx_ringbuf, data, length);
|
*cnt = ring_buf_put(sh_uart->tx_ringbuf, data, length);
|
||||||
|
|
||||||
if (atomic_set(&sh_uart->ctrl_blk->tx_busy, 1) == 0) {
|
if (atomic_set(&sh_uart->ctrl_blk->tx_busy, 1) == 0) {
|
||||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
#ifdef CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN
|
||||||
uart_irq_tx_enable(sh_uart->ctrl_blk->dev);
|
uart_irq_tx_enable(sh_uart->ctrl_blk->dev);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ static int write(const struct shell_transport *transport,
|
||||||
const struct shell_uart *sh_uart = (struct shell_uart *)transport->ctx;
|
const struct shell_uart *sh_uart = (struct shell_uart *)transport->ctx;
|
||||||
const u8_t *data8 = (const u8_t *)data;
|
const u8_t *data8 = (const u8_t *)data;
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN) &&
|
if (IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN) &&
|
||||||
!sh_uart->ctrl_blk->blocking) {
|
!sh_uart->ctrl_blk->blocking) {
|
||||||
irq_write(sh_uart, data, length, cnt);
|
irq_write(sh_uart, data, length, cnt);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue