Skip to content

Commit b79911c

Browse files
Update WHD wi-fi driver to use Mbed network stack memory manager (#502)
* Update WHD driver to use Mbed EMAC memory manager. Currently able to boot up the wi-fi module OK but cannot bring up the actual interface. * Fix a few more bugs * Working! * Reformat, fix EMAC test, fix build error * Build error * Convert another copy to realloc * Fix unittests build, fix MIMXRT build * Anotha one * Use force
1 parent 3e917d3 commit b79911c

File tree

53 files changed

+685
-762
lines changed

Some content is hidden

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

53 files changed

+685
-762
lines changed

cmsis/CMSIS_5/CMSIS/RTOS2/RTX/Source/rtx_mutex.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ const char *osMutexGetName (osMutexId_t mutex_id) {
520520
osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout) {
521521
osStatus_t status;
522522

523+
// a null mutex handle is always invalid
524+
if(mutex_id == 0) {
525+
return osErrorParameter;
526+
}
527+
523528
EvrRtxMutexAcquire(mutex_id, timeout);
524529
if (IsException() || IsIrqMasked()) {
525530
EvrRtxMutexError(mutex_id, (int32_t)osErrorISR);
@@ -534,6 +539,11 @@ osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout) {
534539
osStatus_t osMutexRelease (osMutexId_t mutex_id) {
535540
osStatus_t status;
536541

542+
// a null mutex handle is always invalid
543+
if(mutex_id == 0) {
544+
return osErrorParameter;
545+
}
546+
537547
EvrRtxMutexRelease(mutex_id);
538548
if (IsException() || IsIrqMasked()) {
539549
EvrRtxMutexError(mutex_id, (int32_t)osErrorISR);
@@ -561,6 +571,11 @@ osThreadId_t osMutexGetOwner (osMutexId_t mutex_id) {
561571
osStatus_t osMutexDelete (osMutexId_t mutex_id) {
562572
osStatus_t status;
563573

574+
// a null mutex handle is always invalid
575+
if(mutex_id == 0) {
576+
return osErrorParameter;
577+
}
578+
564579
EvrRtxMutexDelete(mutex_id);
565580
if (IsException() || IsIrqMasked()) {
566581
EvrRtxMutexError(mutex_id, (int32_t)osErrorISR);

cmsis/device/rtos/source/mbed_boot.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ void mbed_init(void)
8383
SCnSCB->ACTLR |= SCnSCB_ACTLR_DISDEFWBUF_Msk;
8484
#endif
8585
#endif
86+
87+
// If present, set the bits to enable memory / usage / bus faults.
88+
// Otherwise these will all get escalated to hard faults.
89+
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
90+
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk | SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk;
91+
#endif
92+
8693
mbed_mpu_manager_init();
8794
mbed_cpy_nvic();
8895
mbed_sdk_init();

connectivity/drivers/emac/TARGET_Freescale_EMAC/kinetis_emac.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,17 +395,10 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
395395
// If buffer is chained or not aligned then make a contiguous aligned copy of it
396396
if (memory_manager->get_next(buf) ||
397397
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
398-
emac_mem_buf_t *copy_buf;
399-
copy_buf = memory_manager->alloc_heap(memory_manager->get_total_len(buf), ENET_BUFF_ALIGNMENT);
400-
if (NULL == copy_buf) {
401-
memory_manager->free(buf);
402-
return false;
398+
buf = memory_manager->realloc_heap(buf, ENET_BUFF_ALIGNMENT);
399+
if(buf == nullptr) {
400+
return false;
403401
}
404-
405-
// Copy to new buffer and free original
406-
memory_manager->copy(copy_buf, buf);
407-
memory_manager->free(buf);
408-
buf = copy_buf;
409402
}
410403

411404
/* Check if a descriptor is available for the transfer (wait 10ms before dropping the buffer) */

connectivity/drivers/emac/TARGET_NXP_EMAC/TARGET_IMX/imx_emac.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,10 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
396396
// If buffer is chained or not aligned then make a contiguous aligned copy of it
397397
if (memory_manager->get_next(buf) ||
398398
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
399-
emac_mem_buf_t *copy_buf;
400-
copy_buf = memory_manager->alloc_heap(memory_manager->get_total_len(buf), ENET_BUFF_ALIGNMENT);
401-
if (NULL == copy_buf) {
402-
memory_manager->free(buf);
399+
buf = memory_manager->realloc_heap(buf, ENET_BUFF_ALIGNMENT);
400+
if (buf == nullptr) {
403401
return false;
404402
}
405-
406-
// Copy to new buffer and free original
407-
memory_manager->copy(copy_buf, buf);
408-
memory_manager->free(buf);
409-
buf = copy_buf;
410403
}
411404

412405
SCB_CleanDCache_by_Addr(static_cast<uint32_t *>(memory_manager->get_ptr(buf)), memory_manager->get_len(buf));

connectivity/drivers/emac/TARGET_NXP_EMAC/TARGET_LPCTarget/lpc17_emac.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -505,16 +505,10 @@ bool LPC17_EMAC::link_out(emac_mem_buf_t *p)
505505
if (notdmasafe) {
506506
/* Allocate a buffer in DMA memory.
507507
MEMORY MANAGER HEAP MUST BE IN DMA SAFE MEMORY. */
508-
np = memory_manager->alloc_heap(memory_manager->get_total_len(p), 0);
509-
if (np == NULL) {
510-
memory_manager->free(p);
508+
p = memory_manager->realloc_heap(p, 0);
509+
if (p == nullptr) {
511510
return false;
512511
}
513-
memory_manager->copy(np, p);
514-
/* use the new buffer for descriptor queueing. The original buffer will
515-
be de-allocated. */
516-
memory_manager->free(p);
517-
p = np;
518512
dn = 1;
519513
}
520514
#else

connectivity/drivers/emac/TARGET_NXP_EMAC/TARGET_MCU_LPC546XX/lpc546xx_emac.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -397,17 +397,11 @@ bool LPC546XX_EMAC::link_out(emac_mem_buf_t *buf)
397397
// If buffer is chained or not aligned then make a contiguous aligned copy of it
398398
if (memory_manager->get_next(buf) ||
399399
reinterpret_cast<uint32_t>(memory_manager->get_ptr(buf)) % ENET_BUFF_ALIGNMENT) {
400-
emac_mem_buf_t *copy_buf;
401-
copy_buf = memory_manager->alloc_heap(memory_manager->get_total_len(buf), ENET_BUFF_ALIGNMENT);
402-
if (NULL == copy_buf) {
403-
memory_manager->free(buf);
404-
return false;
405-
}
406400

407-
// Copy to new buffer and free original
408-
memory_manager->copy(copy_buf, buf);
409-
memory_manager->free(buf);
410-
buf = copy_buf;
401+
buf = memory_manager->realloc_heap(buf, ENET_BUFF_ALIGNMENT);
402+
if(buf == nullptr) {
403+
return false;
404+
}
411405
}
412406

413407
/* Check if a descriptor is available for the transfer. */

connectivity/drivers/emac/include/GenericEthDMA.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,15 @@ namespace mbed {
244244
// Step 2: Copy packet if needed
245245
if(needToCopy)
246246
{
247-
auto * newBuf = memory_manager->alloc_heap(memory_manager->get_total_len(buf), 0);
248-
if(newBuf == nullptr)
247+
buf = memory_manager->realloc_heap(buf, 0);
248+
if(buf == nullptr)
249249
{
250250
// No free memory, drop packet
251251
return CompositeEMAC::ErrCode::OUT_OF_MEMORY;
252252
}
253253

254-
// We should have gotten just one contiguous buffer
255-
MBED_ASSERT(memory_manager->get_next(newBuf) == nullptr);
256254
packetDescsUsed = 1;
257255
neededFreeDescs = packetDescsUsed + extraTxDescsToLeave;
258-
259-
// Copy data over
260-
memory_manager->copy_from_buf(static_cast<uint8_t *>(memory_manager->get_ptr(newBuf)), memory_manager->get_len(newBuf), buf);
261-
memory_manager->free(buf);
262-
buf = newBuf;
263256
}
264257

265258
tr_debug("Transmitting packet of length %lu in %zu buffers and %zu descs\n",

connectivity/drivers/wifi/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if("STM" IN_LIST MBED_TARGET_LABELS)
2626
add_subdirectory(TARGET_STM EXCLUDE_FROM_ALL)
2727
endif()
2828

29-
if("WHD" IN_LIST MBED_TARGET_LABELS)
29+
if("COMPONENT_WHD=1" IN_LIST MBED_TARGET_DEFINITIONS)
3030
create_mbed_wifi_target()
3131
add_subdirectory(COMPONENT_WHD EXCLUDE_FROM_ALL)
3232
endif()

connectivity/drivers/wifi/COMPONENT_WHD/mbed_lib.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "cy_psoc6_whd",
3+
"config": {
4+
"present": 1,
5+
"tx-buffer-header-space": {
6+
"help": "Header space in bytes that needs to be present in buffers passed from the Mbed EMAC to the WHD driver.",
7+
"value": 64
8+
}
9+
},
10+
}

0 commit comments

Comments
 (0)