mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-18 06:59:55 +00:00
transport/nrf5340: Add support for host to controller flow control
This commit is contained in:
@@ -73,8 +73,20 @@ struct nrf5340_ble_hci_pool_cmd {
|
||||
bool allocated;
|
||||
};
|
||||
|
||||
/* (Pseudo)pool for HCI commands */
|
||||
static struct nrf5340_ble_hci_pool_cmd nrf5340_ble_hci_pool_cmd;
|
||||
/*
|
||||
* If controller-to-host flow control is enabled we need to hold an extra command
|
||||
* buffer for HCI_Host_Number_Of_Completed_Packets which can be sent at any time.
|
||||
*/
|
||||
#if MYNEWT_VAL(BLE_HS_FLOW_CTRL) || MYNEWT_VAL(BLE_LL_CFG_FEAT_CTRL_TO_HOST_FLOW_CONTROL)
|
||||
#define HCI_CMD_COUNT 2
|
||||
#else
|
||||
#define HCI_CMD_COUNT 1
|
||||
#endif
|
||||
|
||||
static uint8_t nrf5340_ble_hci_pool_cmd_mempool_buf[OS_MEMPOOL_BYTES(
|
||||
HCI_CMD_COUNT,
|
||||
BLE_HCI_TRANS_CMD_SZ)];
|
||||
static struct os_mempool nrf5340_ble_hci_pool_cmd_mempool;
|
||||
|
||||
/* Pools for HCI events (high and low priority) */
|
||||
static uint8_t nrf5340_ble_hci_pool_evt_hi_buf[OS_MEMPOOL_BYTES(
|
||||
@@ -90,7 +102,7 @@ static struct os_mempool nrf5340_ble_hci_pool_evt_lo;
|
||||
static uint8_t nrf5340_ble_hci_pool_acl_buf[OS_MEMPOOL_BYTES(
|
||||
MYNEWT_VAL(BLE_ACL_BUF_COUNT),
|
||||
POOL_ACL_BLOCK_SIZE)];
|
||||
static struct os_mempool nrf5340_ble_hci_pool_acl;
|
||||
static struct os_mempool_ext nrf5340_ble_hci_pool_acl;
|
||||
static struct os_mbuf_pool nrf5340_ble_hci_pool_acl_mbuf;
|
||||
|
||||
/* Interface to host/ll */
|
||||
@@ -207,9 +219,7 @@ ble_hci_trans_buf_alloc(int type)
|
||||
|
||||
switch (type) {
|
||||
case BLE_HCI_TRANS_BUF_CMD:
|
||||
assert(!nrf5340_ble_hci_pool_cmd.allocated);
|
||||
nrf5340_ble_hci_pool_cmd.allocated = 1;
|
||||
buf = nrf5340_ble_hci_pool_cmd.cmd;
|
||||
buf = os_memblock_get(&nrf5340_ble_hci_pool_cmd_mempool);
|
||||
break;
|
||||
case BLE_HCI_TRANS_BUF_EVT_HI:
|
||||
buf = os_memblock_get(&nrf5340_ble_hci_pool_evt_hi);
|
||||
@@ -233,9 +243,9 @@ ble_hci_trans_buf_free(uint8_t *buf)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (buf == nrf5340_ble_hci_pool_cmd.cmd) {
|
||||
assert(nrf5340_ble_hci_pool_cmd.allocated);
|
||||
nrf5340_ble_hci_pool_cmd.allocated = 0;
|
||||
if (os_memblock_from(&nrf5340_ble_hci_pool_cmd_mempool, buf)) {
|
||||
rc = os_memblock_put(&nrf5340_ble_hci_pool_cmd_mempool, buf);
|
||||
assert(rc == 0);
|
||||
} else if (os_memblock_from(&nrf5340_ble_hci_pool_evt_hi, buf)) {
|
||||
rc = os_memblock_put(&nrf5340_ble_hci_pool_evt_hi, buf);
|
||||
assert(rc == 0);
|
||||
@@ -387,7 +397,7 @@ nrf5340_ble_hci_trans_rx_process(int channel)
|
||||
rxd->om = os_mbuf_get_pkthdr(&nrf5340_ble_hci_pool_acl_mbuf,
|
||||
sizeof(struct ble_mbuf_hdr));
|
||||
if (!rxd->om) {
|
||||
/* not much we can do here... */
|
||||
/* TODO not much we can do here... */
|
||||
assert(0);
|
||||
}
|
||||
|
||||
@@ -423,6 +433,15 @@ nrf5340_ble_hci_trans_rx(int channel, void *user_data)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg)
|
||||
{
|
||||
nrf5340_ble_hci_pool_acl.mpe_put_cb = cb;
|
||||
nrf5340_ble_hci_pool_acl.mpe_put_arg = arg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nrf5340_ble_hci_init(void)
|
||||
{
|
||||
@@ -430,13 +449,14 @@ nrf5340_ble_hci_init(void)
|
||||
|
||||
SYSINIT_ASSERT_ACTIVE();
|
||||
|
||||
rc = os_mempool_init(&nrf5340_ble_hci_pool_acl, MYNEWT_VAL(BLE_ACL_BUF_COUNT),
|
||||
POOL_ACL_BLOCK_SIZE, nrf5340_ble_hci_pool_acl_buf,
|
||||
"nrf5340_ble_hci_pool_acl");
|
||||
rc = os_mempool_ext_init(&nrf5340_ble_hci_pool_acl,
|
||||
MYNEWT_VAL(BLE_ACL_BUF_COUNT), POOL_ACL_BLOCK_SIZE,
|
||||
nrf5340_ble_hci_pool_acl_buf,
|
||||
"nrf5340_ble_hci_pool_acl");
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
|
||||
rc = os_mbuf_pool_init(&nrf5340_ble_hci_pool_acl_mbuf,
|
||||
&nrf5340_ble_hci_pool_acl, POOL_ACL_BLOCK_SIZE,
|
||||
&nrf5340_ble_hci_pool_acl.mpe_mp, POOL_ACL_BLOCK_SIZE,
|
||||
MYNEWT_VAL(BLE_ACL_BUF_COUNT));
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
|
||||
@@ -454,5 +474,11 @@ nrf5340_ble_hci_init(void)
|
||||
"nrf5340_ble_hci_pool_evt_lo");
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
|
||||
rc = os_mempool_init(&nrf5340_ble_hci_pool_cmd_mempool,
|
||||
HCI_CMD_COUNT, BLE_HCI_TRANS_CMD_SZ,
|
||||
nrf5340_ble_hci_pool_cmd_mempool_buf,
|
||||
"nrf5340_ble_hci_pool_cmd_mempool");
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
|
||||
ipc_nrf5340_recv(IPC_RX_CHANNEL, nrf5340_ble_hci_trans_rx, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user