From 4e4dc8e16ebdcaa1e8a2fe8fdc529bc8a9565c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 20 Apr 2020 01:05:48 +0200 Subject: [PATCH] Add dynamic memory info to meminfo command --- stm-firmware/shell.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index 548fdd1..b4cd5da 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -200,12 +201,13 @@ static shellmatta_retCode_t shell_cmd_cal(const shellmatta_handle_t handle, return SHELLMATTA_OK; } -static shellmatta_retCode_t shell_get_sp(const shellmatta_handle_t handle, +static shellmatta_retCode_t shell_meminfo(const shellmatta_handle_t handle, const char *arguments, uint32_t length) { (void)arguments; (void)length; + struct mallinfo mi; shellmatta_printf(handle, "Stack pointer: %p\r\n" @@ -214,6 +216,15 @@ static shellmatta_retCode_t shell_get_sp(const shellmatta_handle_t handle, read_stack_pointer(), stack_check_get_usage(), stack_check_get_free()); + + mi = mallinfo(); + shellmatta_printf(handle, "\r\nDynamic Memory Management\r\n"); + shellmatta_printf(handle, "Allocated bytes: %d\r\n", mi.arena, mi.arena); + shellmatta_printf(handle, "Number of free chunks: %d\r\n", mi.ordblks); + shellmatta_printf(handle, "Top-most, releasable space: %d\r\n", mi.keepcost); + shellmatta_printf(handle, "Total free space: %d\r\n", mi.fordblks); + shellmatta_printf(handle, "Total allocated space: %d\r\n", mi.uordblks); + return SHELLMATTA_OK; } @@ -352,11 +363,11 @@ static shellmatta_cmd_t cmd[10] = { .next = &cmd[8], }, { - .cmd = "get-stack-pointer", - .cmdAlias = "sp", - .helpText = "Get the stack pointer", + .cmd = "meminfo", + .cmdAlias = NULL, + .helpText = "Get information about memory usage", .usageText = "", - .cmdFct = shell_get_sp, + .cmdFct = shell_meminfo, .next = &cmd[9], }, {