mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-23 21:01:25 +01:00
23 lines
577 B
C
23 lines
577 B
C
#ifndef freeMemory_h
|
|
#define freeMemory_h
|
|
|
|
// thanks go to https://github.com/mpflaga/Arduino-MemoryFree
|
|
#ifdef __arm__
|
|
// should use uinstd.h to define sbrk but Due causes a conflict
|
|
extern "C" char* sbrk(int incr);
|
|
#else // __ARM__
|
|
extern char *__brkval;
|
|
#endif // __arm__
|
|
|
|
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__
|
|
}
|
|
#endif
|