icyphy / lf-buckler

Programming an nRF embedded board with a Berkeley Buckler daughter card using Lingua Franca.
BSD 2-Clause "Simplified" License
7 stars 0 forks source link

Busy wait vs. wait for interrupt #9

Closed edwardalee closed 2 years ago

edwardalee commented 2 years ago

The lf_nanosleep function in lf_nrf52_support.c busy waits. It would be far more energy efficient to wait for interrupt. If the event queue is empty, that is all it needs to do. Otherwise, if the requested wait interval is large enough, it should set up a timer interrupt for the time of the first event on the event queue. To perform a wait for interrupt on the Arm Cortex M4, just use the following line of code:

__WFI()