mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
freememory() available more generally
fixed some mem diags
This commit is contained in:
parent
083c73ebc3
commit
c30f1c7cbe
|
@ -33,7 +33,8 @@
|
|||
#include "MQTTBrokers.h"
|
||||
#include "DCCTimer.h"
|
||||
#include "CommandDistributor.h"
|
||||
#include "MemoryFree.h"
|
||||
// #include "MemoryFree.h"
|
||||
#include "freeMemory.h"
|
||||
|
||||
MQTTInterface *MQTTInterface::singleton = NULL;
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
#include "DCCEXParser.h"
|
||||
#include "Queue.h"
|
||||
#include "ObjectPool.h"
|
||||
#include "MemoryFree.h"
|
||||
// #include "MemoryFree.h"
|
||||
#include "freeMemory.h"
|
||||
|
||||
#define MAXPAYLOAD 64 // max length of a payload recieved
|
||||
#define MAXDOMAINLENGTH 32 // domain name length for the broker e.g. test.mosquitto.org
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
#if (ARDUINO >= 100)
|
||||
#include <Arduino.h>
|
||||
// #include <Transport/MQTT/DccMQTT.h>
|
||||
// #include <Diag/Telemetry/DccTelemetry.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
|
||||
extern unsigned int __heap_start;
|
||||
extern void *__brkval;
|
||||
|
||||
/*
|
||||
* The free list structure as maintained by the
|
||||
* avr-libc memory allocation routines.
|
||||
*/
|
||||
struct __freelist
|
||||
{
|
||||
size_t sz;
|
||||
struct __freelist *nx;
|
||||
};
|
||||
|
||||
/* The head of the free list structure */
|
||||
extern struct __freelist *__flp;
|
||||
|
||||
#include "MemoryFree.h"
|
||||
|
||||
/* Calculates the size of the free list */
|
||||
int freeListSize()
|
||||
{
|
||||
struct __freelist* current;
|
||||
int total = 0;
|
||||
for (current = __flp; current; current = current->nx)
|
||||
{
|
||||
total += 2; /* Add two bytes for the memory block's header */
|
||||
total += (int) current->sz;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
int freeMemory()
|
||||
{
|
||||
int free_memory;
|
||||
if ((int)__brkval == 0)
|
||||
{
|
||||
free_memory = ((int)&free_memory) - ((int)&__heap_start);
|
||||
}
|
||||
else
|
||||
{
|
||||
free_memory = ((int)&free_memory) - ((int)__brkval);
|
||||
free_memory += freeListSize();
|
||||
}
|
||||
// report free memory over MQTT - to be replaced by Telemetry
|
||||
// DccTelemetry::free_memory(free_memory);
|
||||
|
||||
return free_memory;
|
||||
}
|
14
MemoryFree.h
14
MemoryFree.h
|
@ -1,14 +0,0 @@
|
|||
#ifndef MEMORY_FREE_H
|
||||
#define MEMORY_FREE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int freeMemory();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -31,11 +31,13 @@ extern char *__malloc_heap_start;
|
|||
#error Unsupported board type
|
||||
#endif
|
||||
|
||||
|
||||
static volatile int minimum_free_memory = __INT_MAX__;
|
||||
|
||||
#if !defined(__IMXRT1062__)
|
||||
static inline int freeMemory() {
|
||||
|
||||
inline int freeMemory()
|
||||
// static inline int freeMemory()
|
||||
{
|
||||
char top;
|
||||
#if defined(__arm__)
|
||||
return &top - reinterpret_cast<char *>(sbrk(0));
|
||||
|
@ -47,7 +49,8 @@ static inline int freeMemory() {
|
|||
}
|
||||
|
||||
// Return low memory value.
|
||||
int minimumFreeMemory() {
|
||||
int minimumFreeMemory()
|
||||
{
|
||||
byte sreg_save = SREG;
|
||||
noInterrupts(); // Disable interrupts
|
||||
int retval = minimum_free_memory;
|
||||
|
@ -71,7 +74,8 @@ int minimumFreeMemory() {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
static inline int freeMemory() {
|
||||
static inline int freeMemory()
|
||||
{
|
||||
extern unsigned long _ebss;
|
||||
extern unsigned long _sdata;
|
||||
extern unsigned long _estack;
|
||||
|
@ -84,7 +88,8 @@ static inline int freeMemory() {
|
|||
}
|
||||
|
||||
// Return low memory value.
|
||||
int minimumFreeMemory() {
|
||||
int minimumFreeMemory()
|
||||
{
|
||||
//byte sreg_save = SREG;
|
||||
//noInterrupts(); // Disable interrupts
|
||||
int retval = minimum_free_memory;
|
||||
|
@ -93,7 +98,6 @@ int minimumFreeMemory() {
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Update low ram level. Allow for extra bytes to be specified
|
||||
// by estimation or inspection, that may be used by other
|
||||
// called subroutines. Must be called with interrupts disabled.
|
||||
|
@ -103,9 +107,11 @@ int minimumFreeMemory() {
|
|||
// So even if all of the heap is freed, the reported minimum free
|
||||
// memory will not increase.
|
||||
//
|
||||
void updateMinimumFreeMemory(unsigned char extraBytes) {
|
||||
void updateMinimumFreeMemory(unsigned char extraBytes)
|
||||
{
|
||||
int spare = freeMemory() - extraBytes;
|
||||
if (spare < 0) spare = 0;
|
||||
if (spare < minimum_free_memory) minimum_free_memory = spare;
|
||||
if (spare < 0)
|
||||
spare = 0;
|
||||
if (spare < minimum_free_memory)
|
||||
minimum_free_memory = spare;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#ifndef freeMemory_h
|
||||
#define freeMemory_h
|
||||
|
||||
void updateMinimumFreeMemory(unsigned char extraBytes=0);
|
||||
int minimumFreeMemory();
|
||||
int freeMemory();
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user