From 4f32bbc46a48276bba949364dc44d532c19dae78 Mon Sep 17 00:00:00 2001 From: taitep Date: Thu, 29 Jan 2026 21:27:36 +0100 Subject: i think i managed to make a working uart driver for the new interface?? --- src/crt0.S | 3 +++ src/syscalls.c | 16 +++++++++++----- src/uart.c | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/uart.c (limited to 'src') diff --git a/src/crt0.S b/src/crt0.S index 97228c1..49d8493 100644 --- a/src/crt0.S +++ b/src/crt0.S @@ -62,6 +62,9 @@ _start: #endif call __libc_init_array # Run global initialization functions + # initialize UART + call uart_init + call main call exit _exit: j _exit diff --git a/src/syscalls.c b/src/syscalls.c index 443c9cd..5c5d577 100644 --- a/src/syscalls.c +++ b/src/syscalls.c @@ -44,17 +44,21 @@ int _lseek(int file, int ptr, int dir) { return 0; } int _open(const char *name, int flags, int mode) { return -1; } int _read(int file, char *buf, int len) { - while (!uart_rx_ready()) - ; + uint32_t uart_data; + do { + uart_data = UART_RXDATA; + } while (uart_data & UART_RXDATA_EMPTY); int i; for (i = 0; i < len; i++) { - if (!uart_rx_ready()) { + buf[i] = (char)uart_data; + uart_data = UART_RXDATA; + if (uart_data & UART_RXDATA_EMPTY) { break; } - buf[i] = uart_getc_nonblocking(); } - return i; + // *(volatile int *)1 = i; + return i + 1; } void *_sbrk(int incr) { @@ -91,9 +95,11 @@ int _wait(int *status) { } int _write(int file, char *buf, int len) { + // uart_puts("_write called\n"); for (int i = 0; i < len; i++) { uart_putc(buf[i]); } + // *(volatile int *)0 = len; return len; } diff --git a/src/uart.c b/src/uart.c new file mode 100644 index 0000000..86bc01f --- /dev/null +++ b/src/uart.c @@ -0,0 +1,24 @@ +#include "uart.h" + +void uart_init(void) { + UART_TXCTRL = UART_TXCTRL_TXEN; + UART_RXCTRL = UART_RXCTRL_RXEN; +} + +void uart_putc(char c) { + while (UART_TXDATA & UART_TXDATA_FULL) {} + UART_TXDATA = (uint32_t)c; +} + +void uart_puts(const char* s) { + while (*s) + uart_putc(*s++); +} + +char uart_getc(void) { + uint32_t data; + do { + data = UART_RXDATA; + } while (data & UART_RXDATA_EMPTY); + return (char)data; +} -- cgit v1.2.3