If I receive data on the UART that comes in via its event handler, how can I then create an event to wake up from sd_app_event_wait and do further processing from the application main loop?
If I receive data on the UART that comes in via its event handler, how can I then create an event to wake up from sd_app_event_wait and do further processing from the application main loop?
Any UART interrupt will bring the chip out of sd_app_event_wait(), running the interrupt handler which again calls the event handlers. However, when all interrupt handlers are finished, the chip will return to the main loop, which again will do a new call to sd_app_event_wait(), putting the chip back to sleep.
If you want to transfer execution out of the interrupt, you need to have some way of signaling the main loop. This can either be some kind of flag solution, or you can look into using the app_scheduler module, which gives you the possibility of posting an event from an interrupt handler or similar, which will then be handled from main context. There have been a couple of other discussions on the scheduler on Developer Zone, so I'd recommend you to have a look at some of the other questions.
Ole,
Thank you for your quick reply. I already posted a question about the scheduler as it was my first choice. However bonding does not seem to work when using the scheduler, see devzone.nordicsemi.com/.../bondmanager-and-scheduler
I hadn't seen that question, but I've just answered it. There shouldn't be any problems with bonding when using the scheduler, this is implemented in for example ble_app_hids_keyboard.
Thank you Ole for pointing to hids_keyboard. Am I correct that a bond_manaager event_handler is necessary when using the scheduler?