From 3f3bef9c6bf0b9143da80e4b4363eb0362fb91c9 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 18 Jun 2024 17:29:25 +0200 Subject: clean up code for getting main controller compiling again --- lib/pbdrv/ext/freertos/include.cmake | 10 ++++++++++ lib/pbdrv/ext/freertos/pb-mem.c | 31 +++++++++++++++++++++++++++++++ lib/pbdrv/ext/freertos/pb-mod.c | 9 +++++++++ lib/pbdrv/ext/stdlib/include.cmake | 4 ++++ lib/pbdrv/ext/stdlib/pb-mem.c | 26 ++++++++++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 lib/pbdrv/ext/freertos/include.cmake create mode 100644 lib/pbdrv/ext/freertos/pb-mem.c create mode 100644 lib/pbdrv/ext/freertos/pb-mod.c create mode 100644 lib/pbdrv/ext/stdlib/include.cmake create mode 100644 lib/pbdrv/ext/stdlib/pb-mem.c (limited to 'lib/pbdrv/ext') diff --git a/lib/pbdrv/ext/freertos/include.cmake b/lib/pbdrv/ext/freertos/include.cmake new file mode 100644 index 0000000..d01afe7 --- /dev/null +++ b/lib/pbdrv/ext/freertos/include.cmake @@ -0,0 +1,10 @@ +target_sources(pbdrv-mod PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/pb-mem.c" + "${CMAKE_CURRENT_LIST_DIR}/pb-mod.c" + ) +target_link_libraries(pbdrv-mod + freertos_kernel + freertos_kernel_include + freertos_config + ) + diff --git a/lib/pbdrv/ext/freertos/pb-mem.c b/lib/pbdrv/ext/freertos/pb-mem.c new file mode 100644 index 0000000..96c48d1 --- /dev/null +++ b/lib/pbdrv/ext/freertos/pb-mem.c @@ -0,0 +1,31 @@ +#include + +#include "../../pb-mem.h" +#include "../../pb-types.h" + +__weak inline void * pb_malloc(size_t sz) { + return pvPortMalloc(sz); +} + +__weak inline void pb_free(void * ptr) { + vPortFree(ptr); +} + +__weak inline void * pb_realloc(void * ptr, size_t sz) { + return NULL; // shit out of luck (don't use mpack_writer_init_growable) +} + +__weak void * pb_memcpy(void * dest, const void * src, size_t sz) { + for (size_t offset = 0; offset < sz; offset++) + *((char*) dest + offset) = *((char*) src + offset); + return dest; +} + +int pb_memcmp(const void * a, const void * b, size_t sz) { + for (size_t offset = 0; offset < sz; offset++) { + int diff = *((char*) a + offset) - *((char*) b + offset); + if (diff != 0) return diff; + } + return 0; +} + diff --git a/lib/pbdrv/ext/freertos/pb-mod.c b/lib/pbdrv/ext/freertos/pb-mod.c new file mode 100644 index 0000000..75495be --- /dev/null +++ b/lib/pbdrv/ext/freertos/pb-mod.c @@ -0,0 +1,9 @@ +#include +#include + +#include "../../pb-types.h" + +__weak void pb_mod_blocking_delay_ms(unsigned long ms) { + vTaskDelay(ms / portTICK_PERIOD_MS); +} + diff --git a/lib/pbdrv/ext/stdlib/include.cmake b/lib/pbdrv/ext/stdlib/include.cmake new file mode 100644 index 0000000..fce788d --- /dev/null +++ b/lib/pbdrv/ext/stdlib/include.cmake @@ -0,0 +1,4 @@ +target_sources(pbdrv-mod PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/pb-mem.c" + ) + diff --git a/lib/pbdrv/ext/stdlib/pb-mem.c b/lib/pbdrv/ext/stdlib/pb-mem.c new file mode 100644 index 0000000..1f59a84 --- /dev/null +++ b/lib/pbdrv/ext/stdlib/pb-mem.c @@ -0,0 +1,26 @@ +#include +#include + +#include "../../pb-mem.h" +#include "../../pb-types.h" + +__weak inline void * pb_malloc(size_t sz) { + return malloc(sz); +} + +__weak inline void pb_free(void * ptr) { + free(ptr); +} + +__weak inline void * pb_realloc(void * ptr, size_t sz) { + return realloc(ptr, sz); +} + +__weak void * pb_memcpy(void * dest, const void * src, size_t sz) { + return memcpy(dest, src, sz); +} + +int pb_memcmp(const void * a, const void * b, size_t sz) { + return memcmp(a, b, sz); +} + -- cgit v1.2.3