From 8c95a688841a04a0de9dd4923f92fb68ea55909c Mon Sep 17 00:00:00 2001 From: Neil McNeight Date: Fri, 20 Mar 2015 15:28:22 -0700 Subject: [PATCH 1/3] Updated with code from http://playground.arduino.cc/code/AvailableMemory Added vim related entries to .gitignore from https://github.com/github/gitignore/blob/master/Global/Vim.gitignore Verfied code against Arduino 1.6.1 running on Arduino Leonardo --- .gitignore | 6 ++++ MemoryFree.cpp | 48 +++++++++++++++++++++++++----- MemoryFree.h | 5 +++- README => README.md | 2 ++ examples/FreeMemory/FreeMemory.ino | 31 +++++++++++++++++++ examples/FreeMemory/FreeMemory.pde | 28 ----------------- 6 files changed, 84 insertions(+), 36 deletions(-) rename README => README.md (63%) create mode 100644 examples/FreeMemory/FreeMemory.ino delete mode 100644 examples/FreeMemory/FreeMemory.pde diff --git a/.gitignore b/.gitignore index fa86a4b..cdbd978 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ *.o *.orig .*.swp +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +*.un~ +Session.vim +.netrwhist +*~ diff --git a/MemoryFree.cpp b/MemoryFree.cpp index d1883ee..6823004 100644 --- a/MemoryFree.cpp +++ b/MemoryFree.cpp @@ -1,18 +1,52 @@ -extern unsigned int __bss_end; +#if (ARDUINO >= 100) +#include +#else +#include +#endif + extern unsigned int __heap_start; extern void *__brkval; +/* + * The free list structure as maintained by the + * avr-libc memory allocation routines. + */ +struct __freelist +{ + size_t sz; + struct __freelist *nx; +}; -#include "MemoryFree.h" +/* The head of the free list structure */ +extern struct __freelist *__flp; +#include "MemoryFree.h"; -int freeMemory() { - int free_memory; +/* Calculates the size of the free list */ +int freeListSize() +{ + struct __freelist* current; + int total = 0; + for (current = __flp; current; current = current->nx) + { + total += 2; /* Add two bytes for the memory block's header */ + total += (int) current->sz; + } + + return total; +} - if((int)__brkval == 0) - free_memory = ((int)&free_memory) - ((int)&__bss_end); +int freeMemory() +{ + int free_memory; + if ((int)__brkval == 0) + { + free_memory = ((int)&free_memory) - ((int)&__heap_start); + } else + { free_memory = ((int)&free_memory) - ((int)__brkval); - + free_memory += freeListSize(); + } return free_memory; } diff --git a/MemoryFree.h b/MemoryFree.h index 143bf0c..f9d7cad 100644 --- a/MemoryFree.h +++ b/MemoryFree.h @@ -1,3 +1,7 @@ +// MemoryFree library based on code posted here: +// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1213583720/15 +// Extended by Matthew Murdoch to include walking of the free list. + #ifndef MEMORY_FREE_H #define MEMORY_FREE_H @@ -12,4 +16,3 @@ int freeMemory(); #endif #endif - diff --git a/README b/README.md similarity index 63% rename from README rename to README.md index 237533c..527f486 100644 --- a/README +++ b/README.md @@ -1,3 +1,5 @@ This is the excellent MemoryFree library from http://www.arduino.cc/playground/Code/AvailableMemory. I am hosting it here so there is a quick and easy way to pull it down. + +(20 Mar 2015) Repository updated with code from http://playground.arduino.cc/code/AvailableMemory diff --git a/examples/FreeMemory/FreeMemory.ino b/examples/FreeMemory/FreeMemory.ino new file mode 100644 index 0000000..d69027e --- /dev/null +++ b/examples/FreeMemory/FreeMemory.ino @@ -0,0 +1,31 @@ +#include + +// On Arduino Leonardo with ATmega32U4: +// +// Reported free memory with str commented out: +// 2373 bytes +// +// Reported free memory with str and Serial.println(str) uncommented: +// 2359 bytes +// +// Difference: 14 bytes (13 ASCII chars + null terminator) + +// 14-bytes string +//char str[] = "Hello, world!"; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } +} + +void loop() { +// Serial.println(str); + + Serial.print("freeMemory()="); + Serial.println(freeMemory()); + + delay(1000); +} diff --git a/examples/FreeMemory/FreeMemory.pde b/examples/FreeMemory/FreeMemory.pde deleted file mode 100644 index fbc6228..0000000 --- a/examples/FreeMemory/FreeMemory.pde +++ /dev/null @@ -1,28 +0,0 @@ -#include - -// Reported free memory with str commented out: -// 1848 bytes -// -// Reported free memory with str and Serial.println(str) uncommented: -// 1834 -// -// Difference: 14 bytes (13 ascii chars + null terminator - -// 14-bytes string -//char str[] = "Hallo, world!"; - - -void setup() { - Serial.begin(115200); -} - - -void loop() { - //Serial.println(str); - - Serial.print("freeMemory()="); - Serial.println(freeMemory()); - - delay(1000); -} - From d9ddab08183cbd00a3e56f377f0be2a1bc561745 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 25 May 2015 11:28:40 -0700 Subject: [PATCH 2/3] Remove semicolon from #include "MemoryFree.h"; This causes a compiler warning. --- MemoryFree.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MemoryFree.cpp b/MemoryFree.cpp index 6823004..bf57184 100644 --- a/MemoryFree.cpp +++ b/MemoryFree.cpp @@ -20,7 +20,7 @@ struct __freelist /* The head of the free list structure */ extern struct __freelist *__flp; -#include "MemoryFree.h"; +#include "MemoryFree.h" /* Calculates the size of the free list */ int freeListSize() From a2d60bd958f80fc3dea8479467a1309643bdbc63 Mon Sep 17 00:00:00 2001 From: Neil McNeight Date: Tue, 17 May 2016 19:05:30 -0700 Subject: [PATCH 3/3] Adds Travis CI --- .travis.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..091f37f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +language: c +sudo: false +before_install: + - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16" + - sleep 3 + - export DISPLAY=:1.0 + - wget http://downloads.arduino.cc/arduino-1.6.9-linux64.tar.xz + - tar xf arduino-1.6.9-linux64.tar.xz + - mv arduino-1.6.9 $HOME/arduino_ide +install: + - ln -s $PWD $HOME/arduino_ide/libraries/MemoryFree + - export PATH="$HOME/arduino_ide:$PATH" + - arduino --pref "boardsmanager.additional.urls=https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs 2>&1 + - arduino --install-boards arduino:sam 2>&1 /dev/null + - arduino --install-boards arduino:samd 2>&1 /dev/null + - arduino --install-boards esp8266:esp8266 2>&1 /dev/null + - arduino --install-boards adafruit:avr 2>&1 /dev/null + - arduino --install-library TinyWireM 2>&1 + - arduino --pref "compiler.warning_level=all" --save-prefs +script: + - arduino --verify --board arduino:avr:uno $PWD/examples/FreeMemory/FreeMemory.ino + - arduino --verify --board arduino:sam:arduino_due_x $PWD/examples/FreeMemory/FreeMemory.ino + - arduino --verify --board arduino:samd:zero $PWD/examples/FreeMemory/FreeMemory.ino + - arduino --verify --board esp8266:esp8266:huzzah $PWD/examples/FreeMemory/FreeMemory.ino + - arduino --verify --board arduino:avr:leonardo $PWD/examples/FreeMemory/FreeMemory.ino + - arduino --verify --board adafruit:avr:trinket5 $PWD/examples/FreeMemory/FreeMemory.ino + - arduino --verify --board arduino:avr:gemma $PWD/examples/FreeMemory/FreeMemory.ino +notifications: + email: + on_success: change + on_failure: change