adarkar9 wrote on Friday, September 21, 2007:
> …the pxCurrentTCB may need to be saved/restored…
Won’t the value of pxCurrentTCB always be the same for any one task? After all, it is the current TCB while that task is running. Only vTaskSwitchContext() should change the value of pxCurrentTCB and this is only in a very well controlled manner.
> It isn’t clear to me how the SDCC 8051 port handles Critical Nesting…I guess some CISC ‘magic’…
No magic here. Let me explain. Here is the code for entering a critical section:
#define portENTER_CRITICAL() _asm
EA = 0;
The SDCC port pushes the interrupt enable (IE) register on the stack every time portENTER_CRITICAL() is called (and the accumulator, you’ll see why in a bit). Then it clears the global interrupt enable bit (EA). Each nesting will get two more bytes pushed on the stack (and get interrupt disabled again).
Now, here is the code for exiting a critical section:
#define portEXIT_CRITICAL() _asm
ACC &= 0x80;
IE |= ACC;
The saved value of IE is poped into ACC, all the bits except EA are masked off, and the result is OR’ed into IE. Because only the first call to portENTER_CRITICAL() will have had EA set, only the corresponding call to portEXIT_CRITICAL() that pops off that first copy of IE will actually result in EA being set. This method is nice because it does not require a per task count, but it could end up using more stack space if you next your critical section deeply.
I started with the SDCC port. I got it running on my target hardware and verified correct operation before I ported it to Keil’s C51. It worked fine “as-is”.
I only changed to the critical nesting count because the C51’s inline assembly support is, uh, less than perfect.
> [SDCC] also uses its almost magical stack frame pointer…
I am no SDCC expert, but I did not come across any discussion of a stack frame pointer during my brief foray. I don’t believe the SDCC port uses this feature.
> …post your port.c, [etc.]
I have been waiting for the development effort to settle down a bit before doing this, but I haven’t touched the RTOS files for quite a while. I’ll send my port to Richard.