??? 07/09/10 08:33 Read: times |
#177169 - co-operative scheduler |
I have been using the "Time Triggered Prioritised Cooperative Scheduler" from 8052.com, which suits the 8051 well.
Now I have come across a problem in that the idea of a co-operative system needs all tasks to complete before the scheduler runs again. This inevitably wastes processing time. 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. Additionally, now display is a problem in this application. Display is important, but the machine control is more important. Display takes a lot of time. 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 |