diff --git a/Examples/MAX32655/Bluetooth/BLE4_ctr/main.c b/Examples/MAX32655/Bluetooth/BLE4_ctr/main.c index d477d982d98..5ec58f481f7 100644 --- a/Examples/MAX32655/Bluetooth/BLE4_ctr/main.c +++ b/Examples/MAX32655/Bluetooth/BLE4_ctr/main.c @@ -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; @@ -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(); } /*************************************************************************************************/ @@ -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] */ diff --git a/Examples/MAX32655/Bluetooth/BLE5_ctr/main.c b/Examples/MAX32655/Bluetooth/BLE5_ctr/main.c index b3f59a29f05..ba57fb748a6 100644 --- a/Examples/MAX32655/Bluetooth/BLE5_ctr/main.c +++ b/Examples/MAX32655/Bluetooth/BLE5_ctr/main.c @@ -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; @@ -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(); } /*************************************************************************************************/ @@ -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] */ diff --git a/Examples/MAX32655/Bluetooth/BLE_FreeRTOS/stack_dats.c b/Examples/MAX32655/Bluetooth/BLE_FreeRTOS/stack_dats.c index c38bc6e9f33..e3537f13a05 100644 --- a/Examples/MAX32655/Bluetooth/BLE_FreeRTOS/stack_dats.c +++ b/Examples/MAX32655/Bluetooth/BLE_FreeRTOS/stack_dats.c @@ -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(); @@ -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; diff --git a/Examples/MAX32655/Bluetooth/BLE_datc/main.c b/Examples/MAX32655/Bluetooth/BLE_datc/main.c index 79d4df10763..9a995bcb04a 100644 --- a/Examples/MAX32655/Bluetooth/BLE_datc/main.c +++ b/Examples/MAX32655/Bluetooth/BLE_datc/main.c @@ -115,9 +115,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(); @@ -213,27 +215,60 @@ int main(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); + +#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE) + WsfTraceEnable(TRUE); +#endif + + /* Complete the LL initialization */ + /* 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 != LlInit(&llCfg)) { + WSF_ASSERT(0); + } + WsfCsExit(); bdAddr_t bdAddr; diff --git a/Examples/MAX32655/Bluetooth/BLE_dats/main.c b/Examples/MAX32655/Bluetooth/BLE_dats/main.c index 7e3cf7c7d05..7ee4f104b20 100644 --- a/Examples/MAX32655/Bluetooth/BLE_dats/main.c +++ b/Examples/MAX32655/Bluetooth/BLE_dats/main.c @@ -115,9 +115,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(); @@ -208,10 +210,9 @@ int main(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(); @@ -219,17 +220,50 @@ int main(void) #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); + +#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE) + WsfTraceEnable(TRUE); +#endif + + /* Complete the LL initialization */ + /* 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 != LlInit(&llCfg)) { + WSF_ASSERT(0); + } + WsfCsExit(); bdAddr_t bdAddr; diff --git a/Examples/MAX32655/Bluetooth/BLE_fit/main.c b/Examples/MAX32655/Bluetooth/BLE_fit/main.c index d583cbf6d79..eb8a2b92af7 100644 --- a/Examples/MAX32655/Bluetooth/BLE_fit/main.c +++ b/Examples/MAX32655/Bluetooth/BLE_fit/main.c @@ -115,9 +115,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(); @@ -194,27 +196,60 @@ int main(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); + +#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE) + WsfTraceEnable(TRUE); +#endif + + /* Complete the LL initialization */ + /* 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 != LlInit(&llCfg)) { + WSF_ASSERT(0); + } + WsfCsExit(); bdAddr_t bdAddr; diff --git a/Examples/MAX32655/Bluetooth/BLE_fit_FreeRTOS/bt_stack.c b/Examples/MAX32655/Bluetooth/BLE_fit_FreeRTOS/bt_stack.c index cd11150b38e..ea3a3c088e4 100644 --- a/Examples/MAX32655/Bluetooth/BLE_fit_FreeRTOS/bt_stack.c +++ b/Examples/MAX32655/Bluetooth/BLE_fit_FreeRTOS/bt_stack.c @@ -172,9 +172,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(); @@ -327,10 +329,10 @@ void btStartup(void) mainLlRtCfg.defTxPwrLvl = DEFAULT_TX_POWER; #endif - uint32_t memUsed; + uint32_t llmemUsed; 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(); @@ -338,17 +340,47 @@ void btStartup(void) AppTerminalInit(); #if defined(HCI_TR_EXACTLE) && (HCI_TR_EXACTLE == 1) + /* 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; diff --git a/Examples/MAX32655/Bluetooth/BLE_mcs/main.c b/Examples/MAX32655/Bluetooth/BLE_mcs/main.c index a53eb4a80ca..a1f96ee038c 100644 --- a/Examples/MAX32655/Bluetooth/BLE_mcs/main.c +++ b/Examples/MAX32655/Bluetooth/BLE_mcs/main.c @@ -111,9 +111,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(); @@ -182,27 +184,60 @@ int main(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); + +#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE) + WsfTraceEnable(TRUE); +#endif + + /* Complete the LL initialization */ + /* 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 != LlInit(&llCfg)) { + WSF_ASSERT(0); + } + WsfCsExit(); bdAddr_t bdAddr; diff --git a/Examples/MAX32655/Bluetooth/BLE_otac/main.c b/Examples/MAX32655/Bluetooth/BLE_otac/main.c index 49d7d9f6202..c53c51a7ce1 100644 --- a/Examples/MAX32655/Bluetooth/BLE_otac/main.c +++ b/Examples/MAX32655/Bluetooth/BLE_otac/main.c @@ -116,9 +116,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(); @@ -209,27 +211,60 @@ int main(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); + +#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE) + WsfTraceEnable(TRUE); +#endif + + /* Complete the LL initialization */ + /* 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 != LlInit(&llCfg)) { + WSF_ASSERT(0); + } + WsfCsExit(); bdAddr_t bdAddr; diff --git a/Examples/MAX32655/Bluetooth/BLE_otas/main.c b/Examples/MAX32655/Bluetooth/BLE_otas/main.c index c4f2320eaa4..9e6db92ef67 100644 --- a/Examples/MAX32655/Bluetooth/BLE_otas/main.c +++ b/Examples/MAX32655/Bluetooth/BLE_otas/main.c @@ -116,19 +116,20 @@ 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(); WsfTimerInit(); - #if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE) WsfCsEnter(); + WsfHeapAlloc(PLATFORM_UART_TERMINAL_BUFFER_SIZE); memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE); - WsfHeapAlloc(memUsed); WsfCsExit(); WsfTraceRegisterHandler(WsfBufIoWrite); @@ -188,8 +189,6 @@ void setAdvTxPower(void) /*************************************************************************************************/ int main(void) { - uint32_t memUsed; - #if defined(HCI_TR_EXACTLE) && (HCI_TR_EXACTLE == 1) /* Configurations must be persistent. */ static BbRtCfg_t mainBbRtCfg; @@ -224,17 +223,51 @@ int main(void) mainWsfInit(); #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); + +#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE) + WsfTraceEnable(TRUE); +#endif + + /* Complete the LL initialization */ + /* 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 != LlInit(&llCfg)) { + WSF_ASSERT(0); + } + WsfCsExit(); bdAddr_t bdAddr; diff --git a/Examples/MAX32655/Bluetooth/BLE_periph/main.c b/Examples/MAX32655/Bluetooth/BLE_periph/main.c index d4b86f7c404..65cc788f9f8 100644 --- a/Examples/MAX32655/Bluetooth/BLE_periph/main.c +++ b/Examples/MAX32655/Bluetooth/BLE_periph/main.c @@ -131,8 +131,8 @@ static void mainWsfInit(void) 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(); #if defined(HCI_TR_EXACTLE) && (HCI_TR_EXACTLE == 1) @@ -151,32 +151,56 @@ static void mainWsfInit(void) const uint8_t numPools = sizeof(mainPoolDesc) / sizeof(mainPoolDesc[0]); + /* Initial buffer configuration. */ WsfCsEnter(); - memUsed = WsfBufInit(numPools, mainPoolDesc); + memUsed = WsfBufCalcSize(numPools, mainPoolDesc); WsfHeapAlloc(memUsed); + WsfBufInit(numPools, mainPoolDesc); WsfCsExit(); WsfOsInit(); WsfTimerInit(); -#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE) - WsfTraceRegisterHandler(WsfBufIoWrite); - WsfTraceEnable(TRUE); -#endif 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); + + 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(); + + /* Run the initialization with properly set the free memory pointers */ + if (llmemUsed != LlInitControllerInit(&llCfg)) { + WSF_ASSERT(0); + } + WsfCsExit(); bdAddr_t bdAddr; @@ -184,6 +208,11 @@ static void mainWsfInit(void) LlSetBdAddr((uint8_t *)&bdAddr); #endif +#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE) + WsfTraceRegisterHandler(WsfBufIoWrite); + WsfTraceEnable(TRUE); +#endif + StackInitPeriph(); PeriphStart(); diff --git a/Examples/MAX32655/Bluetooth/RF_Test/main.c b/Examples/MAX32655/Bluetooth/RF_Test/main.c index 459bfac8cef..66b21543a2a 100644 --- a/Examples/MAX32655/Bluetooth/RF_Test/main.c +++ b/Examples/MAX32655/Bluetooth/RF_Test/main.c @@ -514,8 +514,13 @@ static void mainWsfInit(void) /* Initial buffer configuration. */ uint16_t memUsed; - memUsed = WsfBufInit(numPools, poolDesc); + /* Initial buffer configuration. */ + WsfCsEnter(); + memUsed = WsfBufCalcSize(numPools, poolDesc); WsfHeapAlloc(memUsed); + WsfBufInit(numPools, poolDesc); + WsfCsExit(); + WsfOsInit(); WsfTimerInit(); #if (WSF_TRACE_ENABLED == TRUE) @@ -857,26 +862,54 @@ void printConfigs(void) /*************************************************************************************************/ int main(void) { - uint32_t memUsed; + uint32_t llmemUsed; mainLoadConfiguration(); mainWsfInit(); #if (WSF_TRACE_ENABLED == TRUE) - memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE); - WsfHeapAlloc(memUsed); + WsfCsEnter(); + WsfHeapAlloc(PLATFORM_UART_TERMINAL_BUFFER_SIZE); + WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE); + WsfCsExit(); #endif - LlInitRtCfg_t llCfg = { .pBbRtCfg = &mainBbRtCfg, - .wlSizeCfg = 4, - .rlSizeCfg = 4, - .plSizeCfg = 4, - .pLlRtCfg = &mainLlRtCfg, - .pFreeMem = WsfHeapGetFreeStartAddress(), - .freeMemAvail = WsfHeapCountAvailable() }; + /* 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() + }; - memUsed = LlInitControllerInit(&llCfg); - WsfHeapAlloc(memUsed); + 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(); + + /* Run the initialization with properly set the free memory pointers */ + if (llmemUsed != LlInitControllerInit(&llCfg)) { + WSF_ASSERT(0); + } + + WsfCsExit(); bdAddr_t bdAddr; PalCfgLoadData(PAL_CFG_ID_BD_ADDR, bdAddr, sizeof(bdAddr_t)); diff --git a/Examples/MAX32655/Bluetooth/RF_Test/main.h b/Examples/MAX32655/Bluetooth/RF_Test/main.h index ba8486b1f02..a082659f7ec 100644 --- a/Examples/MAX32655/Bluetooth/RF_Test/main.h +++ b/Examples/MAX32655/Bluetooth/RF_Test/main.h @@ -41,6 +41,7 @@ #include "wsf_timer.h" #include "wsf_trace.h" #include "wsf_bufio.h" +#include "wsf_cs.h" #include "bb_ble_sniffer_api.h" #include "pal_bb.h" #include "pal_cfg.h" diff --git a/Examples/MAX32665/Bluetooth/BLE4_ctr/main.c b/Examples/MAX32665/Bluetooth/BLE4_ctr/main.c index d477d982d98..5ec58f481f7 100644 --- a/Examples/MAX32665/Bluetooth/BLE4_ctr/main.c +++ b/Examples/MAX32665/Bluetooth/BLE4_ctr/main.c @@ -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; @@ -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(); } /*************************************************************************************************/ @@ -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] */ diff --git a/Examples/MAX32665/Bluetooth/BLE5_ctr/main.c b/Examples/MAX32665/Bluetooth/BLE5_ctr/main.c index 62ff05a1c54..c842b6d9739 100644 --- a/Examples/MAX32665/Bluetooth/BLE5_ctr/main.c +++ b/Examples/MAX32665/Bluetooth/BLE5_ctr/main.c @@ -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; @@ -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(); } /*************************************************************************************************/ @@ -267,31 +314,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] */ diff --git a/Examples/MAX32690/Bluetooth/BLE4_ctr/main.c b/Examples/MAX32690/Bluetooth/BLE4_ctr/main.c index d477d982d98..5ec58f481f7 100644 --- a/Examples/MAX32690/Bluetooth/BLE4_ctr/main.c +++ b/Examples/MAX32690/Bluetooth/BLE4_ctr/main.c @@ -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; @@ -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(); } /*************************************************************************************************/ @@ -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] */ diff --git a/Examples/MAX32690/Bluetooth/BLE5_ctr/main.c b/Examples/MAX32690/Bluetooth/BLE5_ctr/main.c index f4b076f5f24..c44c9caadd9 100644 --- a/Examples/MAX32690/Bluetooth/BLE5_ctr/main.c +++ b/Examples/MAX32690/Bluetooth/BLE5_ctr/main.c @@ -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; @@ -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(); } /*************************************************************************************************/ @@ -251,31 +298,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] */ diff --git a/Examples/MAX32690/Bluetooth/BLE_datc/main.c b/Examples/MAX32690/Bluetooth/BLE_datc/main.c index 060c2a2a01e..98d3c583254 100644 --- a/Examples/MAX32690/Bluetooth/BLE_datc/main.c +++ b/Examples/MAX32690/Bluetooth/BLE_datc/main.c @@ -116,8 +116,9 @@ static void mainWsfInit(void) uint16_t memUsed; WsfCsEnter(); - memUsed = WsfBufInit(numPools, mainPoolDesc); + memUsed = WsfBufCalcSize(numPools, mainPoolDesc); WsfHeapAlloc(memUsed); + WsfBufInit(numPools, mainPoolDesc); WsfCsExit(); WsfOsInit(); @@ -213,27 +214,61 @@ int main(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); + +#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE) + WsfTraceEnable(TRUE); +#endif + + /* Complete the LL initialization */ + /* 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 != LlInit(&llCfg)) { + WSF_ASSERT(0); + } + WsfCsExit(); bdAddr_t bdAddr; diff --git a/Libraries/CMSIS/Device/Maxim/MAX32655/Source/heap.c b/Libraries/CMSIS/Device/Maxim/MAX32655/Source/heap.c index 80559e95034..4409f35aff9 100644 --- a/Libraries/CMSIS/Device/Maxim/MAX32655/Source/heap.c +++ b/Libraries/CMSIS/Device/Maxim/MAX32655/Source/heap.c @@ -21,6 +21,7 @@ #include #include #include +#include /* sbrk @@ -48,3 +49,79 @@ caddr_t _sbrk(int incr) return (caddr_t)prev_heap_end; } + +// struct mallinfo { +// size_t arena; /* total space allocated from system */ +// size_t ordblks; /* number of non-inuse chunks */ +// size_t smblks; /* unused -- always zero */ +// size_t hblks; /* number of mmapped regions */ +// size_t hblkhd; /* total space in mmapped regions */ +// size_t usmblks; /* unused -- always zero */ +// size_t fsmblks; /* unused -- always zero */ +// size_t uordblks; /* total allocated space */ +// size_t fordblks; /* total non-inuse space */ +// size_t keepcost; /* top-most, releasable (via malloc_trim) space */ +// }; + +/* +The structure fields contain the following information: + + arena The total amount of memory allocated by means other than + mmap(2) (i.e., memory allocated on the heap). This figure + includes both in-use blocks and blocks on the free list. + + ordblks + The number of ordinary (i.e., non-fastbin) free blocks. + + smblks The number of fastbin free blocks (see mallopt(3)). + + hblks The number of blocks currently allocated using mmap(2). + (See the discussion of M_MMAP_THRESHOLD in mallopt(3).) + + hblkhd The number of bytes in blocks currently allocated using + mmap(2). + + usmblks + This field is unused, and is always 0. Historically, it + was the "highwater mark" for allocated space—that is, the + maximum amount of space that was ever allocated (in + bytes); this field was maintained only in nonthreading + environments. + + fsmblks + The total number of bytes in fastbin free blocks. + + uordblks + The total number of bytes used by in-use allocations. + + fordblks + The total number of bytes in free blocks. + + keepcost + The total amount of releasable free space at the top of + the heap. This is the maximum number of bytes that could + ideally (i.e., ignoring page alignment restrictions, and + so on) be released by malloc_trim(3). +*/ + +struct mallinfo mallinfo(void) +{ + struct mallinfo temp_mallinfo; + + if (heap_end == 0) { + heap_end = (caddr_t)&__HeapBase; + } + + temp_mallinfo.arena = ((size_t)&__HeapLimit - (size_t)&__HeapBase); + temp_mallinfo.ordblks = 0; /* Unused */ + temp_mallinfo.smblks = 0; /* Unused */ + temp_mallinfo.hblks = 0; /* Unused */ + temp_mallinfo.hblkhd = 0; /* Unused */ + temp_mallinfo.usmblks = 0; /* Unused */ + temp_mallinfo.fsmblks = 0; /* Unused */ + temp_mallinfo.uordblks = (size_t)heap_end - (size_t)&__HeapBase; + temp_mallinfo.fordblks = (size_t)&__HeapLimit - (size_t)heap_end; + temp_mallinfo.keepcost = 0 /* Unused */; + + return temp_mallinfo; +} diff --git a/Libraries/CMSIS/Device/Maxim/MAX32665/Source/heap.c b/Libraries/CMSIS/Device/Maxim/MAX32665/Source/heap.c index 80559e95034..4409f35aff9 100644 --- a/Libraries/CMSIS/Device/Maxim/MAX32665/Source/heap.c +++ b/Libraries/CMSIS/Device/Maxim/MAX32665/Source/heap.c @@ -21,6 +21,7 @@ #include #include #include +#include /* sbrk @@ -48,3 +49,79 @@ caddr_t _sbrk(int incr) return (caddr_t)prev_heap_end; } + +// struct mallinfo { +// size_t arena; /* total space allocated from system */ +// size_t ordblks; /* number of non-inuse chunks */ +// size_t smblks; /* unused -- always zero */ +// size_t hblks; /* number of mmapped regions */ +// size_t hblkhd; /* total space in mmapped regions */ +// size_t usmblks; /* unused -- always zero */ +// size_t fsmblks; /* unused -- always zero */ +// size_t uordblks; /* total allocated space */ +// size_t fordblks; /* total non-inuse space */ +// size_t keepcost; /* top-most, releasable (via malloc_trim) space */ +// }; + +/* +The structure fields contain the following information: + + arena The total amount of memory allocated by means other than + mmap(2) (i.e., memory allocated on the heap). This figure + includes both in-use blocks and blocks on the free list. + + ordblks + The number of ordinary (i.e., non-fastbin) free blocks. + + smblks The number of fastbin free blocks (see mallopt(3)). + + hblks The number of blocks currently allocated using mmap(2). + (See the discussion of M_MMAP_THRESHOLD in mallopt(3).) + + hblkhd The number of bytes in blocks currently allocated using + mmap(2). + + usmblks + This field is unused, and is always 0. Historically, it + was the "highwater mark" for allocated space—that is, the + maximum amount of space that was ever allocated (in + bytes); this field was maintained only in nonthreading + environments. + + fsmblks + The total number of bytes in fastbin free blocks. + + uordblks + The total number of bytes used by in-use allocations. + + fordblks + The total number of bytes in free blocks. + + keepcost + The total amount of releasable free space at the top of + the heap. This is the maximum number of bytes that could + ideally (i.e., ignoring page alignment restrictions, and + so on) be released by malloc_trim(3). +*/ + +struct mallinfo mallinfo(void) +{ + struct mallinfo temp_mallinfo; + + if (heap_end == 0) { + heap_end = (caddr_t)&__HeapBase; + } + + temp_mallinfo.arena = ((size_t)&__HeapLimit - (size_t)&__HeapBase); + temp_mallinfo.ordblks = 0; /* Unused */ + temp_mallinfo.smblks = 0; /* Unused */ + temp_mallinfo.hblks = 0; /* Unused */ + temp_mallinfo.hblkhd = 0; /* Unused */ + temp_mallinfo.usmblks = 0; /* Unused */ + temp_mallinfo.fsmblks = 0; /* Unused */ + temp_mallinfo.uordblks = (size_t)heap_end - (size_t)&__HeapBase; + temp_mallinfo.fordblks = (size_t)&__HeapLimit - (size_t)heap_end; + temp_mallinfo.keepcost = 0 /* Unused */; + + return temp_mallinfo; +} diff --git a/Libraries/CMSIS/Device/Maxim/MAX32690/Source/heap.c b/Libraries/CMSIS/Device/Maxim/MAX32690/Source/heap.c index 80559e95034..4409f35aff9 100644 --- a/Libraries/CMSIS/Device/Maxim/MAX32690/Source/heap.c +++ b/Libraries/CMSIS/Device/Maxim/MAX32690/Source/heap.c @@ -21,6 +21,7 @@ #include #include #include +#include /* sbrk @@ -48,3 +49,79 @@ caddr_t _sbrk(int incr) return (caddr_t)prev_heap_end; } + +// struct mallinfo { +// size_t arena; /* total space allocated from system */ +// size_t ordblks; /* number of non-inuse chunks */ +// size_t smblks; /* unused -- always zero */ +// size_t hblks; /* number of mmapped regions */ +// size_t hblkhd; /* total space in mmapped regions */ +// size_t usmblks; /* unused -- always zero */ +// size_t fsmblks; /* unused -- always zero */ +// size_t uordblks; /* total allocated space */ +// size_t fordblks; /* total non-inuse space */ +// size_t keepcost; /* top-most, releasable (via malloc_trim) space */ +// }; + +/* +The structure fields contain the following information: + + arena The total amount of memory allocated by means other than + mmap(2) (i.e., memory allocated on the heap). This figure + includes both in-use blocks and blocks on the free list. + + ordblks + The number of ordinary (i.e., non-fastbin) free blocks. + + smblks The number of fastbin free blocks (see mallopt(3)). + + hblks The number of blocks currently allocated using mmap(2). + (See the discussion of M_MMAP_THRESHOLD in mallopt(3).) + + hblkhd The number of bytes in blocks currently allocated using + mmap(2). + + usmblks + This field is unused, and is always 0. Historically, it + was the "highwater mark" for allocated space—that is, the + maximum amount of space that was ever allocated (in + bytes); this field was maintained only in nonthreading + environments. + + fsmblks + The total number of bytes in fastbin free blocks. + + uordblks + The total number of bytes used by in-use allocations. + + fordblks + The total number of bytes in free blocks. + + keepcost + The total amount of releasable free space at the top of + the heap. This is the maximum number of bytes that could + ideally (i.e., ignoring page alignment restrictions, and + so on) be released by malloc_trim(3). +*/ + +struct mallinfo mallinfo(void) +{ + struct mallinfo temp_mallinfo; + + if (heap_end == 0) { + heap_end = (caddr_t)&__HeapBase; + } + + temp_mallinfo.arena = ((size_t)&__HeapLimit - (size_t)&__HeapBase); + temp_mallinfo.ordblks = 0; /* Unused */ + temp_mallinfo.smblks = 0; /* Unused */ + temp_mallinfo.hblks = 0; /* Unused */ + temp_mallinfo.hblkhd = 0; /* Unused */ + temp_mallinfo.usmblks = 0; /* Unused */ + temp_mallinfo.fsmblks = 0; /* Unused */ + temp_mallinfo.uordblks = (size_t)heap_end - (size_t)&__HeapBase; + temp_mallinfo.fordblks = (size_t)&__HeapLimit - (size_t)heap_end; + temp_mallinfo.keepcost = 0 /* Unused */; + + return temp_mallinfo; +} diff --git a/Libraries/Cordio/controller/sources/ble/ll/ll_init.c b/Libraries/Cordio/controller/sources/ble/ll/ll_init.c index ffa938219ed..e0a5f5905f3 100644 --- a/Libraries/Cordio/controller/sources/ble/ll/ll_init.c +++ b/Libraries/Cordio/controller/sources/ble/ll/ll_init.c @@ -113,7 +113,7 @@ void LlGetDefaultRunTimeCfg(LlRtCfg_t *pCfg) /*************************************************************************************************/ void LlInitRunTimeCfg(const LlRtCfg_t *pCfg) { - WSF_ASSERT(pLctrRtCfg == NULL); +// WSF_ASSERT(pLctrRtCfg == NULL); WSF_ASSERT(pCfg); WSF_ASSERT(pCfg->btVer >= LL_VER_BT_CORE_SPEC_4_0); diff --git a/Libraries/Cordio/controller/sources/common/bb/bb_main.c b/Libraries/Cordio/controller/sources/common/bb/bb_main.c index aadddbc8331..17f2d718705 100644 --- a/Libraries/Cordio/controller/sources/common/bb/bb_main.c +++ b/Libraries/Cordio/controller/sources/common/bb/bb_main.c @@ -51,7 +51,7 @@ const BbRtCfg_t *pBbRtCfg = NULL; /*!< Runtime configuration. */ /*************************************************************************************************/ void BbInitRunTimeCfg(const BbRtCfg_t *pCfg) { - WSF_ASSERT(pBbRtCfg == NULL); + // WSF_ASSERT(pBbRtCfg == NULL); WSF_ASSERT(pCfg); WSF_ASSERT(pCfg->clkPpm >= 20); diff --git a/Libraries/Cordio/wsf/sources/targets/baremetal/wsf_heap.c b/Libraries/Cordio/wsf/sources/targets/baremetal/wsf_heap.c index 3c84251274a..992a98fabe9 100644 --- a/Libraries/Cordio/wsf/sources/targets/baremetal/wsf_heap.c +++ b/Libraries/Cordio/wsf/sources/targets/baremetal/wsf_heap.c @@ -24,6 +24,7 @@ #if defined ( __GNUC__ ) #include +#include #endif /* __GNUC__ */ #include "wsf_types.h" @@ -38,37 +39,16 @@ Macros **************************************************************************************************/ -#ifndef WSF_HEAP_SIZE -#if(PAL_CFG_LL_MAX == 1) -/* Larger link layer configurations will require more heap space. */ -#define WSF_HEAP_SIZE 0x18000 -#else -/* This is the minimum heap size. */ -#define WSF_HEAP_SIZE 0x8000 -#endif -#endif - /************************************************************************************************** Global Variables **************************************************************************************************/ -static void* freeStartAddr = 0; -static uint32_t freeLen = 0; - -/*************************************************************************************************/ -/*! - * \brief Initialize the heap memory. - */ -/*************************************************************************************************/ -static void wsfHeapInit(void) -{ - freeStartAddr = sbrk(WSF_HEAP_SIZE); - freeLen = WSF_HEAP_SIZE; -} +static void* freeStartAddr = NULL; +static uint32_t heapUsed = 0; /*************************************************************************************************/ /*! - * \brief Reserve heap memory. + * \brief Allocate heap memory. * * \param size Number of bytes of heap memory used. */ @@ -78,16 +58,8 @@ void WsfHeapAlloc(uint32_t size) /* Round up to nearest multiple of 4 for word alignment */ size = (size + 3) & ~3; - if(freeStartAddr == 0) { - wsfHeapInit(); - } - - if(freeLen < size) { - WSF_ASSERT(FALSE); - } - - freeStartAddr += size; - freeLen -= size; + freeStartAddr = sbrk(size); + heapUsed += size; } /*************************************************************************************************/ @@ -99,8 +71,9 @@ void WsfHeapAlloc(uint32_t size) /*************************************************************************************************/ void *WsfHeapGetFreeStartAddress(void) { - if(freeStartAddr == 0) { - wsfHeapInit(); + if(freeStartAddr == (caddr_t)-1) { + WSF_ASSERT(0); + return NULL; } return freeStartAddr; @@ -115,11 +88,9 @@ void *WsfHeapGetFreeStartAddress(void) /*************************************************************************************************/ uint32_t WsfHeapCountAvailable(void) { - if(freeStartAddr == 0) { - wsfHeapInit(); - } + struct mallinfo temp_mallinfo = mallinfo(); - return freeLen; + return temp_mallinfo.fordblks; } /*************************************************************************************************/ @@ -131,9 +102,5 @@ uint32_t WsfHeapCountAvailable(void) /*************************************************************************************************/ uint32_t WsfHeapCountUsed(void) { - if(freeStartAddr == 0) { - wsfHeapInit(); - } - - return (WSF_HEAP_SIZE - freeLen); + return heapUsed; }