diff --git a/libraries/AvrHeap/avrheap.cpp b/libraries/AvrHeap/avrheap.cpp index 93d6e9b7..fa9b272e 100644 --- a/libraries/AvrHeap/avrheap.cpp +++ b/libraries/AvrHeap/avrheap.cpp @@ -1,7 +1,7 @@ // // FILE: avrheap.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.2 +// VERSION: 0.2.3 // PURPOSE: experimental library for heap Arduino UNO // URL: https://github.com/RobTillaart/avrheap // @@ -10,6 +10,7 @@ // http://forum.arduino.cc/index.php?topic=355660 // // HISTORY +// 0.2.3 2021-05027 add Arduino-CI // 0.2.2 2020-12-13 arduino-CI + minimal unit tests // 0.2.1 2020-05-27 update library.json // 0.2.0 2020-03-27 Removed support for pre 1.0 version @@ -21,8 +22,10 @@ // 0.1.01 - refactor, added startAddress() // 0.1.00 - initial version + #include "avrheap.h" + struct __freelist { size_t size; @@ -46,18 +49,21 @@ size_t hNibble(Print& p, byte val) return p.write(val + (val<10 ? '0' : 'A'-10)); } + size_t hByte(Print& p, byte val) { size_t len = hNibble(p, val >> 4); return len + hNibble(p, val & 0x0F); } + size_t hWord(Print& p, uint16_t val) { size_t len = hByte(p, (byte)(val >> 8)); return len + hByte(p, (byte)(val & 0xFF) ); } + size_t dumpR(Print& p, byte* adr, int len) { size_t glen = 0; @@ -91,11 +97,13 @@ size_t dumpR(Print& p, byte* adr, int len) return glen; } + size_t dumpAlloced(byte *ptr, bool withDump) { return dumpAlloced(Serial, ptr, withDump); } + size_t dumpAlloced(Print& p, byte *ptr, bool withDump) { size_t len = hWord(p, (uint16_t)ptr); @@ -123,16 +131,17 @@ size_t dumpAlloced(Print& p, byte *ptr, bool withDump) } - Avrheap::Avrheap() { }; + bool Avrheap::isFragmented() { return freeListCount() > 0; }; + uint16_t Avrheap::freeListCount() { uint16_t count = 0; @@ -140,6 +149,7 @@ uint16_t Avrheap::freeListCount() return count; } + uint16_t Avrheap::freeListSize() { uint16_t total = 0; @@ -151,6 +161,7 @@ uint16_t Avrheap::freeListSize() return total; } + void Avrheap::freeListWalk(bool withDump) { int elements = freeListCount(); @@ -182,11 +193,13 @@ void Avrheap::freeListWalk(bool withDump) } } + uint16_t Avrheap::startAddress() { return (uint16_t) &__heap_start; } + void Avrheap::dumpHeap(uint16_t count) { hWord(Serial, (uint16_t)RAMEND); @@ -217,10 +230,12 @@ void Avrheap::dumpHeap(uint16_t count) dumpR(Serial, (byte*)startAddress(), count); } + size_t Avrheap::heapWalk(bool withDump) { return heapWalk(Serial, withDump); } + // EXPERIMENTAL size_t Avrheap::heapWalk(Print& pr, bool withDump) const { @@ -248,6 +263,7 @@ size_t Avrheap::heapWalk(Print& pr, bool withDump) const return len; } + bool Avrheap::inFreeList(uint16_t addr) { for (struct __freelist* p = __flp; p; p = p->next) @@ -257,6 +273,7 @@ bool Avrheap::inFreeList(uint16_t addr) return false; } + uint16_t Avrheap::freeListLargest() { uint16_t largest = 0; @@ -267,10 +284,12 @@ uint16_t Avrheap::freeListLargest() return largest; } + size_t Avrheap::printTo(Print& p) const { size_t len = heapWalk(p, true); return len; } + // --- END OF FILE --- diff --git a/libraries/AvrHeap/avrheap.h b/libraries/AvrHeap/avrheap.h index 262520e6..8f9f92b5 100644 --- a/libraries/AvrHeap/avrheap.h +++ b/libraries/AvrHeap/avrheap.h @@ -2,19 +2,23 @@ // // FILE: avrheap.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.2 +// VERSION: 0.2.3 // PURPOSE: experimental library for heap Arduino UNO // HISTORY: See avrheap.cpp // + #if !defined(ARDUINO_ARCH_AVR) #error “Avrheap library only AVR boards, tested only with UNO.” #endif + #include "Arduino.h" #include "Printable.h" -#define AVRHEAP_LIB_VERSION "0.2.2" + +#define AVRHEAP_LIB_VERSION (F("0.2.3")) + class Avrheap : public Printable { @@ -38,6 +42,7 @@ private: bool inFreeList(uint16_t addr); }; + size_t hNibble(Print& p, byte val); size_t hByte(Print& p, byte val); size_t hWord(Print& p, uint16_t val); @@ -45,4 +50,5 @@ size_t dumpR(Print& p, byte* adr, int len); size_t dumpAlloced(Print& p, byte *ptr, bool withDump = true); size_t dumpAlloced(byte *ptr, bool withDump = true); + // -- END OF FILE -- diff --git a/libraries/AvrHeap/examples/heapdemo/heapdemo.ino b/libraries/AvrHeap/examples/heapdemo/heapdemo.ino index 413eb261..4a9ec045 100644 --- a/libraries/AvrHeap/examples/heapdemo/heapdemo.ino +++ b/libraries/AvrHeap/examples/heapdemo/heapdemo.ino @@ -14,6 +14,7 @@ Avrheap myheap; int *par[10]; + void setup() { Serial.begin(115200); @@ -89,10 +90,10 @@ void setup() Serial.println("\ndone"); } + void loop() { } // -- END OF FILE -- - diff --git a/libraries/AvrHeap/examples/heapdemo1 ( - 0.1.03)/heapdemo1.ino b/libraries/AvrHeap/examples/heapdemo1_pre_0.1.03/heapdemo1_pre_0.1.03.ino similarity index 97% rename from libraries/AvrHeap/examples/heapdemo1 ( - 0.1.03)/heapdemo1.ino rename to libraries/AvrHeap/examples/heapdemo1_pre_0.1.03/heapdemo1_pre_0.1.03.ino index 5d86b7bf..c674f8b8 100644 --- a/libraries/AvrHeap/examples/heapdemo1 ( - 0.1.03)/heapdemo1.ino +++ b/libraries/AvrHeap/examples/heapdemo1_pre_0.1.03/heapdemo1_pre_0.1.03.ino @@ -1,7 +1,7 @@ // -// FILE: heapdemo.ino +// FILE: heapdemo1_pre_0.1.03.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.00 +// VERSION: 0.1.1 // PURPOSE: heapdemo // DATE: 2015-10-25 // URL: https://github.com/RobTillaart/avrheap diff --git a/libraries/AvrHeap/examples/heapdemo2/heapdemo2.ino b/libraries/AvrHeap/examples/heapdemo2/heapdemo2.ino index 25e77934..422e8720 100644 --- a/libraries/AvrHeap/examples/heapdemo2/heapdemo2.ino +++ b/libraries/AvrHeap/examples/heapdemo2/heapdemo2.ino @@ -1,31 +1,36 @@ // // FILE: heapdemo2.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.0 +// VERSION: 0.1.1 // PURPOSE: demo AvrHeap class // DATE: 2015-10-25 // URL: http://forum.arduino.cc/index.php?topic=355660 // https://github.com/RobTillaart/avrheap // + #if !defined(ARDUINO_ARCH_AVR) + void setup() { } + void loop() { } #else + #include "avrheap.h" Avrheap myheap; int *par[10]; + void setup() { int seed = analogRead(A0) + analogRead(A3) + analogRead(A2); @@ -35,7 +40,7 @@ void setup() Serial.print(F("Start ")); Serial.print(F(__FILE__)); Serial.print(F("\nLibVersion ")); - Serial.println(F(AVRHEAP_LIB_VERSION)); + Serial.println(AVRHEAP_LIB_VERSION); Serial.println(); Serial.print(F("HEAP ADDR: ")); @@ -75,10 +80,12 @@ void setup() Serial.println(F("done")); } + void loop() { } + #endif // -- END OF FILE -- diff --git a/libraries/AvrHeap/library.json b/libraries/AvrHeap/library.json index 007e6860..08208840 100644 --- a/libraries/AvrHeap/library.json +++ b/libraries/AvrHeap/library.json @@ -15,7 +15,8 @@ "type": "git", "url": "https://github.com/RobTillaart/avrheap.git" }, - "version":"0.2.2", + "version": "0.2.3", + "license": "MIT", "frameworks": "arduino", "platforms": "avr" } diff --git a/libraries/AvrHeap/library.properties b/libraries/AvrHeap/library.properties index 28adfc50..4f04e9db 100644 --- a/libraries/AvrHeap/library.properties +++ b/libraries/AvrHeap/library.properties @@ -1,5 +1,5 @@ name=AvrHeap -version=0.2.2 +version=0.2.3 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library to runtime analyze the structure of the heap (AVR328). diff --git a/libraries/AvrHeap/test/unit_test_001.cpp_no test_possible b/libraries/AvrHeap/test/unit_test_001.cpp_no test_possible index 9ba427ad..64db5b81 100644 --- a/libraries/AvrHeap/test/unit_test_001.cpp_no test_possible +++ b/libraries/AvrHeap/test/unit_test_001.cpp_no test_possible @@ -29,17 +29,22 @@ unittest_setup() { } + unittest_teardown() { } + unittest(test_constructor) { Avrheap myheap; fprintf(stderr, "no unit tests yet"); + } + unittest_main() + // --------