Wouter van Ooijen wrote: >>> I would not even call it cooperative multitasking, because you can't >>> call schedule-next-task from within a called subroutine. >> >> That's partially correct; it is possible if you extend the state >> machine concept into the called subroutine and consider the subroutine >> state in the calling main task (like through a "done" flag). In >> essence, everywhere you want to be able to yield you have a state >> machine (even if it's degenerated into two states). > > The point is that on 12 and 14 bit core PICs you can't access that part > of the state (the content of the stack). So you are restricted to > "yielding" from the main. No. I might not have made myself clear... Maybe like this: main() { while( 1 ) { taskA(); taskB(); // ... } } taskA() { static state; switch( state ) { case 1: if( sub1() ) state = 2; break; case 2: // ... } return; } bool sub1() { static state; bool done = 0; switch( state ) { case 1: // ... case 15: done = 1; state = 1; break; } return done; } sub1 can yield through taskA. Of course a few prerequisites must be fulfilled for that to work, but it's not impossible. (Lurkers: Please don't pick on the code; it's not complete, it's not meant to be a working example, and so on... It's just meant to illustrate how /in principle/ a called subroutine can yield, albeit through the main level task.) Of course, if you consider that in this case it's not sub1 that yields but instead taskA that yields (because instructed to that effect by sub1), then we are in agreement :) Gerhard -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist