From fb068f6e4e7d028501198e2abb0a7c5522207768 Mon Sep 17 00:00:00 2001 From: Michal Sieron Date: Mon, 9 Jan 2023 16:24:06 +0100 Subject: [PATCH] liblitedram: create utils.c Right now there are only `print_size` and `print_progress` functions from memtest.c, but changed to use uint64_t. Signed-off-by: Michal Sieron --- litex/soc/software/liblitedram/Makefile | 2 +- litex/soc/software/liblitedram/utils.c | 28 +++++++++++++++++++++++++ litex/soc/software/liblitedram/utils.h | 12 +++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 litex/soc/software/liblitedram/utils.c create mode 100644 litex/soc/software/liblitedram/utils.h diff --git a/litex/soc/software/liblitedram/Makefile b/litex/soc/software/liblitedram/Makefile index 0f26d194b..51c3e8952 100644 --- a/litex/soc/software/liblitedram/Makefile +++ b/litex/soc/software/liblitedram/Makefile @@ -1,7 +1,7 @@ include ../include/generated/variables.mak include $(SOC_DIRECTORY)/software/common.mak -OBJECTS = sdram.o bist.o sdram_dbg.o sdram_spd.o +OBJECTS = sdram.o bist.o sdram_dbg.o sdram_spd.o utils.o all: liblitedram.a diff --git a/litex/soc/software/liblitedram/utils.c b/litex/soc/software/liblitedram/utils.c new file mode 100644 index 000000000..7ffa5c749 --- /dev/null +++ b/litex/soc/software/liblitedram/utils.c @@ -0,0 +1,28 @@ +// This file is Copyright (c) 2023 Antmicro +// License: BSD + +#include + +#include + +#define KIB 1024 +#define MIB (KIB*1024) +#define GIB (MIB*1024) + +void print_size(uint64_t size) { + if (size < KIB) + printf("%lluB", size); + else if (size < MIB) + printf("%llu.%lluKiB", size/KIB, (size/1 - KIB*(size/KIB))/(KIB/10)); + else if (size < GIB) + printf("%llu.%lluMiB", size/MIB, (size/KIB - KIB*(size/MIB))/(KIB/10)); + else + printf("%llu.%lluGiB", size/GIB, (size/MIB - KIB*(size/GIB))/(KIB/10)); +} + +void print_progress(const char * header, uint64_t origin, uint64_t size) +{ + printf("%s 0x%llx-0x%llx ", header, origin, origin + size); + print_size(size); + printf(" \r"); +} diff --git a/litex/soc/software/liblitedram/utils.h b/litex/soc/software/liblitedram/utils.h new file mode 100644 index 000000000..68235563b --- /dev/null +++ b/litex/soc/software/liblitedram/utils.h @@ -0,0 +1,12 @@ +// This file is Copyright (c) 2023 Antmicro +// License: BSD + +#ifndef __SDRAM_UTILS_H +#define __SDRAM_UTILS_H + +#include + +void print_size(uint64_t size); +void print_progress(const char * header, uint64_t origin, uint64_t size); + +#endif /* __SDRAM_UTILS_H */