diff --git a/src/helpers/DeviceDiag.cpp b/src/helpers/DeviceDiag.cpp index 117dd72d..1581533b 100644 --- a/src/helpers/DeviceDiag.cpp +++ b/src/helpers/DeviceDiag.cpp @@ -24,6 +24,25 @@ uint32_t DeviceDiag::getStackFreeBytes() { return (uint32_t)uxTaskGetStackHighWaterMark(NULL) * sizeof(StackType_t); } +#elif defined(ESP32) +#include +#include +#include + +// MALLOC_CAP_8BIT: the general-purpose byte-addressable heap (what `new`/ +// malloc() actually draw from) -- excludes DMA-only/IRAM regions a plain +// allocation could never land in, so this matches what's really available to +// the rest of the firmware rather than overstating it with capability pools +// nothing here can use. +void DeviceDiag::getHeapStats(uint32_t& free_bytes, uint32_t& total_bytes) { + free_bytes = (uint32_t)heap_caps_get_free_size(MALLOC_CAP_8BIT); + total_bytes = (uint32_t)heap_caps_get_total_size(MALLOC_CAP_8BIT); +} + +uint32_t DeviceDiag::getStackFreeBytes() { + return (uint32_t)uxTaskGetStackHighWaterMark(NULL) * sizeof(StackType_t); +} + #else void DeviceDiag::getHeapStats(uint32_t& free_bytes, uint32_t& total_bytes) {