2020-07-31 02:27:04 +02:00
|
|
|
#ifndef COMMANDSTATION_DCC_FREEMEMORY_H_
|
|
|
|
#define COMMANDSTATION_DCC_FREEMEMORY_H_
|
2020-07-30 01:03:09 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
extern char *__brkval;
|
|
|
|
#endif // __arm__
|
|
|
|
|
|
|
|
int freeMemory() {
|
|
|
|
char top;
|
|
|
|
#ifdef __arm__
|
|
|
|
return &top - reinterpret_cast<char*>(sbrk(0));
|
|
|
|
#else
|
|
|
|
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
|
|
|
|
#endif // __arm__
|
|
|
|
}
|
2020-07-31 02:27:04 +02:00
|
|
|
#endif // COMMANDSTATION_DCC_FREEMEMORY_H_
|