Archive for August 2010
A client of mine asked that I write a simple co-operative timesharing engine to be used in an embedded project. Timesharing is quite an easy multitasking system and is frequently used in the embedded space because each process must willingly give up cpu control. This is good if you have a critical task that must not be interrupted before it completes. Modern, more powerful cpus have the ability to turn off interrupts during execution (the instructions are sti and cli in the x86 world) but not all processors support this.
Because I cannot be guaranteed that the microcontroller that i’m using has this, i opted to use a software interrupt that i call “swi”. Realistically, you can turn this into a preemptive multitasking system by assigning the programmable interrupt to my “swi” function and have it execute at a pre-determined time.
anyway, i also wanted this to be somewhat compliant with normal POSIX programming, so I created a “fork” function.
It uses “setjmp” and “longjmp” to create save points in the “swi” and then call the next call on the process stack. I was going to include a simple prioritizing system, but really it didn’t require it – i might still.
Anyway, the source is posted in my source code area.