From cfebe5feb55777bb377ff310b8cde03f3e0c25ff Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Fri, 4 Feb 2022 00:05:50 -0700 Subject: Access Uart through rotating buffer --- include/drivers/uart.h | 3 +++ src/cpu/irq.c | 3 +++ src/drivers/uart.c | 38 ++++++++++++++++++++++++++++++++++++++ src/sys/core.c | 1 + 4 files changed, 45 insertions(+) diff --git a/include/drivers/uart.h b/include/drivers/uart.h index b83732f..1491f20 100644 --- a/include/drivers/uart.h +++ b/include/drivers/uart.h @@ -9,6 +9,9 @@ extern void uart_char(unsigned char c); extern void uart_string(char* message); extern void uart_hex(unsigned long data); +void uart_init(); +void* uart_print(char*); +void uart_flush(void); void uart_10(unsigned long); void uart_hexn(unsigned long); diff --git a/src/cpu/irq.c b/src/cpu/irq.c index 2197067..15603b9 100644 --- a/src/cpu/irq.c +++ b/src/cpu/irq.c @@ -84,6 +84,9 @@ unsigned long c_fiq_handler(void) if (counter % 0x6000 == 0) { counter = 0; } + if (counter % 0x8 == 0) { + add_thread(uart_flush, 0, 5); + } if (counter % 0x30 == 0) { return 1; } diff --git a/src/drivers/uart.c b/src/drivers/uart.c index f6fe79b..c5514ce 100644 --- a/src/drivers/uart.c +++ b/src/drivers/uart.c @@ -1,5 +1,43 @@ #include +#define UART_BUFFER_SIZE 0x100 +struct UartBuffer { + char buffer[UART_BUFFER_SIZE]; + unsigned long roffset; + unsigned long woffset; +} ubuffer; + +void uart_init(void) +{ + ubuffer.roffset = 0; + ubuffer.woffset = 0; +} + +// s = zero-terminated string +void* uart_print(char* s) +{ + char* ptr = s; + while (1) { + if (*ptr == 0) + break; + ubuffer.buffer[ubuffer.woffset] = *ptr; + if ((ubuffer.woffset+1)%UART_BUFFER_SIZE == ubuffer.roffset) + return ptr; + ubuffer.woffset++; + ubuffer.woffset %= UART_BUFFER_SIZE; + ptr += 1; + } + return 0; +} + +void uart_flush(void) +{ + while (ubuffer.roffset != ubuffer.woffset) { + uart_char(ubuffer.buffer[ubuffer.roffset++]); + ubuffer.roffset %= UART_BUFFER_SIZE; + } +} + void uart_10(unsigned long val) { unsigned long t = val; diff --git a/src/sys/core.c b/src/sys/core.c index b29412f..d761336 100644 --- a/src/sys/core.c +++ b/src/sys/core.c @@ -28,6 +28,7 @@ void sysinit(void) stimeh = *(unsigned long*)SYS_TIMER_CHI; stimel = *(unsigned long*)SYS_TIMER_CLO; *(unsigned long*) SYS_TIMER_C0 = 60000000 + stimeh; // 60 second trigger + uart_init(); ///... // Route GPU interrupts to Core 0 -- cgit v1.2.1