Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CMSIS): Adding mallinfo function and reworking Cordio memory management. #1179

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
78 changes: 51 additions & 27 deletions Examples/MAX32655/Bluetooth/BLE4_ctr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ static void mainLoadConfiguration(void)
/*************************************************************************************************/
static void mainWsfInit(void)
{
uint32_t llmemUsed, memUsed;

mainLoadConfiguration();

/* +12 for message headroom, +4 for header. */
const uint16_t aclBufSize = 12 + mainLlRtCfg.maxAclLen + 4 + BB_DATA_PDU_TAILROOM;

Expand All @@ -105,24 +109,67 @@ static void mainWsfInit(void)

const uint8_t numPools = sizeof(poolDesc) / sizeof(poolDesc[0]);

/* Calculate how much memory we will need for the LL initialization */
WsfCsEnter();

LlInitRtCfg_t llCfg = {
.pBbRtCfg = &mainBbRtCfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &mainLlRtCfg,
/* Not significant yet, only being used for memory size requirement calculation. */
.pFreeMem = WsfHeapGetFreeStartAddress(),
/* Not significant yet, only being used for memory size requirement calculation. */
.freeMemAvail = WsfHeapCountAvailable()
};

llmemUsed = LlInitSetBbRtCfg(llCfg.pBbRtCfg, llCfg.wlSizeCfg, llCfg.rlSizeCfg, llCfg.plSizeCfg,
llCfg.pFreeMem, llCfg.freeMemAvail);

llCfg.pFreeMem += llmemUsed;
llCfg.freeMemAvail -= llmemUsed;

llmemUsed += LlInitSetLlRtCfg(llCfg.pLlRtCfg, llCfg.pFreeMem, llCfg.freeMemAvail);

WsfCsExit();

/* Initial buffer configuration. */
uint16_t memUsed;
WsfCsEnter();
memUsed = WsfBufInit(numPools, poolDesc);
memUsed = WsfBufCalcSize(numPools, poolDesc);
WsfHeapAlloc(memUsed);
WsfBufInit(numPools, poolDesc);
WsfCsExit();

WsfOsInit();
WsfTimerInit();

#if (WSF_TRACE_ENABLED == TRUE)
WsfCsEnter();
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfHeapAlloc(memUsed);
WsfHeapAlloc(PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfCsExit();

WsfTraceRegisterHandler(WsfBufIoWrite);
WsfTraceEnable(TRUE);
#endif

/* Complete the LL initialization */
WsfCsEnter();

/* Allocate the memory */
WsfHeapAlloc(llmemUsed);

/* Set the free memory pointers */
llCfg.pFreeMem = WsfHeapGetFreeStartAddress();
llCfg.freeMemAvail = WsfHeapCountAvailable();

/* Run the initialization with properly set the free memory pointers */
if (llmemUsed != LlInitControllerInit(&llCfg)) {
WSF_ASSERT(0);
}

WsfCsExit();
}

/*************************************************************************************************/
Expand Down Expand Up @@ -164,31 +211,8 @@ static bool mainCheckServiceTokens(void)
/*************************************************************************************************/
int main(void)
{
uint32_t memUsed;

mainLoadConfiguration();
mainWsfInit();

#if (WSF_TRACE_ENABLED == TRUE)
WsfCsEnter();
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfHeapAlloc(memUsed);
WsfCsExit();
#endif

WsfCsEnter();
LlInitRtCfg_t llCfg = { .pBbRtCfg = &mainBbRtCfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &mainLlRtCfg,
.pFreeMem = WsfHeapGetFreeStartAddress(),
.freeMemAvail = WsfHeapCountAvailable() };

memUsed = LlInitControllerInit(&llCfg);
WsfHeapAlloc(memUsed);
WsfCsExit();

bdAddr_t bdAddr;
PalCfgLoadData(PAL_CFG_ID_BD_ADDR, bdAddr, sizeof(bdAddr_t));
/* Coverity[uninit_use_in_call] */
Expand Down
78 changes: 51 additions & 27 deletions Examples/MAX32655/Bluetooth/BLE5_ctr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ static void mainLoadConfiguration(void)
/*************************************************************************************************/
static void mainWsfInit(void)
{
uint32_t llmemUsed, memUsed;

mainLoadConfiguration();

/* +12 for message headroom, + 2 event header, +255 maximum parameter length. */
const uint16_t maxRptBufSize = 12 + 2 + 255;

Expand All @@ -137,24 +141,67 @@ static void mainWsfInit(void)

const uint8_t numPools = sizeof(poolDesc) / sizeof(poolDesc[0]);

/* Calculate how much memory we will need for the LL initialization */
WsfCsEnter();

LlInitRtCfg_t llCfg = {
.pBbRtCfg = &mainBbRtCfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &mainLlRtCfg,
/* Not significant yet, only being used for memory size requirement calculation. */
.pFreeMem = WsfHeapGetFreeStartAddress(),
/* Not significant yet, only being used for memory size requirement calculation. */
.freeMemAvail = WsfHeapCountAvailable()
};

llmemUsed = LlInitSetBbRtCfg(llCfg.pBbRtCfg, llCfg.wlSizeCfg, llCfg.rlSizeCfg, llCfg.plSizeCfg,
llCfg.pFreeMem, llCfg.freeMemAvail);

llCfg.pFreeMem += llmemUsed;
llCfg.freeMemAvail -= llmemUsed;

llmemUsed += LlInitSetLlRtCfg(llCfg.pLlRtCfg, llCfg.pFreeMem, llCfg.freeMemAvail);

WsfCsExit();

/* Initial buffer configuration. */
uint16_t memUsed;
WsfCsEnter();
memUsed = WsfBufInit(numPools, poolDesc);
memUsed = WsfBufCalcSize(numPools, poolDesc);
WsfHeapAlloc(memUsed);
WsfBufInit(numPools, poolDesc);
WsfCsExit();

WsfOsInit();
WsfTimerInit();

#if (WSF_TRACE_ENABLED == TRUE)
WsfCsEnter();
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfHeapAlloc(memUsed);
WsfHeapAlloc(PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfCsExit();

WsfTraceRegisterHandler(WsfBufIoWrite);
WsfTraceEnable(TRUE);
#endif

/* Complete the LL initialization */
WsfCsEnter();

/* Allocate the memory */
WsfHeapAlloc(llmemUsed);

/* Set the free memory pointers */
llCfg.pFreeMem = WsfHeapGetFreeStartAddress();
llCfg.freeMemAvail = WsfHeapCountAvailable();

/* Run the initialization with properly set the free memory pointers */
if (llmemUsed != LlInitControllerInit(&llCfg)) {
WSF_ASSERT(0);
}

WsfCsExit();
}

/*************************************************************************************************/
Expand Down Expand Up @@ -249,31 +296,8 @@ void setInterruptPriority(void)
/*************************************************************************************************/
int main(void)
{
uint32_t memUsed;

mainLoadConfiguration();
mainWsfInit();

#if (WSF_TRACE_ENABLED == TRUE)
WsfCsEnter();
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfHeapAlloc(memUsed);
WsfCsExit();
#endif

WsfCsEnter();
LlInitRtCfg_t llCfg = { .pBbRtCfg = &mainBbRtCfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &mainLlRtCfg,
.pFreeMem = WsfHeapGetFreeStartAddress(),
.freeMemAvail = WsfHeapCountAvailable() };

memUsed = LlInitControllerInit(&llCfg);
WsfHeapAlloc(memUsed);
WsfCsExit();

bdAddr_t bdAddr;
PalCfgLoadData(PAL_CFG_ID_BD_ADDR, bdAddr, sizeof(bdAddr_t));
/* Coverity[uninit_use_in_call] */
Expand Down
61 changes: 47 additions & 14 deletions Examples/MAX32655/Bluetooth/BLE_FreeRTOS/stack_dats.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ static void mainWsfInit(void)
const uint8_t numPools = sizeof(mainPoolDesc) / sizeof(mainPoolDesc[0]);

uint16_t memUsed;
/* Initial buffer configuration. */
WsfCsEnter();
memUsed = WsfBufInit(numPools, mainPoolDesc);
memUsed = WsfBufCalcSize(numPools, mainPoolDesc);
WsfHeapAlloc(memUsed);
WsfBufInit(numPools, mainPoolDesc);
WsfCsExit();

WsfOsInit();
Expand Down Expand Up @@ -327,27 +329,58 @@ void bleStartup(void)
mainLlRtCfg.defTxPwrLvl = DEFAULT_TX_POWER;
#endif

uint32_t memUsed;
WsfCsEnter();
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfHeapAlloc(memUsed);
WsfHeapAlloc(PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
WsfCsExit();

mainWsfInit();
AppTerminalInit();

#if defined(HCI_TR_EXACTLE) && (HCI_TR_EXACTLE == 1)
uint32_t llmemUsed;

/* Calculate how much memory we will need for the LL initialization */
WsfCsEnter();
LlInitRtCfg_t llCfg = { .pBbRtCfg = &mainBbRtCfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &mainLlRtCfg,
.pFreeMem = WsfHeapGetFreeStartAddress(),
.freeMemAvail = WsfHeapCountAvailable() };

memUsed = LlInit(&llCfg);
WsfHeapAlloc(memUsed);

WsfTraceEnable(FALSE);

LlInitRtCfg_t llCfg = {
.pBbRtCfg = &mainBbRtCfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &mainLlRtCfg,
/* Not significant yet, only being used for memory size requirement calculation. */
.pFreeMem = WsfHeapGetFreeStartAddress(),
/* Not significant yet, only being used for memory size requirement calculation. */
.freeMemAvail = WsfHeapCountAvailable()
};

llmemUsed = LlInitSetBbRtCfg(llCfg.pBbRtCfg, llCfg.wlSizeCfg, llCfg.rlSizeCfg, llCfg.plSizeCfg,
llCfg.pFreeMem, llCfg.freeMemAvail);

llCfg.pFreeMem += llmemUsed;
llCfg.freeMemAvail -= llmemUsed;

llmemUsed += LlInitSetLlRtCfg(llCfg.pLlRtCfg, llCfg.pFreeMem, llCfg.freeMemAvail);

/* Allocate the memory */
WsfHeapAlloc(llmemUsed);

/* Set the free memory pointers */
llCfg.pFreeMem = WsfHeapGetFreeStartAddress();
llCfg.freeMemAvail = WsfHeapCountAvailable();

#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE)
WsfTraceEnable(TRUE);
#endif

/* Run the initialization with properly set the free memory pointers */
if (llmemUsed != LlInitControllerInit(&llCfg)) {
WSF_ASSERT(0);
}

WsfCsExit();

bdAddr_t bdAddr;
Expand Down
Loading