Bluetooth: drivers: Convert STM32 IPM driver to new API

Convert the ipm_stm32wb.c HCI driver to the new HCI driver API.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
This commit is contained in:
Johan Hedberg 2024-06-01 16:25:48 +03:00 committed by Anas Nashif
commit 501e7158a8
4 changed files with 43 additions and 18 deletions

View file

@ -59,6 +59,8 @@ config BT_SPI
config BT_STM32_IPM config BT_STM32_IPM
bool "IPM HCI" bool "IPM HCI"
default y
depends on DT_HAS_ST_STM32WB_RF_ENABLED
select USE_STM32_HAL_CORTEX select USE_STM32_HAL_CORTEX
select HAS_STM32LIB select HAS_STM32LIB
help help

View file

@ -11,7 +11,7 @@
#include <zephyr/init.h> #include <zephyr/init.h>
#include <zephyr/sys/util.h> #include <zephyr/sys/util.h>
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#include <zephyr/drivers/bluetooth/hci_driver.h> #include <zephyr/drivers/bluetooth.h>
#include <zephyr/bluetooth/addr.h> #include <zephyr/bluetooth/addr.h>
#include <zephyr/drivers/clock_control/stm32_clock_control.h> #include <zephyr/drivers/clock_control/stm32_clock_control.h>
#include <zephyr/irq.h> #include <zephyr/irq.h>
@ -21,7 +21,11 @@
#include "shci.h" #include "shci.h"
#include "shci_tl.h" #include "shci_tl.h"
static const struct stm32_pclken clk_cfg[] = STM32_DT_CLOCKS(DT_NODELABEL(ble_rf)); struct hci_data {
bt_hci_recv_t recv;
};
static const struct stm32_pclken clk_cfg[] = STM32_DT_CLOCKS(DT_DRV_INST(0));
#define POOL_SIZE (CFG_TLBLE_EVT_QUEUE_LENGTH * 4 * \ #define POOL_SIZE (CFG_TLBLE_EVT_QUEUE_LENGTH * 4 * \
DIVC((sizeof(TL_PacketHeader_t) + TL_BLE_EVENT_FRAME_SIZE), 4)) DIVC((sizeof(TL_PacketHeader_t) + TL_BLE_EVENT_FRAME_SIZE), 4))
@ -156,7 +160,9 @@ void TM_EvtReceivedCb(TL_EvtPacket_t *hcievt)
static void bt_ipm_rx_thread(void *p1, void *p2, void *p3) static void bt_ipm_rx_thread(void *p1, void *p2, void *p3)
{ {
ARG_UNUSED(p1); const struct device *dev = p1;
struct hci_data *hci = dev->data;
ARG_UNUSED(p2); ARG_UNUSED(p2);
ARG_UNUSED(p3); ARG_UNUSED(p3);
@ -245,7 +251,7 @@ static void bt_ipm_rx_thread(void *p1, void *p2, void *p3)
TL_MM_EvtDone(hcievt); TL_MM_EvtDone(hcievt);
bt_recv(buf); hci->recv(dev, buf);
end_loop: end_loop:
k_sem_give(&ipm_busy); k_sem_give(&ipm_busy);
} }
@ -347,10 +353,12 @@ void transport_init(void)
TL_Enable(); TL_Enable();
} }
static int bt_ipm_send(struct net_buf *buf) static int bt_ipm_send(const struct device *dev, struct net_buf *buf)
{ {
TL_CmdPacket_t *ble_cmd_buff = &BleCmdBuffer; TL_CmdPacket_t *ble_cmd_buff = &BleCmdBuffer;
ARG_UNUSED(dev);
k_sem_take(&ipm_busy, K_FOREVER); k_sem_take(&ipm_busy, K_FOREVER);
switch (bt_buf_get_type(buf)) { switch (bt_buf_get_type(buf)) {
@ -534,8 +542,9 @@ static int c2_reset(void)
return 0; return 0;
} }
static int bt_ipm_open(void) static int bt_ipm_open(const struct device *dev, bt_hci_recv_t recv)
{ {
struct hci_data *hci = dev->data;
int err; int err;
if (!c2_started_flag) { if (!c2_started_flag) {
@ -553,7 +562,7 @@ static int bt_ipm_open(void)
/* Start RX thread */ /* Start RX thread */
k_thread_create(&ipm_rx_thread_data, ipm_rx_stack, k_thread_create(&ipm_rx_thread_data, ipm_rx_stack,
K_KERNEL_STACK_SIZEOF(ipm_rx_stack), K_KERNEL_STACK_SIZEOF(ipm_rx_stack),
bt_ipm_rx_thread, NULL, NULL, NULL, bt_ipm_rx_thread, (void *)dev, NULL, NULL,
K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO),
0, K_NO_WAIT); 0, K_NO_WAIT);
@ -564,14 +573,17 @@ static int bt_ipm_open(void)
} }
#endif /* CONFIG_BT_HCI_HOST */ #endif /* CONFIG_BT_HCI_HOST */
hci->recv = recv;
LOG_DBG("IPM Channel Open Completed"); LOG_DBG("IPM Channel Open Completed");
return 0; return 0;
} }
#ifdef CONFIG_BT_HCI_HOST #ifdef CONFIG_BT_HCI_HOST
static int bt_ipm_close(void) static int bt_ipm_close(const struct device *dev)
{ {
struct hci_data *hci = dev->data;
int err; int err;
struct net_buf *rsp; struct net_buf *rsp;
@ -590,15 +602,15 @@ static int bt_ipm_close(void)
k_thread_abort(&ipm_rx_thread_data); k_thread_abort(&ipm_rx_thread_data);
hci->recv = NULL;
LOG_DBG("IPM Channel Close Completed"); LOG_DBG("IPM Channel Close Completed");
return err; return err;
} }
#endif /* CONFIG_BT_HCI_HOST */ #endif /* CONFIG_BT_HCI_HOST */
static const struct bt_hci_driver drv = { static const struct bt_hci_driver_api drv = {
.name = "BT IPM",
.bus = BT_HCI_DRIVER_BUS_IPM,
.open = bt_ipm_open, .open = bt_ipm_open,
#ifdef CONFIG_BT_HCI_HOST #ifdef CONFIG_BT_HCI_HOST
.close = bt_ipm_close, .close = bt_ipm_close,
@ -606,12 +618,11 @@ static const struct bt_hci_driver drv = {
.send = bt_ipm_send, .send = bt_ipm_send,
}; };
static int _bt_ipm_init(void) static int _bt_ipm_init(const struct device *dev)
{ {
int err; int err;
ARG_UNUSED(dev);
bt_hci_driver_register(&drv);
err = c2_reset(); err = c2_reset();
if (err) { if (err) {
@ -621,4 +632,11 @@ static int _bt_ipm_init(void)
return 0; return 0;
} }
SYS_INIT(_bt_ipm_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); #define HCI_DEVICE_INIT(inst) \
static struct hci_data hci_data_##inst = { \
}; \
DEVICE_DT_INST_DEFINE(inst, _bt_ipm_init, NULL, &hci_data_##inst, NULL, \
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv)
/* Only one instance supported right now */
HCI_DEVICE_INIT(0)

View file

@ -23,6 +23,7 @@
chosen { chosen {
zephyr,entropy = &rng; zephyr,entropy = &rng;
zephyr,flash-controller = &flash; zephyr,flash-controller = &flash;
zephyr,bt-hci = &ble_rf;
}; };
cpus { cpus {

View file

@ -6,8 +6,12 @@ description: |
compatible: "st,stm32wb-rf" compatible: "st,stm32wb-rf"
include: base.yaml include: bt-hci.yaml
properties: properties:
clocks: clocks:
required: true required: true
bt-hci-name:
default: "BT IPM"
bt-hci-bus:
default: "BT_HCI_BUS_IPM"