Unify all heaps (stdlib + LVGL + FreeRTOS) into a single heap managed by FreeRTOS and heap_4_infinitime.c.
LVGL supports custom implementation of malloc() and free() so using pvPortMalloc() and vPortFree() is just a matter of setting the right variables. Other libraries (NimBLE, LittleFS) and InfiniTime code (new) call malloc() and free() from stdlib. InfiniTime now provides the file stdlib.c that provides a custom implementation for malloc(), free(), calloc() and realloc(). This ensures that all calls to the standard allocator are redirected to the FreeRTOS memory manager. Note that realloc() is needed by NimBLE.main
parent
9e808a65ec
commit
1911e2d928
@ -0,0 +1,27 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <FreeRTOS.h>
|
||||||
|
|
||||||
|
// Override malloc() and free() to use the memory manager from FreeRTOS.
|
||||||
|
// According to the documentation of libc, we also need to override
|
||||||
|
// calloc and realloc.
|
||||||
|
// See https://www.gnu.org/software/libc/manual/html_node/Replacing-malloc.html
|
||||||
|
|
||||||
|
void* malloc(size_t size) {
|
||||||
|
return pvPortMalloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void free(void* ptr) {
|
||||||
|
vPortFree(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* calloc(size_t num, size_t size) {
|
||||||
|
(void)(num);
|
||||||
|
(void)(size);
|
||||||
|
// Not supported
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *pvPortRealloc(void *ptr, size_t xWantedSize);
|
||||||
|
void* realloc( void *ptr, size_t newSize) {
|
||||||
|
return pvPortRealloc(ptr, newSize);
|
||||||
|
}
|
Loading…
Reference in New Issue