歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> uC/OS-II源碼分析

uC/OS-II源碼分析

日期:2017/3/1 10:15:47   编辑:Linux編程

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;

}

Copyright © Linux教程網 All Rights Reserved