@@ -515,7 +515,11 @@ static void bt_spi_rx_thread(void *p1, void *p2, void *p3)
515
515
while (true) {
516
516
517
517
/* Wait for interrupt pin to be active */
518
- k_sem_take (& sem_request , K_FOREVER );
518
+ ret = k_sem_take (& sem_request , K_FOREVER );
519
+ if (ret ) {
520
+ LOG_DBG ("Failed to take the semaphore. The RX thread exits." );
521
+ break ;
522
+ }
519
523
520
524
LOG_DBG ("" );
521
525
@@ -685,12 +689,39 @@ static int bt_spi_open(const struct device *dev, bt_hci_recv_t recv)
685
689
return 0 ;
686
690
}
687
691
692
+ static int bt_spi_close (const struct device * dev )
693
+ {
694
+ struct bt_spi_data * hci = dev -> data ;
695
+ int ret ;
696
+
697
+ gpio_pin_interrupt_configure_dt (& irq_gpio , GPIO_INT_DISABLE );
698
+
699
+ /* To exit the thread safely */
700
+ k_sem_reset (& sem_request );
701
+ ret = k_thread_join (& spi_rx_thread_data , K_MSEC (100 ));
702
+ if (ret ) {
703
+ LOG_DBG ("bt_spi_rx_thread is unable to exit" );
704
+ return ret ;
705
+ }
706
+
707
+ /* Reset the BLE controller */
708
+ gpio_pin_set_dt (& rst_gpio , 1 );
709
+ k_sleep (K_MSEC (DT_INST_PROP_OR (0 , reset_assert_duration_ms , 0 )));
710
+ gpio_pin_set_dt (& rst_gpio , 0 );
711
+
712
+ hci -> recv = NULL ;
713
+ LOG_DBG ("Bluetooth disabled" );
714
+
715
+ return 0 ;
716
+ }
717
+
688
718
static DEVICE_API (bt_hci , drv ) = {
689
719
#if defined(CONFIG_BT_BLUENRG_ACI ) && !defined(CONFIG_BT_HCI_RAW )
690
720
.setup = bt_spi_bluenrg_setup ,
691
721
#endif /* CONFIG_BT_BLUENRG_ACI && !CONFIG_BT_HCI_RAW */
692
722
.open = bt_spi_open ,
693
723
.send = bt_spi_send ,
724
+ .close = bt_spi_close ,
694
725
};
695
726
696
727
static int bt_spi_init (const struct device * dev )
0 commit comments