-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BLE cannot restart advertising when it is asleep. #2155
Conversation
hal/src/nRF52840/sleep_hal.cpp
Outdated
@@ -379,6 +387,10 @@ static void fpu_sleep_prepare(void) { | |||
SPARK_ASSERT((fpscr & 0x07) == 0); | |||
} | |||
|
|||
#ifdef DEBUG_BUILD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is here only for going through this function more easily with a debugger. Let's remove it.
hal/src/nRF52840/sleep_hal.cpp
Outdated
@@ -590,6 +602,22 @@ static int enterStopBasedSleep(const hal_sleep_config_t* config, hal_wakeup_sour | |||
// we are still under the effect of HAL_disable_irq that masked all but SoftDevice interrupts using BASEPRI | |||
__enable_irq(); | |||
|
|||
/* | |||
* SD_EVT_IRQn is set pending after __enable_irq() and SoftDevice interrupts being executed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's reword this, I had to read it multiple times and ask additional questions to understand how this works:
Wake-up on BLE events relies mainly on SD_EVT_IRQn
interrupt, which will be disabled through NVIC (not masked) when entering sd_nvic_critical_region_enter()
. Normally on BLE activity we would be woken up by other high-priority SoftDevice interrupts (e.g. timers, radio events etc), however SD_EVT_IRQn
would be set as pending only after we unmask high-priority SoftDevice interrupts (__enable_irq()
) and after the appropriate SoftDevice interrupt handlers finish executing. We would then immediately go back to sleep and wouldn't notice this change in SD_EVT_IRQn
state. As a workaround, for the duration of the sleep, we'll be bumping the priority of SD_EVT_IRQn
, so that it can wake us up from stop mode (WFI
) as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, I think it might be viable to simply move pending IRQ checks under __enable_irq()
.
…ice when device is asleep.
5a422bc
to
004dcd7
Compare
Problem
BLE cannot restart advertising when disconnected by peer device if sleep mode is enabled
Steps to Test
Example App
Completeness