Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "Super Loop" in Embedded C programming language?

Tags:

c

loops

embedded

What is Super Loop in Embedded C programming language?

like image 291
Jayesh Avatar asked Nov 28 '22 22:11

Jayesh


2 Answers

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
  }
}
like image 69
Lundin Avatar answered Dec 01 '22 10:12

Lundin


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!
}
like image 37
tilz0R Avatar answered Dec 01 '22 10:12

tilz0R