请教ucosii移植到stm32问题, 切换任务后如何从中断返回
我看到移植好的代码中这么写的,有两个不明白的地方,请教大家一下OS_CPU_PendSVHandler
CPSID I ; Prevent interruption during context switch
MRS R0, PSP ; PSP is process stack pointer
CBZ R0, OS_CPU_PendSVHandler_nosave ; Skip register save the first time
SUBS R0, R0, #0x20 ; Save remaining regs r4-11 on process stack
STM R0, {R4-R11}
LDR R1, =OSTCBCur ; OSTCBCur->OSTCBStkPtr = SP;
LDR R1,
STR R0, ; R0 is SP of process being switched out
; At this point, entire context of process has been saved
OS_CPU_PendSVHandler_nosave
PUSH {R14} ; Save LR exc_return value
LDR R0, =OSTaskSwHook ; OSTaskSwHook();
BLX R0
POP {R14}
LDR R0, =OSPrioCur ; OSPrioCur = OSPrioHighRdy;
LDR R1, =OSPrioHighRdy
LDRB R2,
STRB R2,
LDR R0, =OSTCBCur ; OSTCBCur= OSTCBHighRdy;
LDR R1, =OSTCBHighRdy
LDR R2,
STR R2,
LDR R0, ; R0 is new process SP; SP = OSTCBHighRdy->OSTCBStkPtr;
LDM R0, {R4-R11} ; Restore r4-11 from new process stack
ADDS R0, R0, #0x20
MSR PSP, R0 ; Load PSP with new process SP
ORR LR, LR, #0x04 ; Ensure exception return uses process stack
CPSIE I
BX LR ; Exception return will restore remaining context
END
对lr使用不是很理解,如果在任务1执行中被systick中断进入调度,那么lr应该是任务1的lr,如果在中断处理函数中调度任务2执行,那么最后第二行的那个lr是哪个数值呢?我理解应该是任务1被中断的时候的lr。
任务1被systick中断的时候,默认寄存器会放到psp中吧,等到进入上面那个函数后,再次保存的r4 - r11 是放在msp中吗?
还有一个问题,在cpsie i和bx lr之间如果发生其他高于systic的中断,还能顺利切换到任务2吗?
thx all
页:
[1]