diff --git a/meson.build b/meson.build index adb97da9..b1430809 100644 --- a/meson.build +++ b/meson.build @@ -24,7 +24,8 @@ openrtx_src = ['openrtx/src/state.c', 'openrtx/src/calibUtils.c', 'openrtx/src/queue.c', 'openrtx/src/rtx.c', - 'openrtx/src/gps.c'] + 'openrtx/src/gps.c', + 'openrtx/src/memory_profiling.cpp'] openrtx_inc = ['openrtx/include', 'openrtx/include/calibration', diff --git a/openrtx/include/memory_profiling.h b/openrtx/include/memory_profiling.h new file mode 100644 index 00000000..a8d43636 --- /dev/null +++ b/openrtx/include/memory_profiling.h @@ -0,0 +1,75 @@ +/*************************************************************************** + * Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN, * + * Frederik Saraci IU2NRO, * + * Silvano Seva IU2KWO * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#ifndef MEMORY_PROFILING_H +#define MEMORY_PROFILING_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \return stack size of the caller thread. + */ +unsigned int getStackSize(); + +/** + * \return absolute free stack of current thread. + * Absolute free stack is the minimum free stack since the thread was + * created. + */ +unsigned int getAbsoluteFreeStack(); + +/** + * \return current free stack of current thread. + * Current free stack is the free stack at the moment when the this + * function is called. + */ +unsigned int getCurrentFreeStack(); + +/** + * \return heap size which is defined in the linker script The heap is + * shared among all threads, therefore this function returns the same value + * regardless which thread is called in. + */ +unsigned int getHeapSize(); + +/** + * \return absolute (not current) free heap. + * Absolute free heap is the minimum free heap since the program started. + * The heap is shared among all threads, therefore this function returns + * the same value regardless which thread is called in. + */ +unsigned int getAbsoluteFreeHeap(); + +/** + * \return current free heap. + * Current free heap is the free heap at the moment when the this + * function is called. + * The heap is shared among all threads, therefore this function returns + * the same value regardless which thread is called in. + */ +unsigned int getCurrentFreeHeap(); + +#ifdef __cplusplus +} +#endif + +#endif /* MEMORY_PROFILING_H */ diff --git a/openrtx/src/memory_profiling.cpp b/openrtx/src/memory_profiling.cpp new file mode 100644 index 00000000..2b0609e3 --- /dev/null +++ b/openrtx/src/memory_profiling.cpp @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN, * + * Frederik Saraci IU2NRO, * + * Silvano Seva IU2KWO * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#include +#include + +/* + * Provide a C-callable wrapper for the corresponding miosix functions. + */ + +unsigned int getStackSize() +{ + return miosix::MemoryProfiling::getStackSize(); +} + +unsigned int getAbsoluteFreeStack() +{ + return miosix::MemoryProfiling::getAbsoluteFreeStack(); +} + +unsigned int getCurrentFreeStack() +{ + return miosix::MemoryProfiling::getCurrentFreeStack(); +} + +unsigned int getHeapSize() +{ + return miosix::MemoryProfiling::getHeapSize(); +} + +unsigned int getAbsoluteFreeHeap() +{ + return miosix::MemoryProfiling::getAbsoluteFreeHeap(); +} + +unsigned int getCurrentFreeHeap() +{ + /* + * BUG: calling getCurrentFreeHeap() leads to a program crash. + * Investigation about this issue has to be deferred until a working error + * handler is implemented. + */ + //return miosix::MemoryProfiling::getCurrentFreeHeap(); + return getAbsoluteFreeHeap(); +}