On Thu, May 21, 2009 at 7:49 AM, Wouter van Ooijen wrote: > > Perhaps something like this: > > > > movlw low ReturnPoint_xxx > > movwf TaskPC+0 > > movlw high ReturnPoint_xxx > > movwf TaskPC+1 > > bsf PIR1,TMR1IE > > ReturnPoint_xxx: > > bcf PIR1,TMR1IE > > > > Then spread this sequence all over your code (better if the compiler is > > aware of the RTOS and generate this automatically, like the CC5X does). > > Of course, don=B4t repeat the 'xxx' part. > > If you spread this yourself this is cooperative multitasking: you > explicitly allow switching at selected points. I would say it is somewhere in between. For example you have this task in pseudo code: void task ( ) { ... ... saveReentry(); while ( 1 ) { ... ... ... ... } } Inside the while there is no trade off, you can make a tight loop or whatever you want. If the scheduler suspends the task in the middle of the loop then it can only continue from the while(1). But sometimes it is ok. If you have something that should not be interrupted then you can still use the good old crtitical section tricks, like: void task ( ) { ... ... saveReentry(); while ( 1 ) { ... ... ... enterCriticalSection(); ... ... ... leaveCriticalSection(); ... ... } } So the scheduler can suspend only on the first 3 lines or the last 2. In a way you can even think it as an event driven rtos where the task was started at certain periods and running for a limited time frame only, however, take a look at a bit more complex example: void task ( ) { ... ... saveReentry(); while ( 1 ) { ... ... ... ... } saveReentry(); switch (...) { case 0: .... case 1: saveReentry(); while ( 1 ) { ... ... ... } break; case 2: .... } } So the task has more than one reentry point which created at different state of the task. It is looks like a cooperative, however, to save the reentry point takes less time than calling the scheduler and also inside the loop there is no need to do that so the code runs at native speed. I would not say that this is efficient or nice, however it could be better some cases than the simply cooperative mode where you might need to call the scheduler from inside the loop degrading its performance. Tamas -- = http://www.mcuhobby.com -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist