mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-27 01:56:14 +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:
parent
7a2beda2a9
commit
fab05bac79
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user