1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 21:01:25 +01:00

Low memory watermark

freememory was returning wrong values
This commit is contained in:
Asbelos 2020-07-24 13:46:23 +01:00
parent 56962d0528
commit 9b58eb29a2
2 changed files with 7 additions and 14 deletions

View File

@ -71,14 +71,7 @@ DCCEXParser serialParser;
// Try monitoring the memory
#include "freeMemory.h"
// TODO: this should be automated instead of ifdef
#if defined(ARDUINO_AVR_MEGA2560)
int minMemory=32767;
#elif defined(ARDUINO_AVR_UNO)
int minMemory=2048;
#else
#error CANNOT COMPILE - Unkown board, can not determine amount of RAM available.
#endif
int ramLowWatermark=32767; // This figure gets overwritten dynamically in loop()
void setup() {
@ -130,10 +123,12 @@ void loop() {
WifiInterface::loop(Serial1);
#endif
// Your additional code e.g. Report any decrease in memory
// Your additional code
// OPtionally report any decrease in memory (will automatically trigger on first call)
int freeNow=freeMemory();
if (freeNow<minMemory) {
minMemory=freeNow;
DIAG(F("\nFree memory=%d"),minMemory);
if (freeNow<ramLowWatermark) {
ramLowWatermark=freeNow;
DIAG(F("\nFree RAM=%d\n"),ramLowWatermark);
}
}

View File

@ -13,8 +13,6 @@ int freeMemory() {
char top;
#ifdef __arm__
return &top - reinterpret_cast<char*>(sbrk(0));
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
return &top - __brkval;
#else // __arm__
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif // __arm__