diff --git a/cpu/mips32r2_common/Makefile.include b/cpu/mips32r2_common/Makefile.include index 00bf930738..79c3f89cde 100644 --- a/cpu/mips32r2_common/Makefile.include +++ b/cpu/mips32r2_common/Makefile.include @@ -11,6 +11,7 @@ ifeq ($(USE_UHI_SYSCALLS),1) #Use UHI to handle syscalls export LINKFLAGS += -luhi export USEMODULE += newlib_syscalls_mips_uhi + CFLAGS += -DHAVE_HEAP_STATS else #Use RIOT to handle syscalls (default) export USEMODULE += newlib_syscalls_default diff --git a/cpu/mips32r2_common/cpu.c b/cpu/mips32r2_common/cpu.c index d2483cbc1c..0b21a8b47a 100644 --- a/cpu/mips32r2_common/cpu.c +++ b/cpu/mips32r2_common/cpu.c @@ -7,11 +7,13 @@ * directory for more details. */ +#include #include #include #include #include #include +#include #include "periph/uart.h" #include "periph/timer.h" @@ -79,3 +81,35 @@ void cpu_init(void) /* trigger static peripheral initialization */ periph_init(); } + +#ifdef MODULE_NEWLIB_SYSCALLS_DEFAULT + +void heap_stats(void) +{ + puts("heap statistics are not supported for newlib_syscalls_default"); +} + +#else + +extern char _end[]; /* defined in linker script */ + +void heap_stats(void) +{ + void *ram_base; + void *ram_extent; + unsigned long heap_size; + + _get_ram_range (&ram_base, &ram_extent); + /* If the _end symbol is within the RAM then use _end. */ + if ((void*)_end > ram_base && (void*)_end < ram_extent) { + heap_size = ram_extent - (void*)_end; + } + else { + heap_size = ram_extent - ram_base; + } + struct mallinfo minfo = mallinfo(); + printf("heap: %lu (used %lu, free %lu) [bytes]\n", + heap_size, minfo.uordblks, heap_size - minfo.uordblks); +} + +#endif