diff options
author | Gurjant Kalsi <me@gurjantkalsi.com> | 2016-06-02 15:59:43 -0700 |
---|---|---|
committer | Gurjant Kalsi <me@gurjantkalsi.com> | 2016-06-02 16:01:56 -0700 |
commit | bb4c6402b05e08d1103e999c6f482da808a0efaf (patch) | |
tree | 9da3a57530cb81ab6ab2eedff258381b6727a63c /platform | |
parent | a6ab56cd5f1bf46111cc3c33d59ecfa963812524 (diff) | |
download | common-bb4c6402b05e08d1103e999c6f482da808a0efaf.tar.gz |
[console][io] Add an optional global input queue.
In this model, getc reads from a global input buffer and the uart posts data to this buffer.
This commit also enables the global input queue for STM32F7 and QEMU-Virt.
Tested on STM32F7/Dartuino and QEMU-ARM A15 with both CONSOLE_HAS_INPUT_BUFFER=1 and CONSOLE_HAS_INPUT_BUFFER=0
Diffstat (limited to 'platform')
-rw-r--r-- | platform/qemu-virt/rules.mk | 3 | ||||
-rw-r--r-- | platform/qemu-virt/uart.c | 23 | ||||
-rw-r--r-- | platform/stm32f7xx/rules.mk | 3 | ||||
-rw-r--r-- | platform/stm32f7xx/uart.c | 17 |
4 files changed, 33 insertions, 13 deletions
diff --git a/platform/qemu-virt/rules.mk b/platform/qemu-virt/rules.mk index a19fdddd..fd588d15 100644 --- a/platform/qemu-virt/rules.mk +++ b/platform/qemu-virt/rules.mk @@ -37,7 +37,8 @@ MODULE_DEPS += \ GLOBAL_DEFINES += \ MEMBASE=$(MEMBASE) \ MEMSIZE=$(MEMSIZE) \ - PLATFORM_SUPPORTS_PANIC_SHELL=1 + PLATFORM_SUPPORTS_PANIC_SHELL=1 \ + CONSOLE_HAS_INPUT_BUFFER=1 GLOBAL_DEFINES += MMU_WITH_TRAMPOLINE=1 \ diff --git a/platform/qemu-virt/uart.c b/platform/qemu-virt/uart.c index b39e186e..4eebe102 100644 --- a/platform/qemu-virt/uart.c +++ b/platform/qemu-virt/uart.c @@ -28,6 +28,7 @@ #include <platform/interrupts.h> #include <platform/debug.h> #include <platform/qemu-virt.h> +#include <target/debugconfig.h> /* PL011 implementation */ #define UART_DR (0x00) @@ -75,15 +76,23 @@ static enum handler_return uart_irq(void *arg) /* while fifo is not empty, read chars out of it */ while ((UARTREG(base, UART_TFR) & (1<<4)) == 0) { - /* if we're out of rx buffer, mask the irq instead of handling it */ - if (cbuf_space_avail(rxbuf) == 0) { - UARTREG(base, UART_IMSC) &= ~(1<<4); // !rxim - break; +#if CONSOLE_HAS_INPUT_BUFFER + if (port == DEBUG_UART) { + char c = UARTREG(base, UART_DR); + cbuf_write_char(&console_input_cbuf, c, false); + } else +#endif + { + /* if we're out of rx buffer, mask the irq instead of handling it */ + if (cbuf_space_avail(rxbuf) == 0) { + UARTREG(base, UART_IMSC) &= ~(1<<4); // !rxim + break; + } + + char c = UARTREG(base, UART_DR); + cbuf_write_char(rxbuf, c, false); } - char c = UARTREG(base, UART_DR); - cbuf_write_char(rxbuf, c, false); - resched = true; } } diff --git a/platform/stm32f7xx/rules.mk b/platform/stm32f7xx/rules.mk index f040a492..27c033cd 100644 --- a/platform/stm32f7xx/rules.mk +++ b/platform/stm32f7xx/rules.mk @@ -34,7 +34,8 @@ LK_HEAP_IMPLEMENTATION ?= miniheap GLOBAL_DEFINES += \ PLATFORM_SUPPORTS_PANIC_SHELL=1 \ - NOVM_MAX_ARENAS=2 + NOVM_MAX_ARENAS=2 \ + CONSOLE_HAS_INPUT_BUFFER=1 MODULE_SRCS += \ $(LOCAL_DIR)/debug.c \ diff --git a/platform/stm32f7xx/uart.c b/platform/stm32f7xx/uart.c index 33d86600..257cc3ec 100644 --- a/platform/stm32f7xx/uart.c +++ b/platform/stm32f7xx/uart.c @@ -161,7 +161,7 @@ void uart_init(void) #endif } -static void stm32_usart_shared_irq(struct uart_instance *u) +static void stm32_usart_shared_irq(struct uart_instance *u, const unsigned int id) { bool resched = false; @@ -200,7 +200,16 @@ static void stm32_usart_shared_irq(struct uart_instance *u) /* we got a character */ uint8_t c = (uint8_t)(u->handle.Instance->RDR & 0xff); - if (cbuf_write_char(&u->rx_buf, c, false) != 1) { + + cbuf_t *target_buf = &u->rx_buf; + +#if CONSOLE_HAS_INPUT_BUFFER + if (id == DEBUG_UART) { + target_buf = &console_input_cbuf; + } +#endif + + if (cbuf_write_char(target_buf, c, false) != 1) { printf("WARNING: uart cbuf overrun!\n"); } resched = true; @@ -225,14 +234,14 @@ static void stm32_usart_shared_irq(struct uart_instance *u) #if ENABLE_UART1 void stm32_USART1_IRQ(void) { - stm32_usart_shared_irq(uart[1]); + stm32_usart_shared_irq(uart[1], 1); } #endif #if ENABLE_UART3 void stm32_USART3_IRQ(void) { - stm32_usart_shared_irq(uart[3]); + stm32_usart_shared_irq(uart[3], 3); } #endif |