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

Is it bad to exit the main 'for(;;) loop when application is done?

The application I am designing gets a pulse ox measurement from the user, sends it, disconnects, and shuts off. Are there any deleterious side effects of exiting the main for(;;) loop present in almost all of the examples?  I want to disconnect from the peer, disable soft device, write data to flash if needed, and exit. The disabling of soft device will cause a fatal error when sd_app_evt_wait() is called so I definitely do not want to make that call and I don't want to skip it either as the loop will just burn battery calories. There is no reason to re-initialize SoftDevice as the device will not run again.

So can I do something like this with no unforeseen consequences in the main loop?

        sd_softdevice_is_enabled(&enabled); // Don't do this if disabled, for example when writing flash at the end
        if (enabled != 1)
        {
            #if (USE_DK == 1)
            NRF_LOG_DEBUG("Exiting application%u\r\n");
            #endif
            while(NRF_LOG_PROCESS());
            return;
        }

I suppose I should add what do I need to clean up if I should do this?

Related