Skip to content

Commit b41d7f0

Browse files
committed
Bluetooth: Controller: Implement bt_hci_driver::close
The open source controller did not expose support for shutting it down via the close() API in the HCI driver. Add support for it, which completes the support for disabling and enabling the Bluetooth stack in Zephyr. Closes #3192. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
1 parent 4349a47 commit b41d7f0

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

subsys/bluetooth/controller/hci/hci_driver.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363

6464
#include "hci_internal.h"
6565

66-
static K_SEM_DEFINE(sem_prio_recv, 0, K_SEM_MAX_LIMIT);
67-
static K_FIFO_DEFINE(recv_fifo);
66+
static struct k_sem sem_prio_recv;
67+
static struct k_fifo recv_fifo;
6868

6969
struct k_thread prio_recv_thread_data;
7070
static K_KERNEL_STACK_DEFINE(prio_recv_thread_stack,
@@ -73,8 +73,7 @@ struct k_thread recv_thread_data;
7373
static K_KERNEL_STACK_DEFINE(recv_thread_stack, CONFIG_BT_RX_STACK_SIZE);
7474

7575
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
76-
static struct k_poll_signal hbuf_signal =
77-
K_POLL_SIGNAL_INITIALIZER(hbuf_signal);
76+
static struct k_poll_signal hbuf_signal;
7877
static sys_slist_t hbuf_pend;
7978
static int32_t hbuf_count;
8079
#endif
@@ -734,13 +733,17 @@ static int hci_driver_open(void)
734733

735734
DEBUG_INIT();
736735

736+
k_fifo_init(&recv_fifo);
737+
k_sem_init(&sem_prio_recv, 0, K_SEM_MAX_LIMIT);
738+
737739
err = ll_init(&sem_prio_recv);
738740
if (err) {
739741
BT_ERR("LL initialization failed: %d", err);
740742
return err;
741743
}
742744

743745
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)
746+
k_poll_signal_init(&hbuf_signal);
744747
hci_init(&hbuf_signal);
745748
#else
746749
hci_init(NULL);
@@ -763,11 +766,26 @@ static int hci_driver_open(void)
763766
return 0;
764767
}
765768

769+
static int hci_driver_close(void)
770+
{
771+
/* Resetting the LL stops all roles */
772+
ll_deinit();
773+
774+
/* Abort prio RX thread */
775+
k_thread_abort(&prio_recv_thread_data);
776+
777+
/* Abort RX thread */
778+
k_thread_abort(&recv_thread_data);
779+
780+
return 0;
781+
}
782+
766783
static const struct bt_hci_driver drv = {
767784
.name = "Controller",
768785
.bus = BT_HCI_DRIVER_BUS_VIRTUAL,
769786
.quirks = BT_QUIRK_NO_AUTO_DLE,
770787
.open = hci_driver_open,
788+
.close = hci_driver_close,
771789
.send = hci_driver_send,
772790
};
773791

0 commit comments

Comments
 (0)