From ef40a58716ce80beba9c8836b96cdb85321bc26e Mon Sep 17 00:00:00 2001 From: darren siepka Date: Mon, 21 Nov 2016 01:44:37 +0000 Subject: [PATCH] added freeram calculation code for use with Teensy --- utils.ino | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/utils.ino b/utils.ino index 72666416..8be2ba28 100644 --- a/utils.ino +++ b/utils.ino @@ -17,7 +17,19 @@ int freeRam () int v; return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); #elif defined(CORE_TEENSY) - return 0; + uint32_t stackTop; + uint32_t heapTop; + + // current position of the stack. + stackTop = (uint32_t) &stackTop; + + // current position of heap. + void* hTop = malloc(1); + heapTop = (uint32_t) hTop; + free(hTop); + + // The difference is the free, available ram. + return (uint16_t)stackTop - heapTop; #endif }