fix(bt): Fix build error in hci transport on ESP32-S31

This commit is contained in:
Wang Mengyang
2026-04-13 16:50:58 +08:00
parent 78f83f60cb
commit b7b4b10584
5 changed files with 62 additions and 18 deletions
@@ -28,6 +28,9 @@
#include "esp_hci_internal.h"
#include "common/hci_driver_h4.h"
#include "common/hci_driver_util.h"
#if UC_BT_CTRL_BLE_IS_ENABLE
#include "ble_mbuf.h"
#endif
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
@@ -151,7 +154,9 @@ hci_h4_sm_w4_header(struct hci_h4_sm *h4sm, struct hci_h4_input_buffer *ib)
memcpy(h4sm->pkt->data, h4sm->hdr, h4sm->len);
break;
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
return -1;
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
case HCI_H4_SYNC:
conn_handle = btdm_get_le16(&h4sm->hdr[0]) & HCI_INTERNAL_CONN_MASK;
h4sm->exp_len = h4sm->hdr[2] + 3;
@@ -256,8 +261,8 @@ hci_h4_sm_w4_payload(struct hci_h4_sm *h4sm,
return -1;
}
}
break;
#endif // UC_BT_CTRL_BLE_IS_ENABLE
break;
default:
return -2;
}
@@ -361,32 +366,31 @@ hci_h4_sm_free_buf(struct hci_h4_sm *h4sm)
break;
#endif // (!CONFIG_BT_CONTROLLER_ENABLED)
case HCI_H4_ACL:
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
uint16_t conn_handle = btdm_get_le16(&h4sm->hdr[0]) & HCI_INTERNAL_CONN_MASK;
if (HCI_INTERNAL_CONN_IS_BLE(conn_handle)) {
#if UC_BT_CTRL_BLE_IS_ENABLE
if (h4sm->om) {
h4sm->frees->acl(h4sm->om);
h4sm->om = NULL;
}
#endif
} else {
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
if (h4sm->pkt) {
h4sm->frees->bredr_acl(h4sm->pkt);
h4sm->pkt = NULL;
}
}
#else
if (h4sm->om) {
h4sm->frees->acl(h4sm->om);
h4sm->om = NULL;
}
#endif
}
break;
#if UC_BT_CTRL_BLE_IS_ENABLE
case HCI_H4_ISO:
if (h4sm->buf) {
h4sm->frees->iso(h4sm->buf);
h4sm->buf = NULL;
}
break;
#endif // #if UC_BT_CTRL_BLE_IS_ENABLE
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
case HCI_H4_SYNC:
if (h4sm->pkt) {
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -8,6 +8,9 @@
#include "esp_hci_internal.h"
#include "common/hci_driver_mem.h"
#include "common/hci_driver_h4.h"
#if UC_BT_CTRL_BLE_IS_ENABLE
#include "ble_mbuf.h"
#endif
hci_driver_packet_t *
hci_driver_mem_cmd_alloc(void)
@@ -23,6 +26,7 @@ hci_driver_mem_evt_alloc(int discardable)
return NULL;
}
#if UC_BT_CTRL_BLE_IS_ENABLE
struct ble_mbuf *
hci_driver_mem_acl_alloc(void)
{
@@ -53,6 +57,8 @@ hci_driver_mem_iso_len_alloc(uint32_t len)
return ble_msys_get_pkthdr(len, ESP_HCI_INTERNAL_ACL_MBUF_LEADINGSPCAE);
}
#endif // #if UC_BT_CTRL_BLE_IS_ENABLE
void
hci_driver_mem_cmd_free(void * ptr)
{
@@ -67,7 +73,7 @@ hci_driver_mem_evt_free(void *ptr)
btdm_hci_trans_buf_free(pkt);
}
#if UC_BTDM_CTRL_BR_EDR_IS_ENABLE
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
hci_driver_packet_t *
hci_driver_mem_bredr_acl_alloc(uint16_t handle)
{
@@ -95,27 +101,31 @@ hci_driver_mem_sync_free(void *ptr)
bredr_hci_trans_sync_tx_done(pkt);
bredr_hci_trans_sync_free(pkt);
}
#endif // UC_BTDM_CTRL_BR_EDR_IS_ENABLE
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
const struct hci_h4_allocators s_hci_driver_mem_alloc = {
.cmd = hci_driver_mem_cmd_alloc,
.evt = hci_driver_mem_evt_alloc,
#if UC_BT_CTRL_BLE_IS_ENABLE
.acl = hci_driver_mem_acl_alloc,
.iso = hci_driver_mem_iso_alloc,
#if UC_BTDM_CTRL_BR_EDR_IS_ENABLE
#endif // #if UC_BT_CTRL_BLE_IS_ENABLE
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
.sync = hci_driver_mem_sync_alloc,
.bredr_acl = hci_driver_mem_bredr_acl_alloc,
#endif // UC_BTDM_CTRL_BR_EDR_IS_ENABLE
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
};
const struct hci_h4_frees s_hci_driver_mem_free = {
.cmd = hci_driver_mem_cmd_free,
.evt = hci_driver_mem_evt_free,
#if UC_BT_CTRL_BLE_IS_ENABLE
.acl = ble_mbuf_free_chain,
.iso = hci_driver_mem_iso_free,
.le_evt = r_ble_hci_trans_buf_free,
#if UC_BTDM_CTRL_BR_EDR_IS_ENABLE
#endif // UC_BT_CTRL_BLE_IS_ENABLE
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
.sync = hci_driver_mem_sync_free,
.bredr_acl = hci_driver_mem_bredr_acl_free,
#endif // UC_BTDM_CTRL_BR_EDR_IS_ENABLE
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
};
@@ -8,13 +8,17 @@
#include "esp_log.h"
#include "esp_hci_driver.h"
#include "esp_hci_internal.h"
#include "btdm_mempool.h"
#include "common/hci_driver_util.h"
#if UC_BT_CTRL_BLE_IS_ENABLE
#include "ble_mbuf.h"
#endif
#define TAG "HCI_UTIL"
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
#define HCI_DRIVER_UTIL_BREDR_HCI_EVT_TX_POOL_NUM 4
#define HCI_DRIVER_UTIL_BREDR_TX_POOL_NUM \
(CONFIG_BT_CTRL_BR_EDR_ACLU_RX_BUF_NB_EFF + CONFIG_BT_CTRL_BR_EDR_SYNC_RX_BUF_NB_EFF + HCI_DRIVER_UTIL_BREDR_HCI_EVT_TX_POOL_NUM)
(UC_BR_EDR_ACLU_RX_BUF_NB + UC_BR_EDR_SYNC_RX_BUF_NB + HCI_DRIVER_UTIL_BREDR_HCI_EVT_TX_POOL_NUM)
#else
#define HCI_DRIVER_UTIL_BREDR_TX_POOL_NUM 0
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
@@ -170,8 +174,9 @@ hci_driver_util_tx_list_dequeue(uint32_t max_tx_len, void **tx_data, bool *last_
uint32_t data_len;
hci_driver_util_tx_entry_t *tx_entry;
hci_driver_packet_t *pkt = NULL;
#if UC_BT_CTRL_BLE_IS_ENABLE
struct ble_mbuf *om = NULL;
uint16_t out_off;
#endif
/* Check if there is any remaining data that hasn't been sent completely. If it has been completed,
* free the corresponding memory. Therefore, the HCI TX entry needs to be sent one by one; multiple
* entries cannot be sent together.
@@ -184,8 +189,10 @@ hci_driver_util_tx_list_dequeue(uint32_t max_tx_len, void **tx_data, bool *last_
if (tx_entry->data_type == HCI_DRIVER_TYPE_ACL) {
if (s_hci_driver_util_env.cur_tx_off >= data_len) {
if (tx_entry->data_source == HCI_DRIVER_LE_ACL) {
#if UC_BT_CTRL_BLE_IS_ENABLE
om = (struct ble_mbuf *)tx_entry->data;
ble_mbuf_free_chain(om);
#endif // #if UC_BT_CTRL_BLE_IS_ENABLE
}
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
else {
@@ -194,10 +201,13 @@ hci_driver_util_tx_list_dequeue(uint32_t max_tx_len, void **tx_data, bool *last_
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
} else {
if (tx_entry->data_source == HCI_DRIVER_LE_ACL) {
#if UC_BT_CTRL_BLE_IS_ENABLE
uint16_t out_off;
om = (struct ble_mbuf *)tx_entry->data;
om = ble_mbuf_off(om, s_hci_driver_util_env.cur_tx_off, &out_off);
tx_len = min(max_tx_len, om->om_len - out_off);
*tx_data = (void *)&om->om_data[out_off];
#endif // #if UC_BT_CTRL_BLE_IS_ENABLE
} else {
tx_len = min(max_tx_len, data_len - s_hci_driver_util_env.cur_tx_off);
*tx_data = &pkt->data[s_hci_driver_util_env.cur_tx_off];
@@ -206,7 +216,9 @@ hci_driver_util_tx_list_dequeue(uint32_t max_tx_len, void **tx_data, bool *last_
} else if (tx_entry->data_type == HCI_DRIVER_TYPE_EVT) {
if (s_hci_driver_util_env.cur_tx_off >= data_len) {
if (tx_entry->data_source == HCI_DRIVER_LE_EVT) {
#if UC_BT_CTRL_BLE_IS_ENABLE
r_ble_hci_trans_buf_free(tx_entry->data);
#endif // #if UC_BT_CTRL_BLE_IS_ENABLE
}
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
else if (tx_entry->data_source == HCI_DRIVER_BREDR_EVT) {
@@ -307,7 +319,9 @@ hci_driver_util_deinit(void)
next_entry = STAILQ_NEXT(tx_entry, next);
if (tx_entry->data_type == HCI_DRIVER_TYPE_EVT) {
if (tx_entry->data_source == HCI_DRIVER_LE_EVT) {
#if UC_BT_CTRL_BLE_IS_ENABLE
r_ble_hci_trans_buf_free(tx_entry->data);
#endif // #if UC_BT_CTRL_BLE_IS_ENABLE
}
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
else if (tx_entry->data_source == HCI_DRIVER_BREDR_EVT) {
@@ -320,7 +334,9 @@ hci_driver_util_deinit(void)
}
} else if (tx_entry->data_type == HCI_DRIVER_TYPE_ACL) {
if (tx_entry->data_source == HCI_DRIVER_LE_ACL) {
#if UC_BT_CTRL_BLE_IS_ENABLE
ble_mbuf_free_chain((struct ble_mbuf *)tx_entry->data);
#endif // #if UC_BT_CTRL_BLE_IS_ENABLE
}
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
else {
@@ -147,7 +147,9 @@ hci_driver_uart_rx_task(void *p)
ret = hci_h4_sm_rx(s_hci_driver_uart_env.h4_sm, data, read_len);
if (ret < 0) {
ESP_LOGE(TAG, "parse rx data error! sm_state:%d\n", s_hci_driver_uart_env.h4_sm->state);
#if UC_BT_CTRL_BLE_IS_ENABLE
r_ble_ll_hci_ev_hw_err(ESP_HCI_SYNC_LOSS_ERR);
#endif // #if UC_BT_CTRL_BLE_IS_ENABLE
}
}
}
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -37,17 +37,23 @@
typedef hci_driver_packet_t *(hci_h4_alloc_cmd)(void);
typedef void *(hci_h4_alloc_evt)(int);
#if CONFIG_BT_CTRL_BLE_ENABLE
typedef struct ble_mbuf *(hci_h4_alloc_acl)(void);
typedef void *(hci_h4_alloc_iso)(uint32_t);
#endif // #if CONFIG_BT_CTRL_BLE_ENABLE
#if CONFIG_BT_CTRL_BREDR_ENABLE
typedef hci_driver_packet_t *(hci_h4_alloc_sync)(uint16_t);
typedef hci_driver_packet_t *(hci_h4_alloc_bredr_acl)(uint16_t);
#endif // #if CONFIG_BT_CTRL_BREDR_ENABLE
struct hci_h4_allocators {
hci_h4_alloc_cmd *cmd;
#if CONFIG_BT_CTRL_BLE_ENABLE
hci_h4_alloc_acl *acl;
#endif // #if CONFIG_BT_CTRL_BLE_ENABLE
hci_h4_alloc_evt *evt;
#if CONFIG_BT_CTRL_BLE_ENABLE
hci_h4_alloc_iso *iso;
#endif // #if CONFIG_BT_CTRL_BLE_ENABLE
#if CONFIG_BT_CTRL_BREDR_ENABLE
hci_h4_alloc_sync *sync;
hci_h4_alloc_bredr_acl *bredr_acl;
@@ -59,19 +65,25 @@ extern const struct hci_h4_allocators hci_h4_allocs_from_hs;
typedef void (hci_h4_free_cmd)(void * ptr);
typedef void (hci_h4_free_evt)(void * ptr);
#if CONFIG_BT_CTRL_BLE_ENABLE
typedef int (hci_h4_free_acl)(struct ble_mbuf *om);
typedef void (hci_h4_free_iso)(void *ptr);
typedef void (hci_h4_free_le_evt)(uint8_t *buf);
#endif // #if CONFIG_BT_CTRL_BLE_ENABLE
#if CONFIG_BT_CTRL_BREDR_ENABLE
typedef void (hci_h4_free_sync)(void *ptr);
typedef void (hci_h4_free_bredr_acl)(void *ptr);
#endif // CONFIG_BT_CTRL_BREDR_ENABLE
struct hci_h4_frees {
hci_h4_free_cmd *cmd;
#if CONFIG_BT_CTRL_BLE_ENABLE
hci_h4_free_acl *acl;
#endif // CONFIG_BT_CTRL_BLE_ENABLE
hci_h4_free_evt *evt;
#if CONFIG_BT_CTRL_BLE_ENABLE
hci_h4_free_iso *iso;
hci_h4_free_le_evt *le_evt;
#endif // CONFIG_BT_CTRL_BLE_ENABLE
#if CONFIG_BT_CTRL_BREDR_ENABLE
hci_h4_free_sync *sync;
hci_h4_free_bredr_acl *bredr_acl;