mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-24 13:21:23 +01:00
Low memory watermark
freememory was returning wrong values
This commit is contained in:
parent
56962d0528
commit
9b58eb29a2
19
CVReader.ino
19
CVReader.ino
@ -71,14 +71,7 @@ DCCEXParser serialParser;
|
|||||||
|
|
||||||
// Try monitoring the memory
|
// Try monitoring the memory
|
||||||
#include "freeMemory.h"
|
#include "freeMemory.h"
|
||||||
// TODO: this should be automated instead of ifdef
|
int ramLowWatermark=32767; // This figure gets overwritten dynamically in loop()
|
||||||
#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
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
@ -130,10 +123,12 @@ void loop() {
|
|||||||
WifiInterface::loop(Serial1);
|
WifiInterface::loop(Serial1);
|
||||||
#endif
|
#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();
|
int freeNow=freeMemory();
|
||||||
if (freeNow<minMemory) {
|
if (freeNow<ramLowWatermark) {
|
||||||
minMemory=freeNow;
|
ramLowWatermark=freeNow;
|
||||||
DIAG(F("\nFree memory=%d"),minMemory);
|
DIAG(F("\nFree RAM=%d\n"),ramLowWatermark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,6 @@ int freeMemory() {
|
|||||||
char top;
|
char top;
|
||||||
#ifdef __arm__
|
#ifdef __arm__
|
||||||
return &top - reinterpret_cast<char*>(sbrk(0));
|
return &top - reinterpret_cast<char*>(sbrk(0));
|
||||||
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
|
|
||||||
return &top - __brkval;
|
|
||||||
#else // __arm__
|
#else // __arm__
|
||||||
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
|
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
|
||||||
#endif // __arm__
|
#endif // __arm__
|
||||||
|
Loading…
Reference in New Issue
Block a user