??? 07/09/10 08:46 Read: times |
#177170 - RE: This inevitably wastes processing time. Responding to: ???'s previous message |
Johan Smit said:
the idea of a co-operative system needs all tasks to complete before the scheduler runs again. This inevitably wastes processing time. Does it? I have been using a sparetime routine that runs at the end of the despatcher. This works well for eg., RS232.
It only needs to check that the remaining time is sufficient to send a character. This speeded up the comms tremendously. Are you using polled comms, then? I suggest to use a background routine for display running in register set 3. At startup, go to this routine and set the PSW to register set 3.
The compiler (I use uc51 from Wickenhaueser) will not use register set 3. Push the necessary A, B, PSW, DPTR on entry to the scheduler. Set psw to register set 0. Then at the end of the scheduler, do not simply reti. Instead, set dptr to the despatcher, push dpl,dph, then reti. This will cause the despatcher to run, servicing the tasks. At the end of the despatcher, pop dph, dpl, PSW, B, A. You are seamlessly back to the background task, which can run endlessly or go to sleep as required. At no time is any processing time wasted, and the additional cost is a few bytes on the stack. Please comment Johan Smit Are we talking Coroutines here? |