It's pretty uncommon for a microcontroller app to terminate. I think
it's architecture-dependent, but I could imagine some micros just
resetting back to the beginning after main() executes, so you still
have an implicit busy loop, it just executes main() over and over
As long as the chip is running and awake it will be pulling
instructions and executing them, so having a busy loop doesn't burn
any more cycles. The only way to stop it from executing is to
explicitly put the chip to sleep (and set it up to wake up an external
interrupt. The general architecture would be:
hw_init(); /* make sure it's configured to wake up on an external
So when goToSleep() runs, the chip goes to sleep immediately. Then
every time the external interrupt hits, it executes the ISR, then
passes control back to the main loop and executes handleWakeupStuff().
If you're just toggling output pins then you can do that from the ISR,
but if you want to do anything that takes a little longer it's good
practice to defer the work to the main loop and keep the ISR fast.