初级会员
- 积分
- 125
- 金钱
- 125
- 注册时间
- 2013-9-28
- 在线时间
- 17 小时
|
10金钱
有两个问题请教一下大神!!!
-->1
在ucos中的上下文切换时发生在pendSV异常中,代码见下:
PendSV_Handler
CPSID I ; Prevent interruption during context switch
MRS R0, PSP ; PSP is process stack pointer
CBZ R0, PendSV_Handler_nosave ;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, [R1]
STR R0, [R1] ; R0 is SP of process being switched out
; At this point, entire context of process has been saved
;OS_CPU_PendSVHandler_nosave
PendSV_Handler_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, [R1]
STRB R2, [R0]
LDR R0, =OSTCBCur ; OSTCBCur = OSTCBHighRdy;
LDR R1, =OSTCBHighRdy
LDR R2, [R1]
STR R2, [R0]
LDR R0, [R2] ; 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
问题:假如在任务A的某处发生了pendSV异常,则LR此时存储的是该处的地址,而在pendSV中对任务栈等信息处理了,但是没有更改LR的值,那么在pendSV处理结束的时刻我们看到有条
BX LR 指令, 那岂不是又回到了任务A的这个地方呀,怎么能切换到别的任务上去啊??????
---->问题2:
参见附件:
图示中上下文切换为什么会回到任务B呀?不是IRQ一直悬起了,上下文切换完后,立刻应该进入到IRQ而不是进入到任务B啊。
|
-
上下文切换
|