Skip to content

Commit 6e38464

Browse files
author
Zhou Xiao
committed
fix(ble): nimble host & hci log write race condition workaround
1 parent 4946a1f commit 6e38464

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

components/bt/common/ble_log/ble_log_spi_out.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,6 @@ static bool spi_out_get_task_mapping(task_map_t *map, size_t num,
707707
}
708708
}
709709
portEXIT_CRITICAL_SAFE(&spinlock);
710-
711-
if (!ret) {
712-
// Shall not be here in normal case
713-
const char *task_name = pcTaskGetName(NULL);
714-
esp_rom_printf("@EW: Failed to assign slot in task map for task %s\n", task_name);
715-
}
716710
return ret;
717711
}
718712

@@ -1388,9 +1382,14 @@ int ble_log_spi_out_host_write(uint8_t source, const char *prefix, const char *f
13881382

13891383
spi_out_log_cb_t *log_cb;
13901384
uint8_t *str_buf;
1385+
bool fallback = false;
13911386
if (!spi_out_get_task_mapping(LOG_MODULE_TASK_MAP(host),
13921387
LOG_MODULE_CB_CNT(host), &log_cb, &str_buf)) {
1393-
return -1;
1388+
// NimBLE workaround
1389+
fallback = true;
1390+
xSemaphoreTake(LOG_MODULE_MUTEX(ul), portMAX_DELAY);
1391+
log_cb = LOG_MODULE_CB(ul, 0);
1392+
str_buf = LOG_MODULE_STR_BUF(ul, 0);
13941393
}
13951394

13961395
// Copy prefix to string buffer
@@ -1411,6 +1410,10 @@ int ble_log_spi_out_host_write(uint8_t source, const char *prefix, const char *f
14111410

14121411
// Write log control block buffer
14131412
spi_out_write_hex(log_cb, source, str_buf, (uint16_t)total_len, true);
1413+
1414+
if (fallback) {
1415+
xSemaphoreGive(LOG_MODULE_MUTEX(ul));
1416+
}
14141417
return 0;
14151418
}
14161419
#endif // SPI_OUT_HOST_ENABLED
@@ -1429,11 +1432,18 @@ int ble_log_spi_out_hci_write(uint8_t source, const uint8_t *addr, uint16_t len)
14291432
}
14301433
if (source == BLE_LOG_SPI_OUT_SOURCE_HCI_DOWNSTREAM) {
14311434
spi_out_log_cb_t *log_cb;
1435+
bool fallback = false;
14321436
if (!spi_out_get_task_mapping(LOG_MODULE_TASK_MAP(hci),
14331437
LOG_MODULE_CB_CNT(hci), &log_cb, NULL)) {
1434-
return -1;
1438+
// NimBLE workaround
1439+
fallback = true;
1440+
xSemaphoreTake(LOG_MODULE_MUTEX(ul), portMAX_DELAY);
1441+
log_cb = LOG_MODULE_CB(ul, 0);
14351442
}
14361443
spi_out_write_hex(log_cb, source, addr, len, true);
1444+
if (fallback) {
1445+
xSemaphoreGive(LOG_MODULE_MUTEX(ul));
1446+
}
14371447
}
14381448
return 0;
14391449
}

0 commit comments

Comments
 (0)