libc: provide the fxlibc HAL

See 8cedf41 in fxlibc for rationale.
This commit is contained in:
Lephe 2024-08-06 19:01:43 +02:00
parent b0c4e6fd2f
commit 85e50658ea
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
2 changed files with 42 additions and 0 deletions

View file

@ -23,6 +23,8 @@ endif()
configure_file(include/gint/config.h.in include/gint/config.h) configure_file(include/gint/config.h.in include/gint/config.h)
set(SOURCES set(SOURCES
# Hardware Abstraction Layer for the standard library
src/fxlibc_hal.c
# Clock Pulse Generator driver # Clock Pulse Generator driver
src/cpg/cpg.c src/cpg/cpg.c
src/cpg/overclock.c src/cpg/overclock.c

40
src/fxlibc_hal.c Normal file
View file

@ -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 <fxlibc/hal.h>
#include <gint/rtc.h>
#include <gint/kmalloc.h>
#include <errno.h>
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;
}