你好,游客 登录 注册 搜索
背景:
阅读新闻

uC/OS-II源码分析

[日期:2012-07-22] 来源:Linux社区  作者:k122769836 [字体:大 中 小]

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;

}

linux
相关资讯       UCOS-II  UCOS 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款