nimble/ll: Fix race condition

This patch fixes race condition when g_ble_ll_data.ll_rfclk_state
is out of sync with nrf52_clock_hfxo_refcnt in nrf52_clock.c

It could happen when HCI Reset has been done while scanning/advertising
etc.

This patch also adds OS_ASSERT_CRITICAL() in places where ll_rfclk_state
is changed.
This commit is contained in:
Łukasz Rymanowski
2019-02-22 21:02:16 +01:00
parent e665d203e9
commit 9a9bac14a3
2 changed files with 5 additions and 0 deletions
+2
View File
@@ -1303,8 +1303,10 @@ ble_ll_reset(void)
ble_ll_state_set(BLE_LL_STATE_STANDBY);
#ifdef BLE_XCVR_RFCLK
OS_ENTER_CRITICAL(sr);
/* Stops rf clock and rfclock timer */
ble_ll_xcvr_rfclk_stop();
OS_EXIT_CRITICAL(sr);
#endif
/* Reset our random address */
+3
View File
@@ -33,6 +33,7 @@ ble_ll_xcvr_rfclk_state(void)
{
uint32_t expiry;
OS_ASSERT_CRITICAL();
if (g_ble_ll_data.ll_rfclk_state == BLE_RFCLK_STATE_ON) {
expiry = g_ble_ll_data.ll_rfclk_start_time;
if ((int32_t)(os_cputime_get32() - expiry) >
@@ -46,6 +47,7 @@ ble_ll_xcvr_rfclk_state(void)
void
ble_ll_xcvr_rfclk_enable(void)
{
OS_ASSERT_CRITICAL();
if (g_ble_ll_data.ll_rfclk_state == BLE_RFCLK_STATE_OFF) {
g_ble_ll_data.ll_rfclk_state = BLE_RFCLK_STATE_ON;
ble_phy_rfclk_enable();
@@ -55,6 +57,7 @@ ble_ll_xcvr_rfclk_enable(void)
void
ble_ll_xcvr_rfclk_disable(void)
{
OS_ASSERT_CRITICAL();
if (g_ble_ll_data.ll_rfclk_state != BLE_RFCLK_STATE_OFF) {
ble_phy_rfclk_disable();
g_ble_ll_data.ll_rfclk_state = BLE_RFCLK_STATE_OFF;