
Repository for CDMS code
Dependencies: SimpleDMA mbed-rtos mbed eeprom
Fork of COM_MNG_TMTC_SIMPLE by
Diff: RAM.h
- Revision:
- 344:1675dbde0bae
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RAM.h Sun Jan 08 14:52:55 2017 +0000 @@ -0,0 +1,35 @@ +/* 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; +} \ No newline at end of file