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:
Krzysztof Chruscinski 2018-11-21 09:16:56 +01:00 committed by Anas Nashif
commit af973ca1e9
3 changed files with 16 additions and 17 deletions

View file

@ -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 {