Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / uC/OS-II源码分析

uC/OS-II源码分析首先从main.c文件看起,下面是uC/OS-II main.C的大致流程:main(){ OSInit(); TaskCreate(...); OSStart();}首先是调用OSInit进行初始化,然后使用TaskCreate创建几个进程/Task,最后调用OSStart,操作系统就开始运行了。--------------------------------------------------------OSInit():  最先看看OSInit完成哪些初始化:void  OSInit (void){#if OS_VERSION >= 204    OSInitHookBegin();                                    /* Call port specific initialization code   */#endif    OS_InitMisc();                                        /* Initialize miscellaneous variables       */    OS_InitRdyList();                                      /* Initialize the Ready List                */    OS_InitTCBList();                                     /* Initialize the free list of OS_TCBs      */    OS_InitEventList();                                    /* Initialize the free list of OS_EVENTs    */#if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)    OS_FlagInit();                                       /* Initialize the event flag structures     */#endif#if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)    OS_MemInit();                                      /* Initialize the memory manager            */#endif#if (OS_Q_EN > 0) && (OS_MAX_QS > 0)    OS_QInit();                                        /* Initialize the message queue structures  */#endif    OS_InitTaskIdle();                                   /* Create the Idle Task  初始化空闲任务  */#if OS_TASK_STAT_EN > 0    OS_InitTaskStat();                                  /* Create the Statistic Task初始化统计任务*/#endif#if OS_VERSION >= 204    OSInitHookEnd();                                  /* Call port specific init. code            */#endif#if OS_VERSION >= 270 && OS_DEBUG_EN > 0    OSDebugInit();#endif}OS_InitMisc()完成的是一些其其他他的变量的初始化:    OSIntNesting  = 0;                                 /* Clear the interrupt nesting counter      */    OSLockNesting = 0;                                /* Clear the scheduling lock counter        */    OSTaskCtr     = 0;                               /* Clear the number of tasks                */    OSRunning     = FALSE;                         /* Indicate that multitasking not started   */        OSCtxSwCtr    = 0;                             /* Clear the context switch counter         */    OSIdleCtr     = 0L;                             /* Clear the 32-bit idle counter            */其中包括:中断嵌套标志OSIntNesting,调度锁定标志OSLockNesting,OS标志OSRunning等。OSRunning在这里设置为FALSE,在后面OSStartHighRdy中会被设置为TRUE表示OS开始工作。--------------------------------------------------------------------OS_InitRdyList()初始化就绪Task列表:static  void  OS_InitRdyList (void){    INT8U    i;    INT8U   *prdytbl;    OSRdyGrp      = 0x00;                           /* Clear the ready list       */    prdytbl       = &OSRdyTbl[0];    for (i = 0; i < OS_RDY_TBL_SIZE; i++) {        *prdytbl++ = 0x00;    }    OSPrioCur     = 0;    OSPrioHighRdy = 0;    OSTCBHighRdy  = (OS_TCB *)0;  //                                   OSTCBCur      = (OS_TCB *)0;}