In either of
loop, if I were to add an
exit(0) call, where would control be passed to? What would the next state of the microcontroller be? Would it stop execution and power down?
I am using a revision 2 Arduino Uno.
My initial guess is wrong. I would have thought it would simply return from loop and the core library would just call loop() again. However, I see the following code was created. Noticing that __stop_program is a hard loop...
An extract of Blink.ino's listing, with exit(0) added:
The disassembly of the above:
Note that if _exit had not called cli, interrupts would be able to do stuff. But that is not the case.
Well I just tested it with my Arduino Uno and it just completely stopped the code and left all the outputs as they were when the code stopped running (so it left an LED I had on on). There seems to not be a IO cleanup when you call exit. This was what I expected because the Arduino IDE provides the setup and loop functions, if you program the ATMEGA*28 with with any other AVR IDE you start with the main function like all C/C++ programs. The setup and loop functions are not standard on AVR MCU's.
Note: The press of the reset button restarts the code, if you were wondering.