This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

sd_app_evt_wait() for power management

Hi my goal is to put the NRF into system on low power mode every other second. I have a repeated app_timer that increments counter variable m_custom_value every second. I thought of two possible ways to do this by calling sd_app_evt_wait() if/while m_custom_value % 2 == 0. 

1. I was wondering if there is any difference if I use an if statement vs while loop to call sd_app_evt_wait(). If I use an if statement then sd_app_evt_wait() is only called once every other second, but if I use a while loop then sd_app_evt_wait() is called continuously for the duration of one second (or approximately one second), every other second. Will using a while loop just interrupt the NRF CPU from sleep or is there no difference between calling sd_app_evt_wait() once or calling sd_app_evt_wait() continuously for the duration where I want the NRF CPU to be sleeping? 

2. Do I need to make sure the NRF is done advertising or force the NRF to stop advertising before calling sd_app_evt_wait() if I want the NRF CPU to go to system on low power mode?

I noticed that if I start BLE advertising then call sd_app_evt_wait() the NRF DK will continue advertising until the advertising timeout or idle power-management code is called. So my current assumption is that if BLE advertising is still active when sd_app_evt_wait() is called, then the NRF CPU will not go to sleep and the active BLE advertising will continue draining significant power. 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define NOTIFICATION_INTERVAL APP_TIMER_TICKS(1000)
APP_TIMER_DEF(m_busy_wait_timer_id);
static uint8_t m_custom_value = 0;
static void notification_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
ret_code_t err_code;
// Increment the value of m_custom_value before notifying it.
m_custom_value++;
}
static void timers_init(void)
{
// Initialize timer module.
ret_code_t err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
app_timer_create(&m_notification_timer_id, APP_TIMER_MODE_REPEATED, notification_timeout_handler);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX