Archived
1
0
This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
keybrd/src/getFreeSRAM.h

54 lines
1.3 KiB
C
Raw Normal View History

2016-05-09 14:05:08 +00:00
// getFreeSRAM.h copied from
// http://andybrown.me.uk/2011/01/01/debugging-avr-dynamic-memory-allocation/
/*
* memdebug.h
*
* Created on: 15 Dec 2010
* Author: Andy Brown
*
* Use without attribution is permitted provided that this
* header remains intact and that these terms and conditions
* are followed:
*
* http://andybrown.me.uk/ws/terms-and-conditions
*/
#include <inttypes.h>
extern unsigned int __bss_end;
extern unsigned int __heap_start;
extern void *__brkval;
//measure and return amount of free SRAM
2016-06-05 20:43:53 +00:00
/*
2016-05-09 14:05:08 +00:00
uint16_t getFreeSRAM()
{
uint8_t newVariable;
// if heap is empty, use bss as start memory address
if ((uint16_t)__brkval == 0)
{
return (((uint16_t)&newVariable) - ((uint16_t)&__bss_end));
}
// else use heap end as the start of the memory address
else
{
return (((uint16_t)&newVariable) - ((uint16_t)__brkval));
}
};
2016-06-05 20:43:53 +00:00
*/
// uint32_t for Teensy LC
uint32_t getFreeSRAM()
{
uint8_t newVariable;
// if heap is empty, use bss as start memory address
if ((uint32_t)__brkval == 0)
{
return (((uint32_t)&newVariable) - ((uint32_t)&__bss_end));
}
// else use heap end as the start of the memory address
else
{
return (((uint32_t)&newVariable) - ((uint32_t)__brkval));
}
};