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

Priority of SWI0 (app_timer) and sd_app_evt_wait

I am attempting to wake up every 250ms using an app timer to manage some background tasks and update our BLE advertising manufacturer data if needed. However, once we enter power_manage(); and execute sd_app_evt_wait(); we no longer get SWI0 interrupts, unless a BLE event occurs. Is this because the SWI0 interrupt is too low of a priority to wake the MCU? Can this be changed to a higher priority? Is there a better way to accomplish this task than app_timer?

int main(void) {
  // Startup Delay: 0.1s
  nrf_delay_ms(100);
  // Initialize
  watchdog_init();
  ble_stack_init();  // Initialize SoftDevice here
  ble_vendor_uuids();
  timers_init();

	// Initialize persistent storage module.
  uint32_t err_code = pstorage_init();
  APP_ERROR_CHECK(err_code);

  gap_params_init();
  advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE);
  services_init();   // Create and start 250ms repeated timer here
  conn_params_init();
  sec_params_init();
  advertising_start();
  // Enter main loop
  for (;;)
  {
    power_manage();
    // Feed Watchdog
    NRF_WDT->RR[0] = WDT_RR_RR_Reload;
  }}
  • Any application interrupt happening after calling sd_app_evt_wait() should wake the MCU. Priority has no role (AFAIK) in wake up mechanism.

    When is SWI0 interrupt triggered? How does your application know if the interrupt did not occur? Because your for loop has no conditions, so if the interrupt occurred, it will wake the system, run SWI0 interrupt handler and return to the for loop and sleep again.

  • SWI0 should be triggered in timer_timeouts_check() in RTC1_IRQHandler(). The SWI0 interrupt should be calling the function specified when I created the app_timer inside services_init(). It does a few times until I enter sd_app_evt_wait().

    The oscillator is configured in SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false) inside ble_stack_init().

    Is the RTC or app_timer somehow being disabled or not fully configured before sd_app_evt_wait()?

  • you said that SWI0 interrupt should be called in RTC1_IRQHAndler() I am guessing that you pend SWI0 interrupt using nvic_setpending function inside RTC1 interrupt handler. This means that when setting SWI0 interrupt to pend, the device is not sleeping. Oh god, i am making a lot of guesses here about your code and it does not make sense to me. Can you please post your code where you trigger the SWI0 interrupt

Related