mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 14:58:12 +00:00
fix(diag): real heap-free via mallinfo, flush-align Errors row
sbrk(0)-high-water counted freed-and-recycled blocks as permanently used, understating free heap. mallinfo().uordblks reflects bytes actually outstanding. Also strip the trailing space from the decoded error-flag string so right-alignment sits flush. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -110,6 +110,8 @@ class DiagnosticsScreen : public UIScreen {
|
||||
if (err & ERR_EVENT_FULL) strcat(buf, "F ");
|
||||
if (err & ERR_EVENT_CAD_TIMEOUT) strcat(buf, "C ");
|
||||
if (err & ERR_EVENT_STARTRX_TIMEOUT) strcat(buf, "R ");
|
||||
int len = strlen(buf); // drop the trailing space so right-alignment sits flush
|
||||
if (len > 0 && buf[len - 1] == ' ') buf[len - 1] = '\0';
|
||||
}
|
||||
addRow("Errors", buf);
|
||||
}
|
||||
|
||||
@@ -3,17 +3,20 @@
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <malloc.h>
|
||||
|
||||
// Same linker symbols + _sbrk() the core's own new.cpp uses to implement
|
||||
// malloc's heap (see framework-arduinoadafruitnrf52/cores/nRF5/new.cpp) —
|
||||
// there's no separate "free heap" API on this core, so this mirrors it.
|
||||
extern "C" char* _sbrk(int incr);
|
||||
// Heap region size from the linker symbols the core's new.cpp uses for sbrk
|
||||
// (framework-arduinoadafruitnrf52/cores/nRF5/new.cpp). "Used" comes from
|
||||
// newlib's mallinfo().uordblks (bytes actually outstanding) rather than
|
||||
// sbrk(0) - __HeapBase: sbrk only ever grows, so a high-water mark there
|
||||
// counts freed-and-recycled blocks as permanently "used" and free heap looks
|
||||
// far lower than it really is.
|
||||
extern unsigned char __HeapBase[];
|
||||
extern unsigned char __HeapLimit[];
|
||||
|
||||
void DeviceDiag::getHeapStats(uint32_t& free_bytes, uint32_t& total_bytes) {
|
||||
total_bytes = (uint32_t)(__HeapLimit - __HeapBase);
|
||||
uint32_t used = (uint32_t)((unsigned char*)_sbrk(0) - __HeapBase);
|
||||
uint32_t used = (uint32_t)mallinfo().uordblks;
|
||||
free_bytes = (used < total_bytes) ? (total_bytes - used) : 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user