From: Jon Langseth Date: Wed, 7 Sep 2011 20:43:47 +0000 (+0200) Subject: Added FreeRam function, borrowed from the FAT16lib. X-Git-Url: https://git.defcon.no/?a=commitdiff_plain;h=4f09799ebf9b68f8a91546bdb03db44aaadc7b4c;p=rctxduino Added FreeRam function, borrowed from the FAT16lib. --- diff --git a/source/RCTXDuino/RCTXDuino.pde b/source/RCTXDuino/RCTXDuino.pde index ebe62ad..0c63499 100644 --- a/source/RCTXDuino/RCTXDuino.pde +++ b/source/RCTXDuino/RCTXDuino.pde @@ -696,6 +696,7 @@ void ISR_timer(void) } } + #ifdef DEBUG void serial_debug() { @@ -720,6 +721,8 @@ void serial_debug() Serial.print("Average loop time:"); Serial.println(avg_loop_time); + Serial.print("Free RAM:"); + Serial.print( FreeRam() ); Serial.println(); } #endif @@ -1089,6 +1092,33 @@ void ui_handler() return; } +#ifdef DEBUG +/* The following code is taken from the + Arduino FAT16 Library by William Greiman + The code may or may-not survive in the long run, + depending on what licensing-terms we decide on. + The license will be open source, but the FAT16lib + is GPL v3, and I (fishy) am personally not so sure about that... + + On the other hand... This code is a very "intuitive approach", + so contacting the author may give us the option of relicencing just this bit... +*/ +static int FreeRam(void) { + extern int __bss_end; + extern int* __brkval; + int free_memory; + if (reinterpret_cast(__brkval) == 0) { + // if no heap use from end of bss section + free_memory = reinterpret_cast(&free_memory) + - reinterpret_cast(&__bss_end); + } else { + // use from top of stack to heap + free_memory = reinterpret_cast(&free_memory) + - reinterpret_cast(__brkval); + } + return free_memory; +} +#endif