aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-02-04 00:05:50 -0700
committerChristian Cunningham <cc@localhost>2022-02-04 00:05:50 -0700
commitcfebe5feb55777bb377ff310b8cde03f3e0c25ff (patch)
tree7877e930627b5665431ed2104fb79e20a8ef1159
parentf4f23afb28268570d0da7f70bda6d2bcf760f839 (diff)
Access Uart through rotating buffer
-rw-r--r--include/drivers/uart.h3
-rw-r--r--src/cpu/irq.c3
-rw-r--r--src/drivers/uart.c38
-rw-r--r--src/sys/core.c1
4 files changed, 45 insertions, 0 deletions
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 <drivers/uart.h>
+#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