2022-02-16 21:42:29 +01:00
|
|
|
#include "FreeRTOS.h"
|
2023-04-09 12:17:10 +02:00
|
|
|
#include <algorithm>
|
2023-05-03 20:41:38 +02:00
|
|
|
#include <unordered_map>
|
2023-04-09 12:17:10 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2022-02-16 21:42:29 +01:00
|
|
|
|
|
|
|
void NVIC_SystemReset(void) {}
|
2023-04-09 12:17:10 +02:00
|
|
|
|
|
|
|
void APP_ERROR_HANDLER(int err) {
|
|
|
|
fprintf(stderr, "APP_ERROR_HANDLER: %d", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2023-05-03 20:41:38 +02:00
|
|
|
std::unordered_map<void *, size_t> allocatedMemory;
|
2023-04-09 12:17:10 +02:00
|
|
|
size_t currentFreeHeap = configTOTAL_HEAP_SIZE;
|
|
|
|
size_t minimumEverFreeHeap = configTOTAL_HEAP_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *pvPortMalloc( size_t xWantedSize ) {
|
|
|
|
void* ptr = malloc(xWantedSize);
|
|
|
|
allocatedMemory[ptr] = xWantedSize;
|
|
|
|
|
|
|
|
size_t currentSize = 0;
|
|
|
|
std::for_each(allocatedMemory.begin(), allocatedMemory.end(), [¤tSize](const std::pair<void*, size_t>& item){
|
|
|
|
currentSize += item.second;
|
|
|
|
});
|
|
|
|
|
|
|
|
currentFreeHeap = configTOTAL_HEAP_SIZE - currentSize;
|
|
|
|
minimumEverFreeHeap = std::min(currentFreeHeap, minimumEverFreeHeap);
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
void vPortFree( void *pv ) {
|
|
|
|
allocatedMemory.erase(pv);
|
|
|
|
return free(pv);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t xPortGetFreeHeapSize(void) {
|
|
|
|
return currentFreeHeap;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t xPortGetMinimumEverFreeHeapSize(void) {
|
|
|
|
return minimumEverFreeHeap;
|
|
|
|
}
|