Example #1
0
/* Absolutely need a naked function because function call push the return address on the stack */
void nOS_SwitchContext(void)
{
    PUSH_CONTEXT();
    nOS_runningThread->stackPtr = (uint8_t*)SP;
    nOS_runningThread = nOS_highPrioThread;
    SP = (int)nOS_highPrioThread->stackPtr;
    POP_CONTEXT();
    asm volatile("ret");
}
Example #2
0
void SWI_Handler (void)
{
    /* Within an IRQ ISR the link register has an offset from the true return
    address, but an SWI ISR does not.  Add the offset manually so the same
    ISR return code can be used in both cases. */
    __asm volatile ( "ADD   LR, LR, #4" );

    /* Perform the context switch.  First save the context of the current task. */
    PUSH_CONTEXT();

    nOS_runningThread = nOS_highPrioThread;

    /* Restore the context of the new task. */
    POP_CONTEXT();
}