aboutsummaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/uart.c38
1 files changed, 38 insertions, 0 deletions
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;