在main函数中不能init中断,只能创建task 和event(消息队列消息邮箱等),在系统的第一个子程序中才能init中断,开启timetick开始调度任务,中断向量表应该在main函数运行之前的汇编boot函数中就已经确定了。
看一下main中的最后一个函数调用
- /*
- *********************************************************************************************************
- * START MULTITASKING
- *
- * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
- * task that you have created. Before you can call OSStart(), you MUST have called OSInit()
- * and you MUST have created at least one task.
- *
- * Arguments : none
- *
- * Returns : none
- *
- * Note : OSStartHighRdy() MUST:
- * a) Call OSTaskSwHook() then,
- * b) Set OSRunning to OS_TRUE.
- * c) Load the context of the task pointed to by OSTCBHighRdy.
- * d_ Execute the task.
- *********************************************************************************************************
- */
- 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 */
- }
- }
在task创建函数中我们已经将就绪表中我们创建的函数置为rdy,也就是说,所有初始化创建的任务都是就绪态
那么直接开始调度函数OS_SchedNew,就会将OSPrioHighRdy设置为task0
第二部,将调度程序求出来的最高优先级赋值给OSPrioCur
第三步,将指向当前运行TCB的指针OSTCBCur指向最高优先级的taskTCB
第四步,调用OSStartHighRdy函数
- ;*********************************************************************************************************
- ; START MULTITASKING
- ; void OSStartHighRdy(void)
- ;
- ; The stack frame is assumed to look as follows:
- ;
- ; Entry Point(Task Name) (High memory)
- ; LR(R14)
- ; R12
- ; R11
- ; R10
- ; R9
- ; R8
- ; R7
- ; R6
- ; R5
- ; R4
- ; R3
- ; R2
- ; R1
- ; R0 : argument
- ; OSTCBHighRdy->OSTCBStkPtr --> CPSR (Low memory)
- ;
- ; Note : OSStartHighRdy() MUST:
- ; a) Call OSTaskSwHook() then,
- ; b) Set OSRunning to TRUE,
- ; c) Switch to the highest priority task.
- ;********************************************************************************************************** */
- OSStartHighRdy
- ;----------------------------------------------------------------------------------
- ; OSRunning = TRUE;
- ;----------------------------------------------------------------------------------
- MSR CPSR_cxsf,#SVCMODE|NOINT ;Switch to SVC mode with IRQ&FIQ disable
- BL OSTaskSwHook ;Call user define Task switch hook
- LDR R0, =OSRunning ; OSRunning =TRUE
- MOV R1, #1
- STRB R1, [R0]
- ;----------------------------------------------------------------------------------
- ; SP = OSTCBHighRdy->OSTCBStkPtr;
- ;----------------------------------------------------------------------------------
- LDR R0, =OSTCBHighRdy
- LDR R0, [R0]
- LDR SP, [R0]
- ;----------------------------------------------------------------------------------
- ; Prepare to return to proper mode
- ;----------------------------------------------------------------------------------
- LDMFD SP!, {R0}
- MSR SPSR_cxsf, R0
- LDMFD SP!, {R0-R12, LR, PC}^
OSRunning =TRUE,SP = OSTCBHighRdy->OSTCBStkPtr;弹出堆栈中的上下文
很有必要认真学习ARM和x86体系的汇编语言和简单的boot驱动
以便更好的移植各种操作系统
阅读(2459) | 评论(0) | 转发(0) |