UCOS-II启动多任务环境的函数是OSStart();用户在调用OSStart()前,必须已经建立了一个或多个任务。OSStart()最终调用OSStartHighRdy()运行多任务启动前优先级最高的任务。OSStartHighRdy()代码是用汇编写的,在文件OS_CPU_A.S中。
函数如下:
OSStartHighRdy
MSR CPSR_cxsf, #0xDF //1; Switch to SYS mode with IRQ and FIQ disabled
BL OSTaskSwHook //2; OSTaskSwHook();
LDR R4, =OSRunning //3; OSRunning = TRUE
MOV R5, #1 //4
STRB R5, [R4] //5
; SWITCH TO HIGHEST PRIORITY TASK
LDR R4, =OSTCBHighRdy //6; Get highest priority task TCB address
LDR R4, [R4] //7; get stack pointer
LDR SP, [R4] //8; switch to the new stack
LDR R4, [SP], #4 //9; pop new task's CPSR
MSR CPSR_cxsf,R4 //10
LDR R0, [SP], #4 //11; pop new task's context
LDR R1, [SP], #4 //12
LDR R2, [SP], #4 //13
LDR R3, [SP], #4 //14
LDR R4, [SP], #4 //15
LDR R5, [SP], #4 //16
LDR R6, [SP], #4 //17
LDR R7, [SP], #4 //18
LDR R8, [SP], #4 //19
LDR R9, [SP], #4 //20
LDR R10, [SP], #4 //21
LDR R11, [SP], #4 //22
LDR R12, [SP], #4 //23
LDR LR, [SP], #4 //24
LDR PC, [SP], #4 //25
代码分析如下:
1:进入系统模式,并关闭IRQ,FIQ中断
2:调用OSTaskSwHook(),这是钩子函数,一般为空,用户可以视需要自己添加内容。
3-5:把OSRunning标志置1。OSRunning是UCOS系统己经启动的一个标识,它在调用UCOS中的OSStart时被置为1。
6-8:SP指向最高优先级任务的堆栈。
9-24:把最高优先级任务堆栈的内容保存到寄存器中
25:开始执行最高优先级任务。
文章评论(0条评论)
登录后参与讨论