新手上路
- 积分
- 29
- 金钱
- 29
- 注册时间
- 2012-8-28
- 在线时间
- 0 小时
|
;/**************************************************************************************
;* 函数名称: OSPendSV
;*
;* 功能描述: OSPendSV is used to cause a context switch.
;*
;* 参 数: None
;*
;* 返 回 值: None
;***************************************************************************************/
PendSV_Handler
CPSID I ; Prevent interruption during context switch
MRS R0, PSP ; PSP is process stack pointer 如果在用PSP堆栈,则可以忽略保存寄存器,参考CM3权威中的双堆栈-白菜注
CBZ R0, PendSV_Handler_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
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
为什么要SUBS R0, R0, #0x20 ????
STM32发生异常时不是自动会把XPSP ,pc,lr,r12,r3,r2,r1,r0保存到堆栈中,难道不更新PSP,要我们手动更新PSP(SUBS R0, R0, #0x20 ),还是什么作用?这个问题我非常纠结!
还有是初始化堆栈的SP应该指向栈顶(r4),但是我感觉在保存堆栈时他是把指向(r0)的SP给了TCB,感觉是在入栈的一半!????我是彻底被这个SP搞的非常糊涂了!希望大神能帮帮我!小弟万分感谢!!!
这个问题纠结我非常久了!希望知道的大神能指导我一下!谢谢!
|
|