change(bt/controller): Adapt BR/EDR controller to new architecture

This commit is contained in:
liqigan
2026-08-13 11:07:07 +08:00
committed by ShenWeilong
parent c48a8567a1
commit e8d3044728
11 changed files with 272 additions and 46 deletions
@@ -109,6 +109,7 @@ extern int bredr_controller_init(void *cfg);
extern void bredr_controller_deinit(void);
extern int bredr_controller_enable(void);
extern void bredr_controller_disable(void);
extern void r_bredr_controller_reset(void);
extern int bredr_controller_env_init(void *cfg);
extern void bredr_controller_env_deinit(void);
extern void bredr_register_setup_callback(bredr_ctrl_callback_t cbk);
@@ -824,7 +825,7 @@ static bool bredr_check_tx_pwr(const char *name, int8_t value, int8_t min_power,
* The menuconfig limits only describe the maximum possible range, but the achievable range can be narrower depending on the chip.
* Returns ESP_ERR_INVALID_ARG if any configured value is out of range so that controller init can be aborted.
*/
static esp_err_t bredr_validate_tx_pwr_cfg(const esp_bredr_controller_config_t *bredr_cfg)
static esp_err_t bredr_validate_tx_pwr_cfg(const esp_bt_ctrl_bredr_config_t *bredr_cfg)
{
int8_t min_power = 0;
int8_t max_power = 0;
@@ -906,6 +907,13 @@ void bredr_stack_disable(void)
}
int bredr_stack_reset(void)
{
r_bredr_controller_reset();
return 0;
}
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
esp_err_t sleep_modem_bredr_mac_modem_state_init(void)
{
@@ -77,27 +77,27 @@ hci_driver_mem_evt_free(void *ptr)
hci_driver_packet_t *
hci_driver_mem_bredr_acl_alloc(uint16_t handle)
{
return btdm_hci_trans_buf_alloc(HCI_H4_ACL, handle);
return bredr_hci_trans_acl_rx_buf_alloc(handle);
}
void
hci_driver_mem_bredr_acl_free(void *ptr)
{
hci_driver_packet_t *pkt = (hci_driver_packet_t *) ptr;
bredr_hci_trans_acl_free(pkt);
bredr_hci_trans_acl_tx_free(pkt);
}
hci_driver_packet_t *
hci_driver_mem_sync_alloc(uint16_t handle)
{
return btdm_hci_trans_buf_alloc(HCI_H4_SYNC, handle);
return bredr_hci_trans_sync_rx_buf_alloc(handle);
}
void
hci_driver_mem_sync_free(void *ptr)
{
hci_driver_packet_t *pkt = (hci_driver_packet_t *) ptr;
bredr_hci_trans_sync_free(pkt);
bredr_hci_trans_sync_tx_free(pkt);
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
@@ -196,7 +196,7 @@ hci_driver_util_tx_list_dequeue(uint32_t max_tx_len, void **tx_data, bool *last_
}
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
else {
bredr_hci_trans_acl_free(pkt);
bredr_hci_trans_acl_tx_free(pkt);
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
} else {
@@ -222,7 +222,7 @@ hci_driver_util_tx_list_dequeue(uint32_t max_tx_len, void **tx_data, bool *last_
}
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
else if (tx_entry->data_source == HCI_DRIVER_BREDR_EVT) {
bredr_hci_trans_evt_free(pkt);
bredr_hci_trans_evt_tx_free(pkt);
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
else {
@@ -247,7 +247,7 @@ hci_driver_util_tx_list_dequeue(uint32_t max_tx_len, void **tx_data, bool *last_
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
else if (tx_entry->data_type == HCI_DRIVER_TYPE_SYNC) {
if (s_hci_driver_util_env.cur_tx_off >= data_len) {
bredr_hci_trans_sync_free(pkt);
bredr_hci_trans_sync_tx_free(pkt);
} 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];
@@ -326,7 +326,7 @@ hci_driver_util_deinit(void)
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
else if (tx_entry->data_source == HCI_DRIVER_BREDR_EVT) {
bredr_hci_trans_evt_tx_done((hci_driver_packet_t *)tx_entry->data);
bredr_hci_trans_evt_free((hci_driver_packet_t *)tx_entry->data);
bredr_hci_trans_evt_tx_free((hci_driver_packet_t *)tx_entry->data);
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
else {
@@ -341,7 +341,7 @@ hci_driver_util_deinit(void)
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
else {
bredr_hci_trans_acl_tx_done((hci_driver_packet_t *)tx_entry->data);
bredr_hci_trans_acl_free((hci_driver_packet_t *)tx_entry->data);
bredr_hci_trans_acl_tx_free((hci_driver_packet_t *)tx_entry->data);
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
} else if (tx_entry->data_type == HCI_DRIVER_TYPE_ISO) {
@@ -351,7 +351,7 @@ hci_driver_util_deinit(void)
else {
// SCO data
bredr_hci_trans_sync_tx_done((hci_driver_packet_t *)tx_entry->pkt);
bredr_hci_trans_sync_free((hci_driver_packet_t *)tx_entry->pkt);
bredr_hci_trans_sync_tx_free((hci_driver_packet_t *)tx_entry->pkt);
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
@@ -108,7 +108,7 @@ hci_driver_vhci_controller_tx(hci_driver_data_type_t data_type, uint8_t *data, u
*buf = old_value;
if (rc >= 0) {
bredr_hci_trans_acl_tx_done(pkt);
bredr_hci_trans_acl_free(pkt);
bredr_hci_trans_acl_tx_free(pkt);
}
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
@@ -134,7 +134,7 @@ hci_driver_vhci_controller_tx(hci_driver_data_type_t data_type, uint8_t *data, u
*buf = old_value;
if (rc >= 0) {
bredr_hci_trans_evt_tx_done((hci_driver_packet_t *)data);
bredr_hci_trans_evt_free((hci_driver_packet_t *)data);
bredr_hci_trans_evt_tx_free((hci_driver_packet_t *)data);
}
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
@@ -164,7 +164,7 @@ hci_driver_vhci_controller_tx(hci_driver_data_type_t data_type, uint8_t *data, u
*buf = old_value;
if (rc >= 0) {
bredr_hci_trans_sync_tx_done(pkt);
bredr_hci_trans_sync_free(pkt);
bredr_hci_trans_sync_tx_free(pkt);
}
}
#endif // UC_BT_CTRL_BR_EDR_IS_ENABLE
@@ -210,7 +210,7 @@ hci_driver_vhci_host_tx(hci_driver_data_type_t data_type, uint8_t *data, uint32_
#endif // UC_BT_CTRL_BLE_IS_ENABLE
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
if (is_bredr) {
pkt = btdm_hci_trans_buf_alloc(data_type, conn_handle);
pkt = bredr_hci_trans_acl_rx_buf_alloc(conn_handle);
assert(pkt);
memcpy(pkt->data, &data[1], pkt_len);
data = (uint8_t *)pkt;
@@ -222,7 +222,7 @@ hci_driver_vhci_host_tx(hci_driver_data_type_t data_type, uint8_t *data, uint32_
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
case HCI_DRIVER_TYPE_SYNC:
conn_handle = btdm_get_le16(&data[1]) & HCI_INTERNAL_CONN_MASK;
pkt = btdm_hci_trans_buf_alloc(data_type, conn_handle);
pkt = bredr_hci_trans_sync_rx_buf_alloc(conn_handle);
assert(pkt);
memcpy(pkt->data, &data[1], pkt_len);
data = (uint8_t *)pkt;
@@ -167,10 +167,12 @@ void bredr_hci_trans_register_tx(btdm_hci_trans_tx_func_t *acl_tx_func,
void bredr_hci_trans_acl_tx_done(hci_driver_packet_t *pkt);
void bredr_hci_trans_sync_tx_done(hci_driver_packet_t *pkt);
void bredr_hci_trans_evt_tx_done(hci_driver_packet_t *pkt);
int bredr_hci_trans_acl_free(hci_driver_packet_t *pkt);
int bredr_hci_trans_sync_free(hci_driver_packet_t *pkt);
int bredr_hci_trans_evt_free(hci_driver_packet_t *pkt);
int bredr_hci_trans_acl_tx_free(hci_driver_packet_t *pkt);
int bredr_hci_trans_sync_tx_free(hci_driver_packet_t *pkt);
int bredr_hci_trans_evt_tx_free(hci_driver_packet_t *pkt);
hci_driver_packet_t *bredr_hci_trans_acl_rx_buf_alloc(uint16_t conn_handle);
hci_driver_packet_t *bredr_hci_trans_sync_rx_buf_alloc(uint16_t conn_handle);
#ifdef __cplusplus
}
#endif
@@ -1,14 +1,14 @@
/*
* SPDX-FileCopyrightText 2026 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_hci_internal.h"
#include "esp_hci_internal.h"
#if UC_BT_CTRL_BLE_IS_ENABLE
#include "ble_priv.h"
#endif /* UC_BT_CTRL_BLE_IS_ENABLE */
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
#include "bredr_priv.h"
#endif /* #if UC_BT_CTRL_BR_EDR_IS_ENABLE */
@@ -286,12 +286,13 @@ extern int flushableAclData_hci_writeAutoFlushTmo(const uint8_t *cmdbuf, uint8_t
/* Informational (OGF 0x04) - btdm_hci_external / ble */
extern int r_btdm_hci_rd_local_version_info_handler(const uint8_t *cmdbuf, uint8_t len,
uint8_t *rspbuf, uint8_t *rsplen);
extern int r_btdm_hci_rd_local_supported_cmds_handler(const uint8_t *cmdbuf, uint8_t len,
uint8_t *rspbuf, uint8_t *rsplen);
extern int r_btdm_hci_rd_local_supported_cmds_handler(const uint8_t *cmdbuf, uint8_t len, uint8_t *rspbuf,
uint8_t *rsplen);
extern int r_btdm_hci_rd_local_supp_features_handler(const uint8_t *cmdbuf, uint8_t len, uint8_t *rspbuf,
uint8_t *rsplen);
extern int r_btdm_hci_rd_bdaddr_handler(const uint8_t *cmdbuf, uint8_t len, uint8_t *rspbuf,
uint8_t *rsplen);
uint8_t *rsplen);
extern int r_btdm_hci_rd_local_ext_features_handler(const uint8_t *cmdbuf, uint8_t len, uint8_t *rspbuf,
uint8_t *rsplen);
extern int r_btdm_hci_rd_bdaddr_handler(const uint8_t *cmdbuf, uint8_t len, uint8_t *rspbuf, uint8_t *rsplen);
extern int r_btdm_hci_rd_local_supp_codecs_handler(uint8_t *rspbuf, uint8_t *rsplen);
extern int r_btdm_hci_rd_local_supp_codecs_v2_handler(uint8_t *rspbuf, uint8_t *rsplen);
extern int r_btdm_hci_rd_local_supp_codec_cap_handler(const uint8_t *cmdbuf, uint8_t len,
@@ -795,9 +796,6 @@ hci_cmd_proc_controller_baseband_cmds(uint16_t ocf, const uint8_t *cmdbuf, uint8
#if UC_BT_CTRL_BLE_IS_ENABLE
ble_stack_reset();
#endif // UC_BT_CTRL_BLE_IS_ENABLE
#if UC_BT_CTRL_BR_EDR_IS_ENABLE
bredr_stack_reset();
#endif /* UC_BT_CTRL_BR_EDR_IS_ENABLE */
}
break;
case HCI_CMD_OCF_BB_SET_C2H_FLOW_CTRL:
@@ -881,6 +879,15 @@ hci_cmd_proc_informational_params_cmds(uint16_t ocf, const uint8_t *cmdbuf, uint
case HCI_CMD_OCF_INFO_READ_LOCAL_FEATURES:
rc = r_btdm_hci_rd_local_supp_features_handler(cmdbuf, len, rspbuf, rsplen);
break;
case HCI_CMD_OCF_INFO_READ_LOCAL_EXT_FEATURES:
rc = r_btdm_hci_rd_local_ext_features_handler(cmdbuf, len, rspbuf, rsplen);
break;
// case HCI_CMD_OCF_INFO_READ_BUFFER_SIZE:
// rc = r_ble_ll_hci_le_read_bufsize(cmdbuf, len, rspbuf, rsplen);
// break;
// case HCI_CMD_OCF_INFO_READ_COUNTRY_CODE:
// rc = HCI_CMD_ERR_UNKNOWN_HCI_CMD;
// break;
case HCI_CMD_OCF_INFO_READ_BD_ADDR:
rc = r_btdm_hci_rd_bdaddr_handler(cmdbuf, len, rspbuf, rsplen);
break;
@@ -1600,4 +1607,4 @@ hci_cmd_proc_init(void)
{
r_btdm_hci_set_cmd_handler_func(hci_cmd_proc_handler);
return 0;
}
}