solarwind wrote: > Let's say I have two tasks like this: > > void task1() { > while(true) { > do stuff; > if(case) > yield(); > } > } > > void task2() { > while(true) { > do other stuff; > if(case) > yield(); > } > } > > Is it possible to switch the tasks every x milliseconds (for example, > 50 ms) in a way that the context is saved? To switch based on time you need a preemptive system. That's a lot more complicated, and in this case unnecessary. All you need is a cooperative system where tasks explicitly have to give up the processor. Did you read my other post about this from yesterday? I even showed you source code to implement a simple task scheduler (I wouldn't go so far as calling it a RTOS). It will support exactly what you are trying to do in the example above, except that I called it TASK_YIELD instead of YIELD. > Note that neither of these tasks return, Right. That's why they're tasks. A task is a single thread of execution. Since PICs only have one execution unit, each task runs on its own virtualized processor. This is done by letting each task run in turn on the real processor for short periods. > but if > a certain case exists (like no data in the RX buffer, for example), > the task will yield and let the other task do its thing (is this how > it's supposed to work)? I discussed this in a post yesterday already. Go back and read it. ******************************************************************** Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products (978) 742-9014. Gold level PIC consultants since 2000. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist