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 <msieron@antmicro.com>
This commit is contained in:
parent
2bdf04c19e
commit
fb068f6e4e
|
@ -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
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// This file is Copyright (c) 2023 Antmicro <www.antmicro.com>
|
||||
// License: BSD
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <liblitedram/utils.h>
|
||||
|
||||
#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");
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
// This file is Copyright (c) 2023 Antmicro <www.antmicro.com>
|
||||
// License: BSD
|
||||
|
||||
#ifndef __SDRAM_UTILS_H
|
||||
#define __SDRAM_UTILS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void print_size(uint64_t size);
|
||||
void print_progress(const char * header, uint64_t origin, uint64_t size);
|
||||
|
||||
#endif /* __SDRAM_UTILS_H */
|
Loading…
Reference in New Issue