From 85e50658eab0798838cad86551a691d60044c39f Mon Sep 17 00:00:00 2001 From: Lephe Date: Tue, 6 Aug 2024 19:01:43 +0200 Subject: [PATCH] libc: provide the fxlibc HAL See 8cedf41 in fxlibc for rationale. --- CMakeLists.txt | 2 ++ src/fxlibc_hal.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/fxlibc_hal.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b2dd45..a2b4e91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,8 @@ endif() configure_file(include/gint/config.h.in include/gint/config.h) set(SOURCES + # Hardware Abstraction Layer for the standard library + src/fxlibc_hal.c # Clock Pulse Generator driver src/cpg/cpg.c src/cpg/overclock.c diff --git a/src/fxlibc_hal.c b/src/fxlibc_hal.c new file mode 100644 index 0000000..fed2498 --- /dev/null +++ b/src/fxlibc_hal.c @@ -0,0 +1,40 @@ +/* Hardware Abstraction Layer (HAL) implementation for fxlibc. We can group + this in a single file because LTO will prune away unused functions. */ + +#include +#include +#include +#include + +void *fxlibc_hal_malloc(size_t size) +{ + return kmalloc(size, NULL); +} + +void fxlibc_hal_free(void *ptr) +{ + return kfree(ptr); +} + +void *fxlibc_hal_realloc(void *ptr, size_t size) +{ + return krealloc(ptr, size); +} + +void fxlibc_hal_rawtime(struct tm *tm) +{ + rtc_time_t rtc; + rtc_get_time(&rtc); + tm->tm_sec = rtc.seconds; + tm->tm_min = rtc.minutes; + tm->tm_hour = rtc.hours; + tm->tm_mday = rtc.month_day; + tm->tm_mon = rtc.month; + tm->tm_year = rtc.year - 1900; + tm->tm_isdst = 0; +} + +clock_t fxlibc_hal_clock(void) +{ + return (CLOCKS_PER_SEC * (uint64_t)rtc_ticks()) / 128; +}