Pages: [1]   Go Down
Author Topic: Never returning for loop()?  (Read 967 times)
0 Members and 1 Guest are viewing this topic.
Corona De Tucson
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Car Hacker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

New to Arduino, but pretty experienced coder.  The idea of the Arduino calling loop() repeatedly looks a lot like cooperative multitasking (ala Win3.1 and early MacOS).  So my question is this: if loop() calls a function that never returns, what do I lose?  I assume there is some housekeeping going in the "background". For example:

void setup(){
   // some stuff
}

void loop(){
   goawayforever();
}

void goawayforever(){
   while(1){
     //do some stuff;
   }
}


I have looked for the source code that runs in the Arduino but have been stymied.  

Craig
Logged

Central Europe
Offline Offline
Edison Member
*
Karma: 7
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Craig,

your thoughts are too complicated, it's far more primitive than that. Look into arduino/hardware/arduino/cores/arduino/main.cpp and you'll see this:
Code:
int main(void)
{
        init();
        setup();
        for (;;)
                loop();
        return 0;
}

This should answer all your questions.

Korman
« Last Edit: September 25, 2010, 09:32:01 am by Korman » Logged

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, it would not need co-operative multitasking (which is not so difficult on theArduino), but pre-emptive multitasking.

However there is an implementation of a FreeRTOS (DuinOS)
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1256745982/150
Logged

Corona De Tucson
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Car Hacker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@Korman,
    Indeed, I was overthinking...thanks for the concise answer!

Logged

Essex, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 150
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The only stuff going on in the background is the interrupt service routine that keeps track of clock ticks. You can see that in wiring.c. Everything else that happens is because you made it so, whether you meant to or not  smiley-wink
Logged

Home of the Nokia QVGA TFT LCD hacks: http://andybrown.me.uk

Pages: [1]   Go Up
Jump to: