diff --git a/cpu/fe310/cpu.c b/cpu/fe310/cpu.c index b8e12ec44..94abc4e96 100644 --- a/cpu/fe310/cpu.c +++ b/cpu/fe310/cpu.c @@ -19,6 +19,7 @@ #include #include +#include #include "thread.h" #include "irq.h" @@ -344,3 +345,17 @@ void thread_yield_higher(void) /* Use SW intr to schedule context switch */ CLINT_REG(CLINT_MSIP) = 1; } + +/** + * @brief Print heap statistics + */ +void heap_stats(void) +{ + extern char _heap_start; /* defined in linker script */ + extern char _heap_end; /* defined in linker script */ + + long int heap_size = &_heap_end - &_heap_start; + struct mallinfo minfo = mallinfo(); + printf("heap: %ld (used %u, free %ld) [bytes]\n", + heap_size, minfo.uordblks, heap_size - minfo.uordblks); +} diff --git a/cpu/fe310/include/cpu_conf.h b/cpu/fe310/include/cpu_conf.h index 4023b0079..698ea7873 100644 --- a/cpu/fe310/include/cpu_conf.h +++ b/cpu/fe310/include/cpu_conf.h @@ -34,6 +34,11 @@ #endif /** @} */ +/** + * @brief Declare the heap_stats function as available + */ +#define HAVE_HEAP_STATS + #ifdef __cplusplus extern "C" { #endif