启动ucosii之五OSStart()

函数原型来自OS_CORE.C

//该函数由SStart()函数调用,功能是运行优先级最高的就绪任务,在调用OSStart()之前,用户必须先调用OSInit(),并且已经至少创建了一个任务.
//OSStartHighRdy()默认指针OSTCBHighRdy指向优先级最高就绪任务的任务控制块(OS_TCB)(在这之前OSTCBHighRdy已由OSStart()设置好了).
void  OSStart (void)//通过这个函数,开始多任务
{
 INT8U y;
 INT8U x;
    //确保操作系统没有在运行
    if (OSRunning == FALSE) {
 //获取任务就绪表中就绪的最高优先级
        y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's task priority number   */
        x             = OSUnMapTbl[OSRdyTbl[y]];
        OSPrioHighRdy = (INT8U)((y << 3) + x);
        OSPrioCur     = OSPrioHighRdy;
 //指向就绪的最高优先级的任务控制块
        OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
        OSTCBCur      = OSTCBHighRdy;


//_OSStartHighRdy(),实际核心代码采用汇编语言编写在Os_cpu_a.asm中.
        OSStartHighRdy();                            /* Execute target specific code to start task     */
    }
}

函数原型来自OS_CPU_A.ASM
为了启动任务,OSStartHighRdy()从任务控制块(OS_TCB)中找到指向堆栈的指针,然后运行POP DS/ POP ES/ POPA  和 IRET

_OSStartHighRdy  PROC FAR

            MOV    AX, SEG _OSTCBHighRdy          ; Reload DS
            MOV    DS, AX                         ;
;
            CALL   FAR PTR _OSTaskSwHook          ; Call user defined task switch hook
;
            MOV    AL, 1                          ; OSRunning = TRUE;
            MOV    BYTE PTR DS:_OSRunning, AL     ;   (Indicates that multitasking has started)
;
            LES    BX, DWORD PTR DS:_OSTCBHighRdy ; SS:SP = OSTCBHighRdy->OSTCBStkPtr
            MOV    SS, ES:[BX+2]                  ;
            MOV    SP, ES:[BX+0]                  ;
;
            POP    DS                             ; Load task's context
            POP    ES                             ;
            POPA                                  ;
;
            IRET                                  ; Run task

_OSStartHighRdy  ENDP

你可能感兴趣的:(uCOSII)