Skip to content

Commit be12504

Browse files
kevin-gillespiecrsz20
authored andcommitted
feat(CMSIS): Adding mallinfo function and reworking Cordio memory management. (#1179)
Co-authored-by: crsz20 <[email protected]> Co-authored-by: crsz20 <[email protected]>
1 parent a8c9a8c commit be12504

File tree

94 files changed

+6621
-8474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+6621
-8474
lines changed

.github/workflows/clang-format-run-pr.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ on:
2525
issue_comment:
2626
types: [created]
2727

28+
permissions:
29+
actions: write
30+
2831
env:
2932
CLANG_VERSION: 14
3033

Examples/MAX32655/Bluetooth/BLE4_ctr/main.c

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ static void mainLoadConfiguration(void)
9595
/*************************************************************************************************/
9696
static void mainWsfInit(void)
9797
{
98+
uint32_t llmemUsed, memUsed;
99+
100+
mainLoadConfiguration();
101+
98102
/* +12 for message headroom, +4 for header. */
99103
const uint16_t aclBufSize = 12 + mainLlRtCfg.maxAclLen + 4 + BB_DATA_PDU_TAILROOM;
100104

@@ -105,24 +109,61 @@ static void mainWsfInit(void)
105109

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

112+
/* Calculate how much memory we will need for the LL initialization */
113+
WsfCsEnter();
114+
115+
LlInitRtCfg_t llCfg = {
116+
.pBbRtCfg = &mainBbRtCfg,
117+
.wlSizeCfg = 4,
118+
.rlSizeCfg = 4,
119+
.plSizeCfg = 4,
120+
.pLlRtCfg = &mainLlRtCfg,
121+
/* Not significant yet, only being used for memory size requirement calculation. */
122+
.pFreeMem = WsfHeapGetFreeStartAddress(),
123+
/* Not significant yet, only being used for memory size requirement calculation. */
124+
.freeMemAvail = WsfHeapCountAvailable()
125+
};
126+
127+
llmemUsed = LlInitSetRtCfg(&llCfg);
128+
129+
WsfCsExit();
130+
108131
/* Initial buffer configuration. */
109-
uint16_t memUsed;
110132
WsfCsEnter();
111-
memUsed = WsfBufInit(numPools, poolDesc);
133+
memUsed = WsfBufCalcSize(numPools, poolDesc);
112134
WsfHeapAlloc(memUsed);
135+
WsfBufInit(numPools, poolDesc);
113136
WsfCsExit();
114137

115138
WsfOsInit();
116139
WsfTimerInit();
140+
117141
#if (WSF_TRACE_ENABLED == TRUE)
118142
WsfCsEnter();
119-
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
120-
WsfHeapAlloc(memUsed);
143+
WsfHeapAlloc(PLATFORM_UART_TERMINAL_BUFFER_SIZE);
144+
WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
121145
WsfCsExit();
122146

123147
WsfTraceRegisterHandler(WsfBufIoWrite);
124148
WsfTraceEnable(TRUE);
125149
#endif
150+
151+
/* Complete the LL initialization */
152+
WsfCsEnter();
153+
154+
/* Allocate the memory */
155+
WsfHeapAlloc(llmemUsed);
156+
157+
/* Set the free memory pointers */
158+
llCfg.pFreeMem = WsfHeapGetFreeStartAddress();
159+
llCfg.freeMemAvail = WsfHeapCountAvailable();
160+
161+
/* Run the initialization with properly set the free memory pointers */
162+
if (llmemUsed != LlInitControllerInit(&llCfg)) {
163+
WSF_ASSERT(0);
164+
}
165+
166+
WsfCsExit();
126167
}
127168

128169
/*************************************************************************************************/
@@ -164,31 +205,8 @@ static bool mainCheckServiceTokens(void)
164205
/*************************************************************************************************/
165206
int main(void)
166207
{
167-
uint32_t memUsed;
168-
169-
mainLoadConfiguration();
170208
mainWsfInit();
171209

172-
#if (WSF_TRACE_ENABLED == TRUE)
173-
WsfCsEnter();
174-
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
175-
WsfHeapAlloc(memUsed);
176-
WsfCsExit();
177-
#endif
178-
179-
WsfCsEnter();
180-
LlInitRtCfg_t llCfg = { .pBbRtCfg = &mainBbRtCfg,
181-
.wlSizeCfg = 4,
182-
.rlSizeCfg = 4,
183-
.plSizeCfg = 4,
184-
.pLlRtCfg = &mainLlRtCfg,
185-
.pFreeMem = WsfHeapGetFreeStartAddress(),
186-
.freeMemAvail = WsfHeapCountAvailable() };
187-
188-
memUsed = LlInitControllerInit(&llCfg);
189-
WsfHeapAlloc(memUsed);
190-
WsfCsExit();
191-
192210
bdAddr_t bdAddr;
193211
PalCfgLoadData(PAL_CFG_ID_BD_ADDR, bdAddr, sizeof(bdAddr_t));
194212
/* Coverity[uninit_use_in_call] */

Examples/MAX32655/Bluetooth/BLE5_ctr/main.c

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ static void mainLoadConfiguration(void)
111111
/*************************************************************************************************/
112112
static void mainWsfInit(void)
113113
{
114+
uint32_t llmemUsed, memUsed;
115+
116+
mainLoadConfiguration();
117+
114118
/* +12 for message headroom, + 2 event header, +255 maximum parameter length. */
115119
const uint16_t maxRptBufSize = 12 + 2 + 255;
116120

@@ -137,24 +141,61 @@ static void mainWsfInit(void)
137141

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

144+
/* Calculate how much memory we will need for the LL initialization */
145+
WsfCsEnter();
146+
147+
LlInitRtCfg_t llCfg = {
148+
.pBbRtCfg = &mainBbRtCfg,
149+
.wlSizeCfg = 4,
150+
.rlSizeCfg = 4,
151+
.plSizeCfg = 4,
152+
.pLlRtCfg = &mainLlRtCfg,
153+
/* Not significant yet, only being used for memory size requirement calculation. */
154+
.pFreeMem = WsfHeapGetFreeStartAddress(),
155+
/* Not significant yet, only being used for memory size requirement calculation. */
156+
.freeMemAvail = WsfHeapCountAvailable()
157+
};
158+
159+
llmemUsed = LlInitSetRtCfg(&llCfg);
160+
161+
WsfCsExit();
162+
140163
/* Initial buffer configuration. */
141-
uint16_t memUsed;
142164
WsfCsEnter();
143-
memUsed = WsfBufInit(numPools, poolDesc);
165+
memUsed = WsfBufCalcSize(numPools, poolDesc);
144166
WsfHeapAlloc(memUsed);
167+
WsfBufInit(numPools, poolDesc);
145168
WsfCsExit();
146169

147170
WsfOsInit();
148171
WsfTimerInit();
172+
149173
#if (WSF_TRACE_ENABLED == TRUE)
150174
WsfCsEnter();
151-
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
152-
WsfHeapAlloc(memUsed);
175+
WsfHeapAlloc(PLATFORM_UART_TERMINAL_BUFFER_SIZE);
176+
WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
153177
WsfCsExit();
154178

155179
WsfTraceRegisterHandler(WsfBufIoWrite);
156180
WsfTraceEnable(TRUE);
157181
#endif
182+
183+
/* Complete the LL initialization */
184+
WsfCsEnter();
185+
186+
/* Allocate the memory */
187+
WsfHeapAlloc(llmemUsed);
188+
189+
/* Set the free memory pointers */
190+
llCfg.pFreeMem = WsfHeapGetFreeStartAddress();
191+
llCfg.freeMemAvail = WsfHeapCountAvailable();
192+
193+
/* Run the initialization with properly set the free memory pointers */
194+
if (llmemUsed != LlInitControllerInit(&llCfg)) {
195+
WSF_ASSERT(0);
196+
}
197+
198+
WsfCsExit();
158199
}
159200

160201
/*************************************************************************************************/
@@ -249,31 +290,8 @@ void setInterruptPriority(void)
249290
/*************************************************************************************************/
250291
int main(void)
251292
{
252-
uint32_t memUsed;
253-
254-
mainLoadConfiguration();
255293
mainWsfInit();
256294

257-
#if (WSF_TRACE_ENABLED == TRUE)
258-
WsfCsEnter();
259-
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
260-
WsfHeapAlloc(memUsed);
261-
WsfCsExit();
262-
#endif
263-
264-
WsfCsEnter();
265-
LlInitRtCfg_t llCfg = { .pBbRtCfg = &mainBbRtCfg,
266-
.wlSizeCfg = 4,
267-
.rlSizeCfg = 4,
268-
.plSizeCfg = 4,
269-
.pLlRtCfg = &mainLlRtCfg,
270-
.pFreeMem = WsfHeapGetFreeStartAddress(),
271-
.freeMemAvail = WsfHeapCountAvailable() };
272-
273-
memUsed = LlInitControllerInit(&llCfg);
274-
WsfHeapAlloc(memUsed);
275-
WsfCsExit();
276-
277295
bdAddr_t bdAddr;
278296
PalCfgLoadData(PAL_CFG_ID_BD_ADDR, bdAddr, sizeof(bdAddr_t));
279297
/* Coverity[uninit_use_in_call] */

Examples/MAX32655/Bluetooth/BLE_FreeRTOS/stack_dats.c

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ static void mainWsfInit(void)
174174
const uint8_t numPools = sizeof(mainPoolDesc) / sizeof(mainPoolDesc[0]);
175175

176176
uint16_t memUsed;
177+
/* Initial buffer configuration. */
177178
WsfCsEnter();
178-
memUsed = WsfBufInit(numPools, mainPoolDesc);
179+
memUsed = WsfBufCalcSize(numPools, mainPoolDesc);
179180
WsfHeapAlloc(memUsed);
181+
WsfBufInit(numPools, mainPoolDesc);
180182
WsfCsExit();
181183

182184
WsfOsInit();
@@ -327,27 +329,52 @@ void bleStartup(void)
327329
mainLlRtCfg.defTxPwrLvl = DEFAULT_TX_POWER;
328330
#endif
329331

330-
uint32_t memUsed;
331332
WsfCsEnter();
332-
memUsed = WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
333-
WsfHeapAlloc(memUsed);
333+
WsfHeapAlloc(PLATFORM_UART_TERMINAL_BUFFER_SIZE);
334+
WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE);
334335
WsfCsExit();
335336

336337
mainWsfInit();
337338
AppTerminalInit();
338339

339340
#if defined(HCI_TR_EXACTLE) && (HCI_TR_EXACTLE == 1)
341+
uint32_t llmemUsed;
342+
343+
/* Calculate how much memory we will need for the LL initialization */
340344
WsfCsEnter();
341-
LlInitRtCfg_t llCfg = { .pBbRtCfg = &mainBbRtCfg,
342-
.wlSizeCfg = 4,
343-
.rlSizeCfg = 4,
344-
.plSizeCfg = 4,
345-
.pLlRtCfg = &mainLlRtCfg,
346-
.pFreeMem = WsfHeapGetFreeStartAddress(),
347-
.freeMemAvail = WsfHeapCountAvailable() };
348-
349-
memUsed = LlInit(&llCfg);
350-
WsfHeapAlloc(memUsed);
345+
346+
WsfTraceEnable(FALSE);
347+
348+
LlInitRtCfg_t llCfg = {
349+
.pBbRtCfg = &mainBbRtCfg,
350+
.wlSizeCfg = 4,
351+
.rlSizeCfg = 4,
352+
.plSizeCfg = 4,
353+
.pLlRtCfg = &mainLlRtCfg,
354+
/* Not significant yet, only being used for memory size requirement calculation. */
355+
.pFreeMem = WsfHeapGetFreeStartAddress(),
356+
/* Not significant yet, only being used for memory size requirement calculation. */
357+
.freeMemAvail = WsfHeapCountAvailable()
358+
};
359+
360+
llmemUsed = LlInitSetRtCfg(&llCfg);
361+
362+
/* Allocate the memory */
363+
WsfHeapAlloc(llmemUsed);
364+
365+
/* Set the free memory pointers */
366+
llCfg.pFreeMem = WsfHeapGetFreeStartAddress();
367+
llCfg.freeMemAvail = WsfHeapCountAvailable();
368+
369+
#if (WSF_TOKEN_ENABLED == TRUE) || (WSF_TRACE_ENABLED == TRUE)
370+
WsfTraceEnable(TRUE);
371+
#endif
372+
373+
/* Run the initialization with properly set the free memory pointers */
374+
if (llmemUsed != LlInitControllerInit(&llCfg)) {
375+
WSF_ASSERT(0);
376+
}
377+
351378
WsfCsExit();
352379

353380
bdAddr_t bdAddr;

0 commit comments

Comments
 (0)