rtel wrote on Tuesday, March 22, 2005:
>If I need to store the nesting depth counter, do I still
>need to store the Enable interrupt bit? If this is so, is
>that the nesting depth counter need to keep checking
>if 0 , then restore the EA bit during context
I don’t quite follow your question, but will try to answer it.
In the 8051 port a yield is performed by simply calling the vPortYield() function. In other ports a software interrupt is used.
When a software interrupt is used the status registers are saved to the stack by the processor, so the save/restore context functions do not have to explicitly save/restore the interrupt status flags.
When a function is used (as in the 8051 port) the status registers are not automatically saved to the stack by the processor, so the save/restore context functions must do this explicitly - even when you are saving the nesting depth counter. When the context is restored the interrupt flag is set back to the same value it was when the context was saved. The nesting counter is also restored so the kernel knows how many times EXIT_CRITICAL() has to be called before interrupts can be enabled (assuming they are disabled).
>For 8051 port, it is known that XRAM is required for
>context switching. Thus, if NAKE function is not
>supported in Keil, do I need to impement this COPY
>XRAM to STACK / COPY STACK to XRAM to ASM
>macro? As if I do that by function call, seems that
>would corrupt the stack’s content.
Again, don’t quite follow the question but I will try to answer …
If Naked cannot be used then the entry to the yield functions might have to be written in an asm file. An asm file is used to prevent the compiler generating any function entry code - as this will corrupt the stack.
In the asm file, the first thing that should be done is to save the context and copy it to XRAM. Therefore the context is immediately saved onto the stack before the stack is modified in any other way.
Once the context has been saved the C function can be called. Now it does not matter if the stack is modified as the context is already saved.
After the C function has returned, the stack will be back to it’s original state. The stack can be copied back from XRAM and the restore context macro can now be called (both from the asm file) to restore the stack of the task immediately prior to returning to the task.
It is a pain if the compiler does not support __naked as I prefer to avoid asm code whenever possible! (some compilers call this __task, have you checked to see if this is available?).
Hope this helps.