mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.2.3 AvrHeap
This commit is contained in:
parent
698ed49275
commit
e0fd73a084
@ -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 ---
|
||||
|
@ -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 --
|
||||
|
@ -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 --
|
||||
|
||||
|
@ -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
|
@ -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 --
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AvrHeap
|
||||
version=0.2.2
|
||||
version=0.2.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library to runtime analyze the structure of the heap (AVR328).
|
||||
|
@ -29,17 +29,22 @@ unittest_setup()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
Avrheap myheap;
|
||||
|
||||
fprintf(stderr, "no unit tests yet");
|
||||
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// --------
|
||||
|
Loading…
x
Reference in New Issue
Block a user