Hi, I built my app on the ble_app_uart peripheral example. I am looking to replace nrf_delay_ms(ms); with a low power alternative, I figured a function with loop on power_manage(); and a one shot timer clearing a flag would do the job, and could just replace calling nrf_delay_ms(ms); but it doesnt work, there is no delay.
Any insight on what is wrong?
My delay function:
/** function for calling low power delay */
uint8_t nrf_le_delay_ms(int ms_delay)
{
#if DEBUG_EXTENDED_MESSAGES
NRF_LOG_INFO("waiting");
#endif
uint32_t err_code;
err_code = app_timer_start(m_le_delay, APP_TIMER_TICKS(ms_delay), NULL);
APP_ERROR_CHECK(err_code);
m_le_delay_flag = true;
while(m_le_delay_flag)
{
power_manage();
}
return 0;
}
timer:
/**
* @brief Handler for low-power delay timer
* @details this event is triggered when calling the delay-timer and has no other purpose than delaying the program
*/
static void timer_evt_leDelay(void * p_context){
#if DEBUG_EXTENDED_MESSAGES
NRF_LOG_INFO("timer_ledelay");
#endif
m_le_delay_flag = false;
}
Usage:
APP_TIMER_DEF(m_le_delay);
static volatile bool m_le_delay_flag = false; /**< Flag to indicate le delay is running. */
int main(void){
uint32_t err_code;
// ... Initializing variables, wdt, flash, GPIOTE, timer, softdevice, starting advertising,
err_code = app_timer_create(&m_le_delay, APP_TIMER_MODE_SINGLE_SHOT, timer_evt_leDelay);
APP_ERROR_CHECK(err_code);
// .. initializing display stuff and transfer over spi
nrf_le_delay_ms(1000); // Allow user to read init
for(;;)
{
...
}
}