forked from espressif/esp-idf
Merge branch 'feat/optimize_hci_data_recv_process_v5.0' into 'release/v5.0'
Feat/optimize hci data recv process (v5.0) See merge request espressif/esp-idf!37830
This commit is contained in:
@ -90,7 +90,7 @@ menu "HCI Config"
|
||||
config BT_LE_HCI_TRANS_TASK_STACK_SIZE
|
||||
int "HCI transport task stack size"
|
||||
depends on !BT_LE_HCI_INTERFACE_USE_RAM
|
||||
default 1024
|
||||
default 2048
|
||||
help
|
||||
This configures stack size of hci transport task
|
||||
endmenu
|
||||
@ -424,7 +424,7 @@ config BT_LE_CRYPTO_STACK_MBEDTLS
|
||||
|
||||
config BT_LE_WHITELIST_SIZE
|
||||
int "BLE white list size"
|
||||
range 1 15
|
||||
range 1 31
|
||||
default 12
|
||||
depends on !BT_NIMBLE_ENABLED
|
||||
|
||||
|
@ -709,6 +709,7 @@ config BT_NIMBLE_GATT_CACHING_DISABLE_AUTO
|
||||
config BT_NIMBLE_WHITELIST_SIZE
|
||||
int "BLE white list size"
|
||||
depends on BT_NIMBLE_ENABLED
|
||||
range 1 31 if SOC_ESP_NIMBLE_CONTROLLER
|
||||
range 1 15
|
||||
default 12
|
||||
help
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -27,7 +27,9 @@
|
||||
#include <string.h>
|
||||
#include <os/os.h>
|
||||
#include <os/os_mbuf.h>
|
||||
#include "esp_hci_driver.h"
|
||||
#include "common/hci_driver_h4.h"
|
||||
#include "common/hci_driver_util.h"
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
@ -62,9 +64,11 @@ hci_h4_frame_start(struct hci_h4_sm *rxs, uint8_t pkt_type)
|
||||
case HCI_H4_ISO:
|
||||
rxs->min_len = 4;
|
||||
break;
|
||||
#if (!CONFIG_BT_CONTROLLER_ENABLED)
|
||||
case HCI_H4_EVT:
|
||||
rxs->min_len = 2;
|
||||
break;
|
||||
#endif // (!CONFIG_BT_CONTROLLER_ENABLED)
|
||||
default:
|
||||
/* !TODO: Sync loss. Need to wait for reset. */
|
||||
return -1;
|
||||
@ -76,7 +80,7 @@ hci_h4_frame_start(struct hci_h4_sm *rxs, uint8_t pkt_type)
|
||||
static int
|
||||
hci_h4_ib_consume(struct hci_h4_input_buffer *ib, uint16_t len)
|
||||
{
|
||||
assert(ib->len >= len);
|
||||
HCI_TRANS_ASSERT((ib->len >= len), ib->len, len);
|
||||
|
||||
ib->buf += len;
|
||||
ib->len -= len;
|
||||
@ -113,7 +117,7 @@ hci_h4_sm_w4_header(struct hci_h4_sm *h4sm, struct hci_h4_input_buffer *ib)
|
||||
|
||||
switch (h4sm->pkt_type) {
|
||||
case HCI_H4_CMD:
|
||||
assert(h4sm->allocs && h4sm->allocs->cmd);
|
||||
HCI_TRANS_ASSERT(h4sm->allocs && h4sm->allocs->cmd, 0, 0);
|
||||
h4sm->buf = h4sm->allocs->cmd();
|
||||
if (!h4sm->buf) {
|
||||
return -1;
|
||||
@ -124,7 +128,7 @@ hci_h4_sm_w4_header(struct hci_h4_sm *h4sm, struct hci_h4_input_buffer *ib)
|
||||
|
||||
break;
|
||||
case HCI_H4_ACL:
|
||||
assert(h4sm->allocs && h4sm->allocs->acl);
|
||||
HCI_TRANS_ASSERT(h4sm->allocs && h4sm->allocs->acl, 0, 0);
|
||||
h4sm->om = h4sm->allocs->acl();
|
||||
if (!h4sm->om) {
|
||||
return -1;
|
||||
@ -145,7 +149,7 @@ hci_h4_sm_w4_header(struct hci_h4_sm *h4sm, struct hci_h4_input_buffer *ib)
|
||||
}
|
||||
}
|
||||
|
||||
assert(h4sm->allocs && h4sm->allocs->evt);
|
||||
HCI_TRANS_ASSERT(h4sm->allocs && h4sm->allocs->evt, 0, 0);
|
||||
|
||||
/* We can drop legacy advertising events if there's no free buffer in
|
||||
* discardable pool.
|
||||
@ -167,7 +171,7 @@ hci_h4_sm_w4_header(struct hci_h4_sm *h4sm, struct hci_h4_input_buffer *ib)
|
||||
break;
|
||||
#endif // !CONFIG_BT_CONTROLLER_ENABLED
|
||||
case HCI_H4_ISO:
|
||||
assert(h4sm->allocs && h4sm->allocs->iso);
|
||||
HCI_TRANS_ASSERT(h4sm->allocs && h4sm->allocs->iso, 0, 0);
|
||||
h4sm->om = h4sm->allocs->iso();
|
||||
if (!h4sm->om) {
|
||||
return -1;
|
||||
@ -177,8 +181,7 @@ hci_h4_sm_w4_header(struct hci_h4_sm *h4sm, struct hci_h4_input_buffer *ib)
|
||||
h4sm->exp_len = (get_le16(&h4sm->hdr[2]) & 0x7fff) + 4;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -193,19 +196,18 @@ hci_h4_sm_w4_payload(struct hci_h4_sm *h4sm,
|
||||
int rc;
|
||||
|
||||
len = min(ib->len, h4sm->exp_len - h4sm->len);
|
||||
|
||||
|
||||
switch (h4sm->pkt_type) {
|
||||
case HCI_H4_CMD:
|
||||
#if (!CONFIG_BT_CONTROLLER_ENABLED)
|
||||
case HCI_H4_EVT:
|
||||
#endif // (!CONFIG_BT_CONTROLLER_ENABLED)
|
||||
if (h4sm->buf) {
|
||||
memcpy(&h4sm->buf[h4sm->len], ib->buf, len);
|
||||
}
|
||||
break;
|
||||
case HCI_H4_ACL:
|
||||
case HCI_H4_ISO:
|
||||
assert(h4sm->om);
|
||||
|
||||
HCI_TRANS_ASSERT(h4sm->om, h4sm->pkt_type, len);
|
||||
mbuf_len = OS_MBUF_PKTLEN(h4sm->om);
|
||||
rc = os_mbuf_append(h4sm->om, ib->buf, len);
|
||||
if (rc) {
|
||||
@ -215,13 +217,11 @@ hci_h4_sm_w4_payload(struct hci_h4_sm *h4sm,
|
||||
len = OS_MBUF_PKTLEN(h4sm->om) - mbuf_len;
|
||||
h4sm->len += len;
|
||||
hci_h4_ib_consume(ib, len);
|
||||
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
return -2;
|
||||
}
|
||||
|
||||
h4sm->len += len;
|
||||
@ -240,51 +240,110 @@ hci_h4_sm_completed(struct hci_h4_sm *h4sm)
|
||||
#if CONFIG_BT_CONTROLLER_ENABLED
|
||||
case HCI_H4_CMD:
|
||||
if (h4sm->buf) {
|
||||
assert(h4sm->frame_cb);
|
||||
HCI_TRANS_ASSERT(h4sm->frame_cb, 0, 0);
|
||||
rc = h4sm->frame_cb(h4sm->pkt_type, h4sm->buf);
|
||||
assert(rc == 0);
|
||||
HCI_TRANS_ASSERT(rc == 0, rc, 0);
|
||||
h4sm->buf = NULL;
|
||||
}
|
||||
break;
|
||||
case HCI_H4_ACL:
|
||||
case HCI_H4_ISO:
|
||||
if (h4sm->om) {
|
||||
assert(h4sm->frame_cb);
|
||||
HCI_TRANS_ASSERT(h4sm->frame_cb, 0, 0);
|
||||
rc = h4sm->frame_cb(h4sm->pkt_type, h4sm->om);
|
||||
assert(rc == 0);
|
||||
HCI_TRANS_ASSERT(rc == 0, rc, 0);
|
||||
h4sm->om = NULL;
|
||||
}
|
||||
break;
|
||||
#else
|
||||
case HCI_H4_CMD:
|
||||
case HCI_H4_EVT:
|
||||
if (h4sm->buf) {
|
||||
assert(h4sm->frame_cb);
|
||||
HCI_TRANS_ASSERT(h4sm->frame_cb, 0, 0);
|
||||
rc = h4sm->frame_cb(h4sm->pkt_type, h4sm->buf);
|
||||
if (rc != 0) {
|
||||
ble_transport_free(h4sm->buf);
|
||||
HCI_TRANS_ASSERT(h4sm->frees && h4sm->frees->cmd, rc, (uint32_t)h4sm->frees);
|
||||
h4sm->frees->cmd(h4sm->buf);
|
||||
}
|
||||
h4sm->buf = NULL;
|
||||
}
|
||||
break;
|
||||
case HCI_H4_EVT:
|
||||
if (h4sm->buf) {
|
||||
HCI_TRANS_ASSERT(h4sm->frame_cb, 0, 0);
|
||||
rc = h4sm->frame_cb(h4sm->pkt_type, h4sm->buf);
|
||||
if (rc != 0) {
|
||||
HCI_TRANS_ASSERT(h4sm->frees && h4sm->frees->evt, rc, (uint32_t)h4sm->frees);
|
||||
h4sm->frees->evt(h4sm->buf);
|
||||
}
|
||||
h4sm->buf = NULL;
|
||||
}
|
||||
break;
|
||||
case HCI_H4_ACL:
|
||||
case HCI_H4_ISO:
|
||||
if (h4sm->om) {
|
||||
assert(h4sm->frame_cb);
|
||||
HCI_TRANS_ASSERT(h4sm->frame_cb, 0, 0);
|
||||
rc = h4sm->frame_cb(h4sm->pkt_type, h4sm->om);
|
||||
if (rc != 0) {
|
||||
os_mbuf_free_chain(h4sm->om);
|
||||
HCI_TRANS_ASSERT(h4sm->frees && h4sm->frees->acl, rc, (uint32_t)h4sm->frees);
|
||||
h4sm->frees->acl(h4sm->om);
|
||||
}
|
||||
h4sm->om = NULL;
|
||||
}
|
||||
break;
|
||||
case HCI_H4_ISO:
|
||||
if (h4sm->om) {
|
||||
HCI_TRANS_ASSERT(h4sm->frame_cb, 0, 0);
|
||||
rc = h4sm->frame_cb(h4sm->pkt_type, h4sm->om);
|
||||
if (rc != 0) {
|
||||
HCI_TRANS_ASSERT(h4sm->frees && h4sm->frees->iso, rc, (uint32_t)h4sm->frees);
|
||||
h4sm->frees->iso(h4sm->om);
|
||||
}
|
||||
h4sm->om = NULL;
|
||||
}
|
||||
break;
|
||||
#endif // CONFIG_BT_CONTROLLER_ENABLED
|
||||
default:
|
||||
assert(0);
|
||||
HCI_TRANS_ASSERT(0, h4sm->pkt_type, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
hci_h4_sm_free_buf(struct hci_h4_sm *h4sm)
|
||||
{
|
||||
switch (h4sm->pkt_type) {
|
||||
case HCI_H4_CMD:
|
||||
if (h4sm->buf) {
|
||||
h4sm->frees->cmd(h4sm->buf);
|
||||
h4sm->buf = NULL;
|
||||
}
|
||||
break;
|
||||
#if (!CONFIG_BT_CONTROLLER_ENABLED)
|
||||
case HCI_H4_EVT:
|
||||
if (h4sm->buf) {
|
||||
h4sm->frees->evt(h4sm->buf);
|
||||
h4sm->buf = NULL;
|
||||
}
|
||||
break;
|
||||
#endif // (!CONFIG_BT_CONTROLLER_ENABLED)
|
||||
case HCI_H4_ACL:
|
||||
if (h4sm->om) {
|
||||
h4sm->frees->acl(h4sm->om);
|
||||
h4sm->om = NULL;
|
||||
}
|
||||
break;
|
||||
case HCI_H4_ISO:
|
||||
if (h4sm->om) {
|
||||
h4sm->frees->iso(h4sm->om);
|
||||
h4sm->om = NULL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
hci_h4_sm_rx(struct hci_h4_sm *h4sm, const uint8_t *buf, uint16_t len)
|
||||
{
|
||||
@ -307,18 +366,18 @@ hci_h4_sm_rx(struct hci_h4_sm *h4sm, const uint8_t *buf, uint16_t len)
|
||||
/* no break */
|
||||
case HCI_H4_SM_W4_HEADER:
|
||||
rc = hci_h4_sm_w4_header(h4sm, &ib);
|
||||
assert(rc >= 0);
|
||||
if (rc) {
|
||||
break;
|
||||
}
|
||||
|
||||
h4sm->state = HCI_H4_SM_W4_PAYLOAD;
|
||||
/* no break */
|
||||
case HCI_H4_SM_W4_PAYLOAD:
|
||||
rc = hci_h4_sm_w4_payload(h4sm, &ib);
|
||||
assert(rc >= 0);
|
||||
if (rc) {
|
||||
break;
|
||||
}
|
||||
|
||||
h4sm->state = HCI_H4_SM_COMPLETED;
|
||||
/* no break */
|
||||
case HCI_H4_SM_COMPLETED:
|
||||
@ -330,6 +389,11 @@ hci_h4_sm_rx(struct hci_h4_sm *h4sm, const uint8_t *buf, uint16_t len)
|
||||
}
|
||||
}
|
||||
|
||||
if (rc < 0) {
|
||||
hci_h4_sm_free_buf(h4sm);
|
||||
h4sm->state = HCI_H4_SM_W4_PKT_TYPE;
|
||||
return -1;
|
||||
}
|
||||
/* Calculate consumed bytes
|
||||
*
|
||||
* Note: we should always consume some bytes unless there is an oom error.
|
||||
@ -339,7 +403,7 @@ hci_h4_sm_rx(struct hci_h4_sm *h4sm, const uint8_t *buf, uint16_t len)
|
||||
*/
|
||||
len = len - ib.len;
|
||||
if (len == 0) {
|
||||
assert(rc < 0);
|
||||
HCI_TRANS_ASSERT((rc < 0), rc, ib.len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -347,10 +411,11 @@ hci_h4_sm_rx(struct hci_h4_sm *h4sm, const uint8_t *buf, uint16_t len)
|
||||
}
|
||||
|
||||
void
|
||||
hci_h4_sm_init(struct hci_h4_sm *h4sm, const struct hci_h4_allocators *allocs,
|
||||
hci_h4_sm_init(struct hci_h4_sm *h4sm, const struct hci_h4_allocators *allocs, const struct hci_h4_frees *frees,
|
||||
hci_h4_frame_cb *frame_cb)
|
||||
{
|
||||
memset(h4sm, 0, sizeof(*h4sm));
|
||||
h4sm->allocs = allocs;
|
||||
h4sm->frees = frees;
|
||||
h4sm->frame_cb = frame_cb;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -53,3 +53,10 @@ const struct hci_h4_allocators s_hci_driver_mem_alloc = {
|
||||
.acl = hci_driver_mem_acl_alloc,
|
||||
.iso = hci_driver_mem_iso_alloc,
|
||||
};
|
||||
|
||||
const struct hci_h4_frees s_hci_driver_mem_free = {
|
||||
.cmd = r_ble_hci_trans_buf_free,
|
||||
.evt = r_ble_hci_trans_buf_free,
|
||||
.acl = os_mbuf_free_chain,
|
||||
.iso = os_mbuf_free_chain,
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -96,7 +96,7 @@ hci_driver_util_tx_list_enqueue(hci_driver_data_type_t type, uint8_t *data, uint
|
||||
hci_driver_util_tx_entry_t *tx_entry;
|
||||
|
||||
tx_entry = os_memblock_get(s_hci_driver_util_env.tx_entry_pool);
|
||||
assert(tx_entry != NULL);
|
||||
HCI_TRANS_ASSERT((tx_entry != NULL), 0, 0);
|
||||
tx_entry->data_type = type;
|
||||
tx_entry->data = data;
|
||||
tx_entry->length = len;
|
||||
@ -149,7 +149,7 @@ hci_driver_util_tx_list_dequeue(uint32_t max_tx_len, void **tx_data, bool *last_
|
||||
*tx_data = &tx_entry->data[s_hci_driver_util_env.cur_tx_off];
|
||||
}
|
||||
} else {
|
||||
assert(0);
|
||||
HCI_TRANS_ASSERT(0, tx_entry->data_type, data_len);
|
||||
}
|
||||
/* If this is the last frame, inform the invoker not to call this API until the current data
|
||||
* has been completely sent.
|
||||
@ -223,3 +223,10 @@ hci_driver_util_deinit(void)
|
||||
|
||||
memset(&s_hci_driver_util_env, 0, sizeof(hci_driver_util_env_t));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
hci_driver_util_assert_check(const uint32_t ln, const char *fn, uint32_t param1, uint32_t param2)
|
||||
{
|
||||
ESP_LOGE(TAG, "hci driver assert: line %d in function %s, param: 0x%x, 0x%x", ln, fn, param1, param2);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -37,7 +37,6 @@ typedef struct {
|
||||
static hci_driver_uart_env_t s_hci_driver_uart_env;
|
||||
static struct hci_h4_sm s_hci_driver_uart_h4_sm;
|
||||
static uint8_t s_hci_driver_uart_rx_data[CONFIG_BT_LE_HCI_RX_PROC_DATA_LEN];
|
||||
static hci_driver_uart_params_config_t hci_driver_uart_params = BT_HCI_DRIVER_UART_CONFIG_DEFAULT();
|
||||
|
||||
static int
|
||||
hci_driver_uart_tx(hci_driver_data_type_t data_type, uint8_t *data, uint32_t length,
|
||||
@ -111,6 +110,7 @@ hci_driver_uart_rx_task(void *p)
|
||||
ESP_LOG_BUFFER_HEXDUMP(TAG, data, read_len, ESP_LOG_DEBUG);
|
||||
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);
|
||||
r_ble_ll_hci_ev_hw_err(ESP_HCI_SYNC_LOSS_ERR);
|
||||
}
|
||||
}
|
||||
@ -175,7 +175,7 @@ hci_driver_uart_init(hci_driver_forward_fn *cb)
|
||||
memset(&s_hci_driver_uart_env, 0, sizeof(hci_driver_uart_env_t));
|
||||
|
||||
s_hci_driver_uart_env.h4_sm = &s_hci_driver_uart_h4_sm;
|
||||
hci_h4_sm_init(s_hci_driver_uart_env.h4_sm, &s_hci_driver_mem_alloc, hci_driver_uart_h4_frame_cb);
|
||||
hci_h4_sm_init(s_hci_driver_uart_env.h4_sm, &s_hci_driver_mem_alloc, &s_hci_driver_mem_free, hci_driver_uart_h4_frame_cb);
|
||||
|
||||
rc = hci_driver_util_init();
|
||||
if (rc) {
|
||||
@ -189,8 +189,8 @@ hci_driver_uart_init(hci_driver_forward_fn *cb)
|
||||
|
||||
s_hci_driver_uart_env.rx_data = s_hci_driver_uart_rx_data;
|
||||
s_hci_driver_uart_env.forward_cb = cb;
|
||||
s_hci_driver_uart_env.hci_uart_params = &hci_driver_uart_params;
|
||||
hci_driver_uart_config(&hci_driver_uart_params);
|
||||
s_hci_driver_uart_env.hci_uart_params = hci_driver_uart_config_param_get();
|
||||
hci_driver_uart_config(s_hci_driver_uart_env.hci_uart_params);
|
||||
/* Currently, the queue size is set to 1. It will be considered as semaphore. */
|
||||
ESP_ERROR_CHECK(uart_driver_install(s_hci_driver_uart_env.hci_uart_params->hci_uart_port,
|
||||
CONFIG_BT_LE_HCI_UART_RX_BUFFER_SIZE,
|
||||
@ -214,14 +214,9 @@ int
|
||||
hci_driver_uart_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin)
|
||||
{
|
||||
int rc;
|
||||
hci_driver_uart_params_config_t *uart_param = s_hci_driver_uart_env.hci_uart_params;
|
||||
|
||||
hci_driver_uart_task_delete();
|
||||
uart_param->hci_uart_tx_pin = tx_pin;
|
||||
uart_param->hci_uart_rx_pin = rx_pin;
|
||||
uart_param->hci_uart_rts_pin = rts_pin;
|
||||
uart_param->hci_uart_cts_pin = cts_pin;
|
||||
hci_driver_uart_config(uart_param);
|
||||
hci_driver_uart_pin_update(tx_pin, rx_pin, cts_pin, rts_pin);
|
||||
/* Currently, the queue size is set to 1. It will be considered as semaphore. */
|
||||
ESP_ERROR_CHECK(uart_driver_install(s_hci_driver_uart_env.hci_uart_params->hci_uart_port,
|
||||
CONFIG_BT_LE_HCI_UART_RX_BUFFER_SIZE,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -60,6 +60,28 @@ typedef struct hci_driver_uart_params_config
|
||||
*/
|
||||
int hci_driver_uart_config(hci_driver_uart_params_config_t *uart_config);
|
||||
|
||||
/**
|
||||
* @brief Update the UART pin configuration for the HCI driver.
|
||||
*
|
||||
* This function updates the TX, RX, CTS, and RTS pin assignments for the HCI driver operating over UART.
|
||||
* It allows dynamic reconfiguration of UART pins as needed.
|
||||
*
|
||||
* @param tx_pin The GPIO number assigned to the UART TX pin.
|
||||
* @param rx_pin The GPIO number assigned to the UART RX pin.
|
||||
* @param cts_pin The GPIO number assigned to the UART CTS pin.
|
||||
* @param rts_pin The GPIO number assigned to the UART RTS pin.
|
||||
*
|
||||
* @return 0 on success, or a negative error code on failure.
|
||||
*/
|
||||
int hci_driver_uart_pin_update(int tx_pin, int rx_pin, int cts_pin, int rts_pin);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the current UART configuration parameters for the HCI driver.
|
||||
*
|
||||
* @return hci_driver_uart_params_config_t* Pointer to the structure with UART configuration parameters.
|
||||
*/
|
||||
hci_driver_uart_params_config_t * hci_driver_uart_config_param_get(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -10,9 +10,9 @@
|
||||
#include "driver/uart.h"
|
||||
#include "hci_driver_uart.h"
|
||||
|
||||
|
||||
static const char *TAG = "hci_uart_config";
|
||||
static uart_config_t s_uart_cfg;
|
||||
static hci_driver_uart_params_config_t s_hci_driver_uart_params = BT_HCI_DRIVER_UART_CONFIG_DEFAULT();
|
||||
|
||||
int hci_driver_uart_config(hci_driver_uart_params_config_t *uart_config)
|
||||
{
|
||||
@ -26,7 +26,6 @@ int hci_driver_uart_config(hci_driver_uart_params_config_t *uart_config)
|
||||
uart_cfg->source_clk= UART_SCLK_DEFAULT;
|
||||
uart_cfg->rx_flow_ctrl_thresh = UART_FIFO_LEN - 1;
|
||||
|
||||
|
||||
ESP_LOGI(TAG,"set uart pin tx:%d, rx:%d.\n", uart_config->hci_uart_tx_pin, uart_config->hci_uart_rx_pin);
|
||||
ESP_LOGI(TAG,"set rts:%d, cts:%d.\n", uart_config->hci_uart_rts_pin, uart_config->hci_uart_cts_pin);
|
||||
ESP_LOGI(TAG,"set baud_rate:%d.\n", uart_config->hci_uart_baud);
|
||||
@ -38,3 +37,20 @@ int hci_driver_uart_config(hci_driver_uart_params_config_t *uart_config)
|
||||
uart_config->hci_uart_rts_pin, uart_config->hci_uart_cts_pin));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
hci_driver_uart_pin_update(int tx_pin, int rx_pin, int cts_pin, int rts_pin)
|
||||
{
|
||||
hci_driver_uart_params_config_t *uart_param = &s_hci_driver_uart_params;
|
||||
uart_param->hci_uart_tx_pin = tx_pin;
|
||||
uart_param->hci_uart_rx_pin = rx_pin;
|
||||
uart_param->hci_uart_rts_pin = rts_pin;
|
||||
uart_param->hci_uart_cts_pin = cts_pin;
|
||||
return hci_driver_uart_config(uart_param);
|
||||
}
|
||||
|
||||
hci_driver_uart_params_config_t *
|
||||
hci_driver_uart_config_param_get(void)
|
||||
{
|
||||
return &s_hci_driver_uart_params;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -114,7 +114,6 @@ int hci_driver_uart_dma_tx_start(esp_bt_hci_tl_callback_t callback, void *arg);
|
||||
static const char *TAG = "uart_dma";
|
||||
static hci_driver_uart_dma_env_t s_hci_driver_uart_dma_env;
|
||||
static struct hci_h4_sm s_hci_driver_uart_h4_sm;
|
||||
static hci_driver_uart_params_config_t hci_driver_uart_dma_params = BT_HCI_DRIVER_UART_CONFIG_DEFAULT();
|
||||
|
||||
/* The list for hci_rx_data */
|
||||
STAILQ_HEAD(g_hci_rxinfo_list, hci_message);
|
||||
@ -607,7 +606,7 @@ hci_driver_uart_dma_init(hci_driver_forward_fn *cb)
|
||||
memset(&s_hci_driver_uart_dma_env, 0, sizeof(hci_driver_uart_dma_env_t));
|
||||
|
||||
s_hci_driver_uart_dma_env.h4_sm = &s_hci_driver_uart_h4_sm;
|
||||
hci_h4_sm_init(s_hci_driver_uart_dma_env.h4_sm, &s_hci_driver_mem_alloc, hci_driver_uart_dma_h4_frame_cb);
|
||||
hci_h4_sm_init(s_hci_driver_uart_dma_env.h4_sm, &s_hci_driver_mem_alloc, &s_hci_driver_mem_free, hci_driver_uart_dma_h4_frame_cb);
|
||||
|
||||
rc = hci_driver_util_init();
|
||||
if (rc) {
|
||||
@ -625,8 +624,8 @@ hci_driver_uart_dma_init(hci_driver_forward_fn *cb)
|
||||
}
|
||||
|
||||
s_hci_driver_uart_dma_env.forward_cb = cb;
|
||||
s_hci_driver_uart_dma_env.hci_uart_params = &hci_driver_uart_dma_params;
|
||||
hci_driver_uart_config(&hci_driver_uart_dma_params);
|
||||
s_hci_driver_uart_dma_env.hci_uart_params = hci_driver_uart_config_param_get();
|
||||
hci_driver_uart_config(s_hci_driver_uart_dma_env.hci_uart_params);
|
||||
|
||||
ESP_LOGI(TAG, "uart attach uhci!");
|
||||
hci_driver_uart_dma_install();
|
||||
@ -653,12 +652,7 @@ error:
|
||||
int
|
||||
hci_driver_uart_dma_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin)
|
||||
{
|
||||
hci_driver_uart_params_config_t *uart_param = s_hci_driver_uart_dma_env.hci_uart_params;
|
||||
uart_param->hci_uart_tx_pin = tx_pin;
|
||||
uart_param->hci_uart_rx_pin = rx_pin;
|
||||
uart_param->hci_uart_rts_pin = rts_pin;
|
||||
uart_param->hci_uart_cts_pin = cts_pin;
|
||||
return hci_driver_uart_config(uart_param);
|
||||
return hci_driver_uart_pin_update(tx_pin, rx_pin, cts_pin, rts_pin);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -48,6 +48,17 @@ struct hci_h4_allocators {
|
||||
extern const struct hci_h4_allocators hci_h4_allocs_from_ll;
|
||||
extern const struct hci_h4_allocators hci_h4_allocs_from_hs;
|
||||
|
||||
typedef void (hci_h4_free_cmd)(uint8_t *buf);
|
||||
typedef void (hci_h4_free_evt)(uint8_t *buf);
|
||||
typedef int (hci_h4_free_acl)(struct os_mbuf *om);
|
||||
typedef int (hci_h4_free_iso)(struct os_mbuf *om);
|
||||
struct hci_h4_frees {
|
||||
hci_h4_free_cmd *cmd;
|
||||
hci_h4_free_acl *acl;
|
||||
hci_h4_free_evt *evt;
|
||||
hci_h4_free_iso *iso;
|
||||
};
|
||||
|
||||
typedef int (hci_h4_frame_cb)(uint8_t pkt_type, void *data);
|
||||
|
||||
struct hci_h4_sm {
|
||||
@ -63,11 +74,13 @@ struct hci_h4_sm {
|
||||
};
|
||||
|
||||
const struct hci_h4_allocators *allocs;
|
||||
const struct hci_h4_frees *frees;
|
||||
hci_h4_frame_cb *frame_cb;
|
||||
};
|
||||
|
||||
void hci_h4_sm_init(struct hci_h4_sm *h4sm,
|
||||
const struct hci_h4_allocators *allocs,
|
||||
const struct hci_h4_frees *frees,
|
||||
hci_h4_frame_cb *frame_cb);
|
||||
|
||||
int hci_h4_sm_rx(struct hci_h4_sm *h4sm, const uint8_t *buf, uint16_t len);
|
||||
|
@ -21,5 +21,5 @@ struct os_mbuf *hci_driver_mem_iso_alloc(void);
|
||||
struct os_mbuf *hci_driver_mem_iso_len_alloc(uint32_t len);
|
||||
|
||||
extern const struct hci_h4_allocators s_hci_driver_mem_alloc;
|
||||
|
||||
extern const struct hci_h4_frees s_hci_driver_mem_free;
|
||||
#endif // _H_HCI_DRIVER_MEM_
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -15,4 +15,9 @@ void hci_driver_util_tx_list_enqueue(hci_driver_data_type_t type, uint8_t *data,
|
||||
|
||||
uint32_t hci_driver_util_tx_list_dequeue(uint32_t max_tx_len, void **tx_data, bool *last_frame);
|
||||
|
||||
void hci_driver_util_assert_check(const uint32_t ln, const char *fn, uint32_t param1, uint32_t param2);
|
||||
#define HCI_TRANS_ASSERT(cond, p1, p2) \
|
||||
if (!(cond)) { \
|
||||
hci_driver_util_assert_check(__LINE__, __func__, p1, p2); \
|
||||
}
|
||||
#endif // _H_HCI_DRIVER_UTIL_
|
||||
|
Reference in New Issue
Block a user