OSIntCtxSw()
is called from OSIntExit()
to perform a context switch when all nested interrupts have returned.
Interrupts are disabled when OSIntCtxSw()
is called.
OSTCBCurPtr
points at the OS_TCB
of the task that is switched out when OSIntCtxSw()
is called and OSIntExit()
sets OSTCBHighRdyPtr
to point at the OS_TCB
of the task that is switched in.
os.h/os_cpu_a.asm
void OSIntCtxSw (void) |
None
None
None
OSIntExit()
.
None
The pseudocode for OSIntCtxSw()
is shown below. Notice that the code does only half of what OSCtxSw()
did. The reason is that OSIntCtxSw()
is called from an ISR and it is assumed that all of the CPU registers of the interrupted task were saved at the beginning of the ISR. OSIntCtxSw()
therefore must only restore the context of the new, high-priority task.
void OSIntCtxSw (void) { OSTaskSwHook(); (1) OSPrioCur = OSPrioHighRdy; (2) OSTCBCurPtr = OSTCBHighRdyPtr; (3) SP = OSTCBHighRdyPtr->StkPtr; (4) Restore all CPU registers; (5) Return from interrupt; (6) } |
(1) (2) (3) (4) The stack pointer of the new task is restored from the (5) All the CPU registers need to be restored from the new task’s stack. (6) A return from interrupt instruction must be executed. |