I'm looking for a tutorial that I can forward to some folks. I know of three different ways of implementing software.
In the first, you have just one real and virtual thread of control, and the software goes something like:
main() { // setup ... while(1) { do_this(); delay(a_while); do_that(); delay(a_while_longer); do_the_other_thing(); delay(even_more); } }
In the second, you're too cheap to buy an RTOS, but you want to have multiple virtual threads of control, so you use what I was taught to call a task loop and what most folks seem to call a state machine:
bool this_flag, that_flag, the_other_flag;
interrupt this_isr() {this_flag = true; /* cleanup */} interrupt that_isr() {that_flag = true; /* cleanup */} interrupt the_other_isr() {the_other_flag = true; /* cleanup */}
main() { // setup ... while (1) { if (this_flag) { do_this(); // resets this_flag } if (that_flag) { do_that(); // resets that_flag } if (the_other_flag) { do_the_other_thing(): // resets the_other_flag } } }
In the third, you spring for an RTOS. Technically you still only have virtual threads of control (since your processor can't really run two pieces of code at once), but you use semiphores and what not to create the same effect.
My question is: Does anyone know a good tutorial that covers all of this, or at least techniques for implementing the task loop/state machine method?
Thanks.