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:
commit
809b54d9f0
|
@ -127,7 +127,7 @@ void loop()
|
||||||
#if ENABLE_FREE_MEM_WARNING
|
#if ENABLE_FREE_MEM_WARNING
|
||||||
static int ramLowWatermark = 32767; // replaced on first loop
|
static int ramLowWatermark = 32767; // replaced on first loop
|
||||||
|
|
||||||
int freeNow = freeMemory();
|
int freeNow = updateMinimumFreeMemory();
|
||||||
if (freeNow < ramLowWatermark)
|
if (freeNow < ramLowWatermark)
|
||||||
{
|
{
|
||||||
ramLowWatermark = freeNow;
|
ramLowWatermark = freeNow;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "DCCWaveform.h"
|
#include "DCCWaveform.h"
|
||||||
#include "DCCTimer.h"
|
#include "DCCTimer.h"
|
||||||
#include "DIAG.h"
|
#include "DIAG.h"
|
||||||
|
#include "freeMemory.h"
|
||||||
|
|
||||||
|
|
||||||
DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
|
DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true);
|
||||||
|
@ -203,6 +204,9 @@ void DCCWaveform::interrupt2() {
|
||||||
if (remainingPreambles > 0 ) {
|
if (remainingPreambles > 0 ) {
|
||||||
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
|
state=WAVE_MID_1; // switch state to trigger LOW on next interrupt
|
||||||
remainingPreambles--;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* © 2020, Harald Barth
|
* © 2020, Harald Barth
|
||||||
|
* © 2021, Neil McKechnie
|
||||||
*
|
*
|
||||||
* This file is part of Asbelos DCC-EX
|
* This file is part of Asbelos DCC-EX
|
||||||
*
|
*
|
||||||
|
@ -30,6 +31,9 @@ extern char *__malloc_heap_start;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static volatile int minimum_free_memory = 32767;
|
||||||
|
|
||||||
|
|
||||||
int freeMemory() {
|
int freeMemory() {
|
||||||
char top;
|
char top;
|
||||||
#if defined(__arm__)
|
#if defined(__arm__)
|
||||||
|
@ -40,3 +44,12 @@ int freeMemory() {
|
||||||
#error bailed out alredy above
|
#error bailed out alredy above
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* © 2020, Harald Barth
|
* © 2020, Harald Barth
|
||||||
|
* © 2021, Neil McKechnie
|
||||||
*
|
*
|
||||||
* This file is part of DCC-EX
|
* This file is part of DCC-EX
|
||||||
*
|
*
|
||||||
|
@ -20,4 +21,5 @@
|
||||||
#ifndef freeMemory_h
|
#ifndef freeMemory_h
|
||||||
#define freeMemory_h
|
#define freeMemory_h
|
||||||
int freeMemory();
|
int freeMemory();
|
||||||
|
int updateMinimumFreeMemory(unsigned char extraBytes=0);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user