/* Function for waiting for events. 
This function will place the chip in low power mode while waiting for events from the SoftDevice or other peripherals. When interrupted by an event, it will call the app_sched_execute function to process the received event. This function will return when the final state of the firmware update is reached OR when a tear down is in progress.  */
static void wait_for_events(void)
/* Function for waiting for events. 
This function will place the chip in low power mode while waiting for events from the SoftDevice or other peripherals. When interrupted by an event, it will call the app_sched_execute function to process the received event. This function will return when the final state of the firmware update is reached OR when a tear down is in progress.  */
static void wait_for_events(void)
{
    for (;;)
    {
        uint32_t err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
        app_sched_execute();
        if ((m_update_status == BOOTLOADER_COMPLETE) ||
            (m_update_status == BOOTLOADER_TIMEOUT)  ||
            (m_update_status == BOOTLOADER_RESET))
        {
            return;
        }
    }
}