aboutsummaryrefslogtreecommitdiff
path: root/lib/pbdrv/ext
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-18 17:29:25 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-18 17:29:25 +0200
commit3f3bef9c6bf0b9143da80e4b4363eb0362fb91c9 (patch)
treec4344b281fd589690b6b82bc6b5c2e91a4f2a13f /lib/pbdrv/ext
parentc1007f50de3ad7284d4a1afa6bfb3b6e427c3556 (diff)
clean up code for getting main controller compiling again
Diffstat (limited to 'lib/pbdrv/ext')
-rw-r--r--lib/pbdrv/ext/freertos/include.cmake10
-rw-r--r--lib/pbdrv/ext/freertos/pb-mem.c31
-rw-r--r--lib/pbdrv/ext/freertos/pb-mod.c9
-rw-r--r--lib/pbdrv/ext/stdlib/include.cmake4
-rw-r--r--lib/pbdrv/ext/stdlib/pb-mem.c26
5 files changed, 80 insertions, 0 deletions
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 <FreeRTOS.h>
+
+#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 <FreeRTOS.h>
+#include <task.h>
+
+#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 <stdlib.h>
+#include <string.h>
+
+#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);
+}
+