Integrate the new heap implementation from InfiniTime (https://github.com/InfiniTimeOrg/InfiniTime/pull/1709).

Since FreeRTOS.h, portmacro_cmsis.h and task.h are now built in C (by lv_mem.c), I had to change some includes and declarations to make them compatible with a C compiler.

Integrating the new memory management from InfiniTime in InfiniSim is not easy because InfiniSim does not include the whole FreeRTOS. Which means that, for example, pvPortMalloc() and vPortFree() are not accessible from InfiniSim.
As a first step, I provided custom implementations for pvPortMalloc(), vPortFree() which are based on ... malloc(). These function keep track of the memory that is currently allocated so that xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize() return something.

Not that this implementation do not keep track of all the memory allocations done in InfiniTime. It can only "see" those done via pvPortMalloc(). It means that the available memory displayed by InfiniSim will probably be very optimistic.
This commit is contained in:
Jean-François Milants
2023-04-09 12:17:10 +02:00
committed by Reinhold Gschweicher
parent e416f2cf74
commit 8ae5ba7c0a
5 changed files with 87 additions and 31 deletions

View File

@@ -59,21 +59,17 @@
#define NRF_ERROR_FORBIDDEN (NRF_ERROR_BASE_NUM + 15) ///< Forbidden Operation
#define NRF_ERROR_INVALID_ADDR (NRF_ERROR_BASE_NUM + 16) ///< Bad Memory Address
#define NRF_ERROR_BUSY (NRF_ERROR_BASE_NUM + 17) ///< Busy
#include <stdexcept>
#include <string> // std::to_string()
template<typename T>
void APP_ERROR_HANDLER(T err) {
throw std::runtime_error("APP_ERROR_HANDLER: " + std::to_string(err));
}
struct SCB_t {
unsigned ICSR = 0;
};
void APP_ERROR_HANDLER(int err);
typedef struct SCB_t {
unsigned ICSR;
} SCB_t;
static SCB_t SCB_member;
static SCB_t *SCB = &SCB_member;
//#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
constexpr unsigned SCB_ICSR_VECTACTIVE_Msk = 0x01;
const unsigned SCB_ICSR_VECTACTIVE_Msk = 0x01;
/**
\brief System Reset
@@ -82,4 +78,21 @@ constexpr unsigned SCB_ICSR_VECTACTIVE_Msk = 0x01;
// copied from nRF5_SDK_15.3.0_59ac345/components/toolchain/cmsis/include/core_cm4.h
void NVIC_SystemReset(void);
#include <stddef.h>
#define configTOTAL_HEAP_SIZE (1024 * 40)
size_t xPortGetFreeHeapSize(void);
size_t xPortGetMinimumEverFreeHeapSize(void);
#ifdef __cplusplus
extern "C" {
#endif
void *pvPortMalloc(size_t xWantedSize);
void vPortFree(void *pv);
#ifdef __cplusplus
}
#endif
#endif /* INC_FREERTOS_H */