1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-30 03:26:13 +01:00

Update freeMemory.cpp

Inhibit interrupts while updating/reading minimum_free_memory as it is accessed from interrupt handler.
This commit is contained in:
Neil McKechnie 2021-03-09 10:13:04 +00:00
parent 7a2beda2a9
commit fab05bac79

View File

@ -18,6 +18,7 @@
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Arduino.h>
#include "freeMemory.h"
// thanks go to https://github.com/mpflaga/Arduino-MemoryFree
@ -50,6 +51,10 @@ int freeMemory() {
// called subroutines.
int updateMinimumFreeMemory(unsigned char extraBytes) {
int spare = freeMemory()-extraBytes;
byte sreg_save = SREG;
noInterrupts();
if (spare < minimum_free_memory) minimum_free_memory = spare;
return minimum_free_memory;
int returnValue = minimum_free_memory;
SREG = sreg_save;
return returnValue;
}