初级会员
- 积分
- 108
- 金钱
- 108
- 注册时间
- 2012-11-27
- 在线时间
- 23 小时
|
5金钱
void OSStart (void)
{
if (OSRunning == OS_FALSE) {
OS_SchedNew(); /* Find highest priority's task priority number */
OSPrioCur = OSPrioHighRdy;
OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
OSTCBCur = OSTCBHighRdy;
OSStartHighRdy(); /* Execute target specific code to start task */
}
}
OSStartHighRdy
LDR R0, =NVIC_SYSPRI2 ; Set the PendSV exception priority
LDR R1, =NVIC_PENDSV_PRI ;设置PendSV异常优先级
STRB R1, [R0]
MOVS R0, #0 ; Set the PSP to 0 for initial context switch call
MSR PSP, R0 ;写通用寄存器R0的值到PSP
LDR R0, __OS_Running ; OSRunning = TRUE,设置运行标志位
MOVS R1, #1
STRB R1, [R0]
LDR R0, =NVIC_INT_CTRL ; Trigger the PendSV exception (causes context switch)
LDR R1, =NVIC_PENDSVSET ;促发PendSV异常
STR R1, [R0]
CPSIE I ;开总中断 ; Enable interrupts at processor level
OSStartHang
B OSStartHang ; Should never get here
;Cortex-M3进入异常服务例程时,自动压栈了R0-R3,R12,LR(R14,连接寄存器),PSR(程序状态寄存器)和PC(R15).并且在返回时自动弹出
OSPendSV
;MRS R3, PRIMASK ;
;CPSID I ;
MRS R0, PSP ; PSP is process stack pointer
CBZ R0, OSPendSV_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, __OS_TCBCur ; 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
OSPendSV_nosave
PUSH {R14}
LDR R0, __OS_TaskSwHook ; OSTaskSwHook();
BLX R0
POP {R14}
LDR R0, __OS_PrioCur ; OSPrioCur = OSPrioHighRdy;
LDR R1, __OS_PrioHighRdy
LDRB R2, [R1]
STRB R2, [R0]
LDR R0, __OS_TCBCur ; OSTCBCur = OSTCBHighRdy;
LDR R1, __OS_TCBHighRdy
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
;MSR PRIMASK, R3 ;
BX LR ; exception return will restore remaining context
问题1:OSStart()函数里面OSPrioCur = OSPrioHighRdy; OSTCBCur = OSTCBHighRdy;为什么在OSPendSV_nosave里面再次赋值?
问题2:LDM R0,{R4-R11}这句汇编于语言的意思是什么?
麻烦大家指导指导!
|
最佳答案
查看完整内容[请看2#楼]
1、俩段程序,一个只运行一次,一个会多次运行,做相同的事很正常;当然,你提到它们首次有重复是对的。
2、LDM是批量加载指令。
|