设为首页 加入收藏

TOP

uC/OS-II源码分析
2014-11-24 11:30:44 来源: 作者: 【 】 浏览:0
Tags: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;


}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇S3C2440定时器和pwm编程分析 下一篇Android倒计时功能的实现

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)
·MySQL 数据类型:从 (2025-12-26 18:20:03)
·Linux Shell脚本教程 (2025-12-26 17:51:10)
·Qt教程,Qt5编程入门 (2025-12-26 17:51:07)