What is Super Loop in Embedded C programming language?
This refers to the eternal loop usually located in main()
of a "bare metal" system (no OS), since such systems can never return from main. A typical bare metal embedded system looks like this:
void main (void)
{
// various initializations
for(;;) // "super loop" or "main loop"
{
// do stuff
}
}
MCU is device which runs continuously or better, it executes instructions when power is on (in general).
So while loop is here to force MCU to do something, even if loop is empty, it will just circle around.
But it must do something as it is not the same as PC program where you have return
at the end of main function.
If you wouldn't have super loop then MCU can get instruction from FLASH/RAM (whatever..) and do something stupid things as MCU don't know what it is executing. It just executes code you provide him.
By using super loop, you guarantee MCU won't just uncontrollable execute some instructions and maybe go to fail-safe area. Of course this can happen even if you have super loop but this is other topic.
int main() {
//Init if you have something
while (1) {
//DO stuff always
}
return 0; //This should never happen!
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With