1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00

Merge pull request #131 from DCC-EX/neil-freemem

More conservative memory monitoring
This commit is contained in:
Asbelos 2021-03-08 13:53:17 +00:00 committed by GitHub
commit 809b54d9f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 1 deletions

View File

@ -127,7 +127,7 @@ void loop()
#if ENABLE_FREE_MEM_WARNING
static int ramLowWatermark = 32767; // replaced on first loop
int freeNow = freeMemory();
int freeNow = updateMinimumFreeMemory();
if (freeNow < ramLowWatermark)
{
ramLowWatermark = freeNow;

View File

@ -23,6 +23,7 @@
#include "DCCWaveform.h"
#include "DCCTimer.h"
#include "DIAG.h"
#include "freeMemory.h"
DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
@ -203,6 +204,9 @@ void DCCWaveform::interrupt2() {
if (remainingPreambles > 0 ) {
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
remainingPreambles--;
// Update free memory diagnostic as we don't have anything else to do this time.
// Allow for checkAck and its called functions using 22 bytes more.
updateMinimumFreeMemory(22);
return;
}

View File

@ -1,5 +1,6 @@
/*
* © 2020, Harald Barth
* © 2021, Neil McKechnie
*
* This file is part of Asbelos DCC-EX
*
@ -30,6 +31,9 @@ extern char *__malloc_heap_start;
#endif
static volatile int minimum_free_memory = 32767;
int freeMemory() {
char top;
#if defined(__arm__)
@ -40,3 +44,12 @@ int freeMemory() {
#error bailed out alredy above
#endif
}
// Update low ram level. Allow for extra bytes to be specified
// by estimation or inspection, that may be used by other
// called subroutines.
int updateMinimumFreeMemory(unsigned char extraBytes) {
int spare = freeMemory()-extraBytes;
if (spare < minimum_free_memory) minimum_free_memory = spare;
return minimum_free_memory;
}

View File

@ -1,5 +1,6 @@
/*
* © 2020, Harald Barth
* © 2021, Neil McKechnie
*
* This file is part of DCC-EX
*
@ -20,4 +21,5 @@
#ifndef freeMemory_h
#define freeMemory_h
int freeMemory();
int updateMinimumFreeMemory(unsigned char extraBytes=0);
#endif