What is “Super Loop” in Embedded C programming language?

≯℡__Kan透↙ 提交于 2019-12-06 11:51:19

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!
}
Karthik Saxena

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(;;) {

}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!