mmserv

Minimum Mean Square Error detection on RISC-V Vector Extention
git clone https://git.ea.contact/mmserv
Log | Files | Refs | README

commit e65c6263319420507cf37fe3f5f32659e1991818
parent 489cc4ae3b6e71f23136be900bd8f871bb2c271d
Author: Egor Achkasov <eaachkasov@gmail.com>
Date:   Wed, 28 May 2025 02:09:54 +0200

Impl U-Boot printf

Diffstat:
Mmain.c | 48+++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/main.c b/main.c @@ -95,10 +95,56 @@ uint64_t readcycle() { #if defined(PLATFORM_ara) #include "../../common/printf.h" + #elif defined(PLATFORM_linux) #include <stdio.h> + #elif defined(PLATFORM_baremetal) -/* TODO */ +#include <common.h> /* This is U-Boot's common.h, not our "include/common.h" */ +#include <asm/io.h> + +/* UART registers for SpacemiT K1 */ +#define UART_BASE 0x1510000000ULL +#define UART_THR (UART_BASE + 0x00) /* Transmit Holding Register */ +#define UART_LSR (UART_BASE + 0x14) /* Line Status Register */ +#define UART_LSR_THRE (1 << 5) /* Transmit Holding Register Empty */ + +static void uart_putc(char c) { + while (!(readl(UART_LSR) & UART_LSR_THRE)); /* Wait for THR empty */ + writel(c, UART_THR); +} +static void print_ulong(unsigned long num) { + char buf[20]; + int i = 0; + if (num == 0) { + uart_putc('0'); + return; + } + while (num > 0) { + buf[i++] = (num % 10) + '0'; + num /= 10; + } + while (i > 0) { + uart_putc(buf[--i]); + } +} +/* U-Boot printf for %lu,%lu,%lu,%lu,%lu, */ +void printf(const char *fmt, unsigned long t1, unsigned long t2, unsigned long t3, + unsigned long t4, unsigned long t5) { + if (strcmp(fmt, "%lu,%lu,%lu,%lu,%lu,") != 0) + return; + print_ulong(t1); + uart_putc(','); + print_ulong(t2); + uart_putc(','); + print_ulong(t3); + uart_putc(','); + print_ulong(t4); + uart_putc(','); + print_ulong(t5); + uart_putc(','); +} + #else #error "Unknown platform" #endif