Using MBED OS Power Management API's in the absence of applications built without MBED OS RTOS?

I was wondering if you are building an MBED OS application that doesn’t use the RTOS and in which case you don’t have access to idle_hook function, should the application call the Power Management API directly or is there a better way to do this or does MBED OS Support going to sleep automatically when RTOS is not used as well? Also Is this true for BAREMETAL based Applications as well, which does not include RTOS by default?

FYI this is for an application using Cordio BLE Platform built for NRF52840_DK and also on MBED OS 5.15.5.

Thanks,
Ajay

@vcoubard, @Kojto any thoughts on this question?

In the baremetal case, an app should create own idle management (when there is nothing to do, execute this function):

  • set-up wake up call (periodic or on event)
  • call sleep() function

Thanks @Kojto for taking the time to respond. I was wondering in the baremetal case and in the case where it’s not a baremetal based project and not using the RTOS, what is the best way to detect there is nothing to do.

In our example we have a timer that goes on every minute to read some serial data from a sensor and we also have a BLE Sensor which sends data every 30 seconds. So the application without the RTOS would be woken up every 30 seconds at the least. Is there a way to detect in the non RTOS Scenario how to detect the processor is idle and then go to sleep for say 30 seconds?

Thanks,
Ajay

@Kojto any thoughts? We are trying to decide we want to go with the approach of not using the RTOS and use the nano lib to reduce the overall size of our binary. Any thoughts on how we can manage when the sleep needs to be triggered in the absence of RTOS?

Thanks,
Ajay

I assume you have main() or a function somewhere in the app that loops (while(1) or similar) always. this is the place where I would add sleep().

The idea there: check if there is anything to do (process any data that were handled in the interrupts since the last sleep). Do any outstanding work, if there is nothing, go to sleep.

pseudocode:

while(1) {
process_adc_measurement();
run_filtering();
update_user_data();
// if I got here, we got all processed
sleep();
}

Thanks @Kojto again for taking the time to respond to my queries and providing suggestions. I do have a main method however since this a Cordio BLE based application, it uses the MBED Event queue and the event queue is processing incoming BLE messages by calling the event queue’s dispatch forever method. However I see your point and I will try and figure a method to go to sleep when there is nothing to process in the main event queue.

Thanks,
Ajay

@Kojto I just realized there is no method available to figure out that the event queue has no immediate events left to be processed and so the application can go to sleep.

Is there a way to figure out if an application is using the event queue and using the dispatch forever method to dispatch events in the loop continuously to go to sleep when there is nothing to process in a non rtos scenario?

Thanks,
Ajay