From af973ca1e9c1b2da67d416e80ad0408bbd5c1d87 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Wed, 21 Nov 2018 09:16:56 +0100 Subject: [PATCH] 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 --- include/shell/shell_uart.h | 6 +++--- subsys/shell/Kconfig.backends | 11 +++++------ subsys/shell/shell_uart.c | 16 ++++++++-------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/shell/shell_uart.h b/include/shell/shell_uart.h index 1554b1b37fe..c4fe563d9d4 100644 --- a/include/shell/shell_uart.h +++ b/include/shell/shell_uart.h @@ -26,7 +26,7 @@ struct shell_uart_ctrl_blk { bool blocking; }; -#ifdef CONFIG_UART_INTERRUPT_DRIVEN +#ifdef CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN #define UART_SHELL_TX_RINGBUF_DECLARE(_name, _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 -#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_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 */ +#endif /* CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN */ /** @brief Shell UART transport instance structure. */ struct shell_uart { diff --git a/subsys/shell/Kconfig.backends b/subsys/shell/Kconfig.backends index c68fd91bf70..9e014b4bbcb 100644 --- a/subsys/shell/Kconfig.backends +++ b/subsys/shell/Kconfig.backends @@ -25,16 +25,15 @@ config SHELL_BACKEND_SERIAL if SHELL_BACKEND_SERIAL # Internal config to enable UART interrupts if supported. -config SHELL_BACKEND_SERIAL_FORCE_INTERRUPTS - bool - default y +config SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN + bool "Interrupt driven" + default y if UART_INTERRUPT_DRIVEN depends on SERIAL_SUPPORT_INTERRUPT - imply UART_INTERRUPT_DRIVEN config SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE int "Set TX ring buffer size" default 8 - depends on UART_INTERRUPT_DRIVEN + depends on SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN help If UART is utilizing DMA transfers then increasing ring buffer size 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 int "RX polling period (in milliseconds)" default 10 - depends on !UART_INTERRUPT_DRIVEN + depends on !SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN help Determines how often UART is polled for RX byte. diff --git a/subsys/shell/shell_uart.c b/subsys/shell/shell_uart.c index 4533dcf3493..c59ec4e3552 100644 --- a/subsys/shell/shell_uart.c +++ b/subsys/shell/shell_uart.c @@ -24,7 +24,7 @@ SHELL_UART_DEFINE(shell_transport_uart, SHELL_DEFINE(shell_uart, "uart:~$ ", &shell_transport_uart, 10, 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) { u8_t *data; @@ -99,11 +99,11 @@ static void uart_callback(void *user_data) 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) { -#ifdef CONFIG_UART_INTERRUPT_DRIVEN +#ifdef CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN struct device *dev = sh_uart->ctrl_blk->dev; 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->context = context; - if (IS_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN)) { + if (IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN)) { uart_irq_init(sh_uart); } else { 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; if (blocking) { - if (!IS_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN)) { + if (!IS_ENABLED(CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN)) { 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_tx_disable(sh_uart->ctrl_blk->dev); #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); 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); #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 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) { irq_write(sh_uart, data, length, cnt); } else {