/* console.c — portable text output built on arch_uart_putc(). * No libc: we implement the tiny bit of formatting we need. */ #include "arch.h" #include "console.h" void putc(char c) { if (c == '\n') arch_uart_putc('\r'); /* CRLF for dumb terminals */ arch_uart_putc(c); } void puts(const char *s) { while (*s) putc(*s++); } /* Read one byte from the UART. Portable wrapper over arch_uart_getc(). */ char getc(void) { return arch_uart_getc(); } /* Discard any bytes currently waiting in the RX FIFO. Used to drop the * bytes our own TX echoes back on half-duplex-wired boards before we start * reading real keystrokes. */ void drain_rx(void) { while (arch_uart_rx_ready()) (void)arch_uart_getc(); } /* Minimal unsigned hex printer — enough to show addresses/registers. */ void puthex(unsigned long v) { static const char d[] = "0123456789abcdef"; int i; puts("0x"); for (i = (int)(sizeof(v) * 2) - 1; i >= 0; i--) putc(d[(v >> (i * 4)) & 0xf]); }