__asm void xPortPendSVHandler( void )
{ //中断发生的瞬间硬件已经保存了部分寄存器,具体如下图1所示
extern uxCriticalNesting;
extern pxCurrentTCB;
extern vTaskSwitchContext;
PRESERVE8
mrs r0, psp
isb
ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */
ldr r2, [r3]
stmdb r0!, {r4-r11} /* Save the remaining registers. */
str r0, [r2] /* Save the new top of stack into the first member of the TCB. */
/* 到这里已经保存完原任务的现场 */
stmdb sp!, {r3, r14}
mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY
msr basepri, r0 //关闭freertos中断
dsb
isb
bl vTaskSwitchContext //找出下一个任务
mov r0, #0
msr basepri, r0 //使能freertos中断
ldmia sp!, {r3, r14}
ldr r1, [r3]
ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */
ldmia r0!, {r4-r11} /* Pop the registers and the critical nesting count. */
msr psp, r0
isb
bx r14 //触发异常,恢复硬件保存的寄存器值,并跳转到所保存的返回地址处的代码
nop
}