Description
OSCtxSw()
is called from the macro OS_TASK_SW()
, which in turn is called from OSSched()
to perform a task-level context switch. Interrupts are disabled when OSCtxSw()
is called.
Prior to calling OSCtxSw()
, OSTCBCurPtr
to point at the OS_TCB
of the task that is being switched out, and OSSched()
sets OSTCBHighRdyPtr
to point at the OS_TCB
of the task being switched in.
Files
os.h/os_cpu_a.asm
Prototype
Code Block |
---|
void OSCtxSw (void) |
Arguments
None
Returned Values
None
Required Configuration
None
Callers
OSSched()
.
Notes/Warnings
None
Example Usage
The pseudocode for OSCtxSw()
follows:
Code Block | ||
---|---|---|
| ||
void OSCtxSw (void)
{
Save all CPU registers; (1)
OSTCBCurPtr->StkPtr = SP; (2)
OSTaskSwHook(); (3)
OSPrioCur = OSPrioHighRdy; (4)
OSTCBCurPtr = OSTCBHighRdyPtr; (5)
SP = OSTCBHighRdyPtr->StkPtr; (6)
Restore all CPU registers; (7)
Return from interrupt; (8)
} |
Panel | ||
---|---|---|
| ||
(1) (2) The current task’s stack pointer is then saved into the current task’s (3) Next, (4) (5) (6) The stack pointer of the new task is restored from the (7) All the CPU registers from the new task’s stack are restored. (8) Finally, |