From 708d3b30ea290fb616d8901659542e272f6a01ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Rymanowski?= Date: Fri, 26 Jul 2019 10:47:42 +0200 Subject: [PATCH] nimble/ll: Fix restarting RX on wfr while scanning With this patch we move restarting RX on wfr while scanning to interrupt context instead of LL context. It is because we want to restart RX as fast as possible while scanning. Also previous ble_phy_restart_rx call in LL context during interrupts enabled was incorrect. --- nimble/controller/src/ble_ll_scan.c | 39 +++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c index 4fcdc6265..3e3f0a161 100644 --- a/nimble/controller/src/ble_ll_scan.c +++ b/nimble/controller/src/ble_ll_scan.c @@ -1392,7 +1392,6 @@ ble_ll_scan_interrupted_event_cb(struct ble_npl_event *ev) } ble_ll_scan_chk_resume(); - ble_phy_restart_rx(); } /** @@ -2512,9 +2511,45 @@ void ble_ll_scan_wfr_timer_exp(void) { struct ble_ll_scan_sm *scansm; + uint8_t chan; + int phy; + int rc; +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) + uint8_t phy_mode; +#endif scansm = &g_ble_ll_scan_sm; - ble_ll_scan_interrupted(scansm); + if (scansm->cur_aux_data) { + /* We actually care about interrupted scan only for EXT ADV because only + * then we might consider to send truncated event to the host. + */ + ble_ll_scan_interrupted(scansm); + + /* Need to disable phy since we are going to move to BLE_LL_STATE_STANDBY + * or we will need to change channel to primary one + */ + ble_phy_disable(); + + if (ble_ll_scan_window_chk(scansm, os_cputime_get32()) == 1) { + /* Outside the window scan */ + ble_ll_state_set(BLE_LL_STATE_STANDBY); + return; + } + + ble_ll_get_chan_to_scan(scansm, &chan, &phy); +#if (BLE_LL_BT5_PHY_SUPPORTED == 1) + phy_mode = ble_ll_phy_to_phy_mode(phy, BLE_HCI_LE_PHY_CODED_ANY); + ble_phy_mode_set(phy_mode, phy_mode); +#endif + rc = ble_phy_setchan(chan, BLE_ACCESS_ADDR_ADV, BLE_LL_CRCINIT_ADV); + BLE_LL_ASSERT(rc == 0); + } + + if (scansm->scan_rsp_pending) { + ble_ll_scan_req_backoff(scansm, 0); + } + + ble_phy_restart_rx(); } #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)