mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-06-05 21:04:49 +00:00
add hci driver for esp_ipc
This commit is contained in:
@@ -833,11 +833,6 @@ ble_hs_init(void)
|
||||
ble_hs_evq_set(nimble_port_get_dflt_eventq());
|
||||
#endif
|
||||
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
|
||||
/* Configure the HCI transport to communicate with a host. */
|
||||
ble_hci_trans_cfg_hs(ble_hs_hci_rx_evt, NULL, ble_hs_rx_data, NULL);
|
||||
#endif
|
||||
|
||||
/* Enqueue the start event to the default event queue. Using the default
|
||||
* queue ensures the event won't run until the end of main(). This allows
|
||||
* the application to configure this package in the meantime.
|
||||
@@ -891,10 +886,6 @@ ble_hs_deinit(void)
|
||||
ble_monitor_deinit();
|
||||
#endif
|
||||
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
|
||||
ble_hci_trans_cfg_hs(NULL, NULL, NULL, NULL);
|
||||
#endif
|
||||
|
||||
ble_npl_mutex_deinit(&ble_hs_mutex);
|
||||
|
||||
ble_mqueue_deinit(&ble_hs_rx_q);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <sysinit/sysinit.h>
|
||||
#include <syscfg/syscfg.h>
|
||||
#include "os/os_mbuf.h"
|
||||
#include "nimble/transport.h"
|
||||
#include "esp_hci_transport.h"
|
||||
#include "esp_hci_internal.h"
|
||||
|
||||
static int
|
||||
ble_transport_host_recv_cb(hci_trans_pkt_ind_t type, uint8_t *data, uint16_t len)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (type == HCI_ACL_IND) {
|
||||
rc = ble_transport_to_hs_acl((struct os_mbuf *)data);
|
||||
} else {
|
||||
rc = ble_transport_to_hs_evt(data);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
ble_transport_to_ll_cmd_impl(void *buf)
|
||||
{
|
||||
return hci_transport_host_cmd_tx(buf, 0);
|
||||
}
|
||||
|
||||
int
|
||||
ble_transport_to_ll_acl_impl(struct os_mbuf *om)
|
||||
{
|
||||
return hci_transport_host_acl_tx((uint8_t *)om, 0);
|
||||
}
|
||||
|
||||
void
|
||||
ble_transport_ll_init(void)
|
||||
{
|
||||
hci_transport_host_callback_register(ble_transport_host_recv_cb);
|
||||
}
|
||||
|
||||
void *
|
||||
ble_transport_alloc_cmd(void)
|
||||
{
|
||||
return r_ble_hci_trans_buf_alloc(ESP_HCI_INTERNAL_BUF_CMD);
|
||||
}
|
||||
|
||||
void
|
||||
ble_transport_free(void *buf)
|
||||
{
|
||||
r_ble_hci_trans_buf_free(buf);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <sysinit/sysinit.h>
|
||||
#include <syscfg/syscfg.h>
|
||||
#include "nimble/transport.h"
|
||||
#include "esp_nimble_hci.h"
|
||||
|
||||
/* This file is only used by ESP32, ESP32C3 and ESP32S3. */
|
||||
int
|
||||
ble_transport_to_ll_cmd_impl(void *buf)
|
||||
{
|
||||
return ble_hci_trans_hs_cmd_tx(buf);
|
||||
}
|
||||
|
||||
int
|
||||
ble_transport_to_ll_acl_impl(struct os_mbuf *om)
|
||||
{
|
||||
return ble_hci_trans_hs_acl_tx(om);
|
||||
}
|
||||
|
||||
@@ -76,154 +76,6 @@ void ble_transport_deinit(void);
|
||||
typedef int ble_hci_trans_rx_cmd_fn(uint8_t *cmd, void *arg);
|
||||
typedef int ble_hci_trans_rx_acl_fn(struct os_mbuf *om, void *arg);
|
||||
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
|
||||
#define ble_transport_alloc_cmd() ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD)
|
||||
#define ble_transport_alloc_event(X) ble_hci_trans_buf_alloc(X ? BLE_HCI_TRANS_BUF_EVT_LO : BLE_HCI_TRANS_BUF_EVT_HI)
|
||||
#define ble_transport_free ble_hci_trans_buf_free
|
||||
|
||||
struct ble_hci_trans_funcs_t {
|
||||
int(*_ble_hci_trans_hs_acl_tx)(struct os_mbuf *om);
|
||||
int(*_ble_hci_trans_hs_cmd_tx)(uint8_t *cmd);
|
||||
int(*_ble_hci_trans_ll_acl_tx)(struct os_mbuf *om);
|
||||
int(*_ble_hci_trans_ll_evt_tx)(uint8_t *hci_ev);
|
||||
int(*_ble_hci_trans_reset)(void);
|
||||
int(*_ble_hci_trans_set_acl_free_cb)(os_mempool_put_fn *cb,void *arg);
|
||||
};
|
||||
|
||||
extern struct ble_hci_trans_funcs_t *ble_hci_trans_funcs_ptr;
|
||||
|
||||
/**
|
||||
* Sends an HCI event from the controller to the host.
|
||||
*
|
||||
* @param cmd The HCI event to send. This buffer must be
|
||||
* allocated via ble_hci_trans_buf_alloc().
|
||||
*
|
||||
* @return 0 on success;
|
||||
* A BLE_ERR_[...] error code on failure.
|
||||
*/
|
||||
extern int r_ble_hci_trans_ll_evt_tx(uint8_t *hci_ev);
|
||||
#define ble_hci_trans_ll_evt_tx ble_hci_trans_funcs_ptr->_ble_hci_trans_ll_evt_tx
|
||||
|
||||
/**
|
||||
* Sends ACL data from controller to host.
|
||||
*
|
||||
* @param om The ACL data packet to send.
|
||||
*
|
||||
* @return 0 on success;
|
||||
* A BLE_ERR_[...] error code on failure.
|
||||
*/
|
||||
extern int r_ble_hci_trans_ll_acl_tx(struct os_mbuf *om);
|
||||
#define ble_hci_trans_ll_acl_tx ble_hci_trans_funcs_ptr->_ble_hci_trans_ll_acl_tx
|
||||
|
||||
/**
|
||||
* Sends an HCI command from the host to the controller.
|
||||
*
|
||||
* @param cmd The HCI command to send. This buffer must be
|
||||
* allocated via ble_hci_trans_buf_alloc().
|
||||
*
|
||||
* @return 0 on success;
|
||||
* A BLE_ERR_[...] error code on failure.
|
||||
*/
|
||||
extern int r_ble_hci_trans_hs_cmd_tx(uint8_t *cmd);
|
||||
#define ble_hci_trans_hs_cmd_tx ble_hci_trans_funcs_ptr->_ble_hci_trans_hs_cmd_tx
|
||||
|
||||
/**
|
||||
* Sends ACL data from host to controller.
|
||||
*
|
||||
* @param om The ACL data packet to send.
|
||||
*
|
||||
* @return 0 on success;
|
||||
* A BLE_ERR_[...] error code on failure.
|
||||
*/
|
||||
extern int r_ble_hci_trans_hs_acl_tx(struct os_mbuf *om);
|
||||
#define ble_hci_trans_hs_acl_tx ble_hci_trans_funcs_ptr->_ble_hci_trans_hs_acl_tx
|
||||
|
||||
/**
|
||||
* Allocates a flat buffer of the specified type.
|
||||
*
|
||||
* @param type The type of buffer to allocate; one of the
|
||||
* BLE_HCI_TRANS_BUF_[...] constants.
|
||||
*
|
||||
* @return The allocated buffer on success;
|
||||
* NULL on buffer exhaustion.
|
||||
*/
|
||||
extern uint8_t *r_ble_hci_trans_buf_alloc(int type);
|
||||
#define ble_hci_trans_buf_alloc r_ble_hci_trans_buf_alloc
|
||||
|
||||
/**
|
||||
* Frees the specified flat buffer. The buffer must have been allocated via
|
||||
* ble_hci_trans_buf_alloc().
|
||||
*
|
||||
* @param buf The buffer to free.
|
||||
*/
|
||||
extern void r_ble_hci_trans_buf_free(uint8_t *buf);
|
||||
#define ble_hci_trans_buf_free r_ble_hci_trans_buf_free
|
||||
|
||||
/**
|
||||
* Configures a callback to get executed whenever an ACL data packet is freed.
|
||||
* The function is called immediately before the free occurs.
|
||||
*
|
||||
* @param cb The callback to configure.
|
||||
* @param arg An optional argument to pass to the callback.
|
||||
*
|
||||
* @return 0 on success;
|
||||
* BLE_ERR_UNSUPPORTED if the transport does not
|
||||
* support this operation.
|
||||
*/
|
||||
extern int r_ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg);
|
||||
#define ble_hci_trans_set_acl_free_cb ble_hci_trans_funcs_ptr->_ble_hci_trans_set_acl_free_cb
|
||||
|
||||
/**
|
||||
* Configures the HCI transport to operate with a controller. The transport
|
||||
* will execute specified callbacks upon receiving HCI packets from the host.
|
||||
*
|
||||
* @param cmd_cb The callback to execute upon receiving an HCI
|
||||
* command.
|
||||
* @param cmd_arg Optional argument to pass to the command
|
||||
* callback.
|
||||
* @param acl_cb The callback to execute upon receiving ACL
|
||||
* data.
|
||||
* @param acl_arg Optional argument to pass to the ACL
|
||||
* callback.
|
||||
*/
|
||||
extern void r_ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
|
||||
void *cmd_arg,
|
||||
ble_hci_trans_rx_acl_fn *acl_cb,
|
||||
void *acl_arg);
|
||||
#define ble_hci_trans_cfg_ll r_ble_hci_trans_cfg_ll
|
||||
|
||||
/**
|
||||
* Configures the HCI transport to operate with a host. The transport will
|
||||
* execute specified callbacks upon receiving HCI packets from the controller.
|
||||
*
|
||||
* @param evt_cb The callback to execute upon receiving an HCI
|
||||
* event.
|
||||
* @param evt_arg Optional argument to pass to the event
|
||||
* callback.
|
||||
* @param acl_cb The callback to execute upon receiving ACL
|
||||
* data.
|
||||
* @param acl_arg Optional argument to pass to the ACL
|
||||
* callback.
|
||||
*/
|
||||
extern void r_ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *evt_cb,
|
||||
void *evt_arg,
|
||||
ble_hci_trans_rx_acl_fn *acl_cb,
|
||||
void *acl_arg);
|
||||
#define ble_hci_trans_cfg_hs r_ble_hci_trans_cfg_hs
|
||||
|
||||
/**
|
||||
* Resets the HCI module to a clean state. Frees all buffers and reinitializes
|
||||
* the underlying transport.
|
||||
*
|
||||
* @return 0 on success;
|
||||
* A BLE_ERR_[...] error code on failure.
|
||||
*/
|
||||
extern int r_ble_hci_trans_reset(void);
|
||||
#define ble_hci_trans_reset ble_hci_trans_funcs_ptr->_ble_hci_trans_reset
|
||||
|
||||
void esp_ble_hci_trans_init(uint8_t);
|
||||
|
||||
#else
|
||||
/**
|
||||
* Sends an HCI event from the controller to the host.
|
||||
*
|
||||
@@ -332,14 +184,13 @@ void esp_ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *evt_cb,
|
||||
* A BLE_ERR_[...] error code on failure.
|
||||
*/
|
||||
int esp_ble_hci_trans_reset(void);
|
||||
#endif
|
||||
|
||||
struct os_mbuf;
|
||||
|
||||
/* Initialization */
|
||||
void ble_transport_init(void);
|
||||
|
||||
/* Allocators for supported data types */
|
||||
#if !SOC_ESP_NIMBLE_CONTROLLER || !CONFIG_BT_CONTROLLER_ENABLED
|
||||
void *ble_transport_alloc_cmd(void);
|
||||
void *ble_transport_alloc_evt(int discardable);
|
||||
struct os_mbuf *ble_transport_alloc_acl_from_hs(void);
|
||||
@@ -349,18 +200,13 @@ struct os_mbuf *ble_transport_alloc_iso_from_ll(void);
|
||||
|
||||
/* Generic deallocator for cmd/evt buffers */
|
||||
void ble_transport_free(void *buf);
|
||||
#endif
|
||||
|
||||
/* Register put callback on acl_from_ll mbufs (for ll-hs flow control) */
|
||||
int ble_transport_register_put_acl_from_ll_cb(os_mempool_put_fn *cb);
|
||||
|
||||
#if CONFIG_BT_CONTROLLER_ENABLED
|
||||
#define ble_transport_to_ll_acl ble_hci_trans_hs_acl_tx
|
||||
#define ble_transport_to_ll_cmd ble_hci_trans_hs_cmd_tx
|
||||
#else
|
||||
|
||||
int ble_transport_to_ll_cmd(void *buf);
|
||||
int ble_transport_to_ll_acl(struct os_mbuf *om);
|
||||
#endif
|
||||
|
||||
/* Send data to hs/ll side */
|
||||
int ble_transport_to_ll_iso(struct os_mbuf *om);
|
||||
|
||||
@@ -124,7 +124,7 @@ esp_err_t esp_nimble_init(void)
|
||||
#endif
|
||||
/* Initialize the host */
|
||||
ble_transport_hs_init();
|
||||
#if CONFIG_BT_CONTROLLER_DISABLED && CONFIG_BT_NIMBLE_TRANSPORT_UART
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER || CONFIG_BT_CONTROLLER_DISABLED
|
||||
ble_transport_ll_init();
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user