What is “Super Loop” in Embedded C programming lan

2019-05-25 01:34发布

What is Super Loop in Embedded C programming language?

标签: c loops embedded
3条回答
▲ chillily
2楼-- · 2019-05-25 01:36

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
  }
}
查看更多
Juvenile、少年°
3楼-- · 2019-05-25 01:46

Super loop is an infinite loop which is suitable only in embedded c programming because there you have to run your code for very very long time and wants explicitly terminate when the behavior is change for your robot or whatever. Superloop be like

while(1){

// Your code

// exit condition

}

for(;;) {

}
查看更多
ら.Afraid
4楼-- · 2019-05-25 01:52

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!
}
查看更多
登录 后发表回答