Skip to content

Commit 58ea18e

Browse files
yeaissakartben
authored andcommitted
bluetooth: hci_nxp: disallow standby usage while sending HCI MSG
Sending an HCI message requires to wake up the controller core if it's asleep. Platform controllers may send responses using non wakeable interrupts and those can be lost during standby usage. Blocking standby usage until the HCI message is sent. Signed-off-by: Yassine El Aissaoui <yassine.elaissaoui@nxp.com>
1 parent 7fbdc6d commit 58ea18e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

drivers/bluetooth/hci/hci_nxp.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <zephyr/drivers/flash.h>
1717
#include <zephyr/bluetooth/hci_types.h>
1818
#include <soc.h>
19+
#include <zephyr/pm/policy.h>
1920

2021
#include <fwk_platform_ble.h>
2122
#include <fwk_platform.h>
@@ -71,6 +72,12 @@ LOG_MODULE_REGISTER(bt_driver);
7172
#if !defined(CONFIG_BT_HCI_SET_PUBLIC_ADDR)
7273
#define bt_nxp_set_mac_address(public_addr) 0
7374
#endif
75+
76+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(standby), okay) && defined(CONFIG_PM) &&\
77+
defined(CONFIG_HCI_NXP_ENABLE_AUTO_SLEEP)
78+
#define HCI_NXP_LOCK_STANDBY_BEFORE_SEND
79+
#endif
80+
7481
/* -------------------------------------------------------------------------- */
7582
/* Public prototypes */
7683
/* -------------------------------------------------------------------------- */
@@ -413,7 +420,18 @@ static int bt_nxp_send(const struct device *dev, struct net_buf *buf)
413420
}
414421

415422
net_buf_push_u8(buf, packetType);
423+
#if defined(HCI_NXP_LOCK_STANDBY_BEFORE_SEND)
424+
/* Sending an HCI message requires to wake up the controller core if it's asleep.
425+
* Platform controllers may send reponses using non wakeable interrupts which can
426+
* be lost during standby usage.
427+
* Blocking standby usage until the HCI message is sent.
428+
*/
429+
pm_policy_state_lock_get(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
430+
#endif
416431
PLATFORM_SendHciMessage(buf->data, buf->len);
432+
#if defined(HCI_NXP_LOCK_STANDBY_BEFORE_SEND)
433+
pm_policy_state_lock_put(PM_STATE_STANDBY, PM_ALL_SUBSTATES);
434+
#endif
417435

418436
net_buf_unref(buf);
419437

0 commit comments

Comments
 (0)