We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am programming a simple full pre-emptive RTOS. It needs context switch. For saving contexts, is it enough to save all registers and CPSR? if tasks have local variables, and the complier uses memories to store them. If just saving registers, it seems not enough. What should I do?
thank you for your help!!!
The main important thing besides saving/restoring flags and processor registers is to switch stack.
Then you have to figure out if any functions used are non-reentrant, because they are using global variables or are playing with hardware.
There are a large number of gotchas with a RTOS, and you will have to decide how much cooperation that should be required by the tasks.
A good start if you want to write your own OS is to look at MicroC/OS-II: www.micrium.com/.../bookstore.html
Thank you for your reply.
I am using GNU C complier. Besides saving/restoring registers and stack switches, how about the local variables? If one task is preempted by another task, the first task has several local variables, how to save them if the complier complie them by using memory. if the second task also has local variables, the complier maybe use the same memories to store them. then there will be crashes.
Local variables stay on the stack unless you defined them as static. Therefore you should not have any static variables in a function.
The stack and the registors are saved by the OS and restored by the OS.
Get a copy of the book and read it. Code is written in 'c' You can also (at least you use to be able to) download the source from there web. They have ports for difference uP's. You should be able to use the source as a starting point.
Look at the license agreement.