From 4b009649c65053d2f0bcd220fc7d0f86b9ddf311 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sun, 3 Feb 2019 18:59:27 +0100 Subject: [PATCH] cpu/atmega_common: changes for common heap command --- cpu/atmega_common/cpu.c | 22 ++++++++++++++++++++++ cpu/atmega_common/include/cpu_conf.h | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/cpu/atmega_common/cpu.c b/cpu/atmega_common/cpu.c index f02469beb4..e1f9556dd9 100644 --- a/cpu/atmega_common/cpu.c +++ b/cpu/atmega_common/cpu.c @@ -112,6 +112,28 @@ void cpu_init(void) periph_init(); } +struct __freelist { + size_t size; + struct __freelist *next; +}; + +extern struct __freelist *__flp; +extern char *__malloc_heap_start; +extern char *__malloc_heap_end; +extern char *__brkval; + +void heap_stats(void) +{ + int heap_size = __malloc_heap_end - __malloc_heap_start; + int free = __malloc_heap_end - __brkval; + struct __freelist *fp; + for (fp = __flp; fp; fp = fp->next) { + free += fp->size; + } + printf("heap: %d (used %d, free %d) [bytes]\n", + heap_size, heap_size - free, free); +} + /* This is a vector which is aliased to __vector_default, * the vector executed when an ISR fires with no accompanying * ISR handler. This may be used along with the ISR() macro to diff --git a/cpu/atmega_common/include/cpu_conf.h b/cpu/atmega_common/include/cpu_conf.h index 7eacb5bf2b..37ede8582f 100644 --- a/cpu/atmega_common/include/cpu_conf.h +++ b/cpu/atmega_common/include/cpu_conf.h @@ -56,6 +56,11 @@ extern "C" { */ #define PUF_SRAM_ATTRIBUTES __attribute__((used, section(".noinit"))) +/** + * @brief Declare the heap_stats function as available + */ +#define HAVE_HEAP_STATS + #ifdef __cplusplus } #endif