Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

SnMemMonitor.h

Committer:
uci1
Date:
2019-06-05
Revision:
125:ce4045184366
Parent:
84:80b15993944e

File content as of revision 125:ce4045184366:

#ifndef SN_SnMemMonitor
#define SN_SnMemMonitor

/*
** Code from https://developer.mbed.org/questions/6994/How-to-print-Free-RAM-available-RAM-or-u/
** Possibly authored by Robert Spilleboudt
*/

/* Using malloc() to determine free memory.*/
 
#include <stdio.h>
#include <stdlib.h>
#define FREEMEM_CELL 100
struct elem { /* Definition of a structure that is FREEMEM_CELL bytes  in size.) */
    struct elem *next;
    char dummy[FREEMEM_CELL-2];
};

int FreeMem(void) {
    int counter;
    struct elem *head, *current, *nextone;
    current = head = (struct elem*) malloc(sizeof(struct elem));
    if (head == NULL)
        return 0;      /*No memory available.*/
    counter = 0;
   // __disable_irq();
    do {
        counter++;
        current->next = (struct elem*) malloc(sizeof(struct elem));
        current = current->next;
    } while (current != NULL);
    /* Now counter holds the number of type elem
       structures we were able to allocate. We
       must free them all before returning. */
    current = head;
    do {
        nextone = current->next;
        free(current);
        current = nextone;
    } while (nextone != NULL);
   // __enable_irq();
 
    return counter*FREEMEM_CELL;
}


#endif // SN_SnMemMonitor