μc的操作系统核心源码基本上都是os_core之类的文件,以前做项目的时候用过但是木有好好看过,现在不忙了可以每天晚上的时间看一点,一则巩固一下c语言的知识,二则可以为以后linux和vxworks打个基础
从main函数开始,除了硬件上的TargetInit();
初始化硬件上的端口(串口等)、PLL和中断
然后就是最主要的系统初始化函数
OSInit ();
- /*
- *********************************************************************************************************
- * INITIALIZATION
- *
- * Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
- * creating any uC/OS-II object and, prior to calling OSStart().
- *
- * Arguments : none
- *
- * Returns : none
- *********************************************************************************************************
- */
- 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_TMR_EN > 0
- OSTmr_Init(); /* Initialize the Timer Manager */
- #endif
- #if OS_VERSION >= 204
- OSInitHookEnd(); /* Call port specific init. code */
- #endif
- #if OS_VERSION >= 270 && OS_DEBUG_EN > 0
- OSDebugInit();
- #endif
- }
如果版本号超过204u则调用函数void OSInitHookBegin (void)
OS_InitMisc();杂项变量初始化
- /*
- *********************************************************************************************************
- * INITIALIZATION
- * INITIALIZE MISCELLANEOUS VARIABLES
- *
- * Description: This function is called by OSInit() to initialize miscellaneous variables.
- *
- * Arguments : none
- *
- * Returns : none
- *********************************************************************************************************
- */
- static void OS_InitMisc (void)
- {
- #if OS_TIME_GET_SET_EN > 0
- OSTime = 0L; /* Clear the 32-bit system clock */
- #endif
- OSIntNesting = 0; /* Clear the interrupt nesting counter */
- OSLockNesting = 0; /* Clear the scheduling lock counter */
- OSTaskCtr = 0; /* Clear the number of tasks */
- OSRunning = OS_FALSE; /* Indicate that multitasking not started */
- OSCtxSwCtr = 0; /* Clear the context switch counter */
- OSIdleCtr = 0L; /* Clear the 32-bit idle counter */
- #if OS_TASK_STAT_EN > 0
- OSIdleCtrRun = 0L;
- OSIdleCtrMax = 0L;
- OSStatRdy = OS_FALSE; /* Statistic task is not ready */
- #endif
- }
OSTime系统时钟变量
OS_EXT volatile INT32U OSTime; /* Current value of system time (in ticks) */
OSIntNesting系统中断嵌套层数变量
OS_EXT INT8U OSIntNesting; /* Interrupt nesting level
OSLockNesting系统调度锁计数器
OS_EXT INT8U OSLockNesting;
多任务嵌套计数器
OSTaskCtr系统创建的task的个数
OS_EXT INT8U OSTaskCtr; /* Number of tasks created
OSRunning系统内核运行标志位
OS_EXT BOOLEAN OSRunning; /* Flag indicating that kernel is running */
OSCtxSwCtr系统上下文切换计数器
OS_EXT INT32U OSCtxSwCtr; /* Counter of number of context switches */
OSIdleCtr系统空闲计数器
OS_EXT volatile INT32U OSIdleCtr; /* Idle counter
OSIdleCtrRun一秒钟内空闲计数器的有效值(据我猜测)
OS_EXT INT32U OSIdleCtrRun; /* Val. reached by idle ctr at run time in 1 sec. */
OSIdleCtrMax一秒钟内空闲计数器的最大值
OS_EXT INT32U OSIdleCtrMax; /* Max. value that idle ctr can take in 1 sec. */
OSStatRdy静态任务就绪的标志位
OS_EXT BOOLEAN OSStatRdy; /* Flag indicating that the statistic task is rdy */
void OS_InitRdyList (void)初始化就绪任务的数组
- /*
- *********************************************************************************************************
- * INITIALIZATION
- * INITIALIZE THE READY LIST
- *
- * Description: This function is called by OSInit() to initialize the Ready List.
- *
- * Arguments : none
- *
- * Returns : none
- *********************************************************************************************************
- */
- static void OS_InitRdyList (void)
- {
- INT8U i;
- #if OS_LOWEST_PRIO <= 63
- INT8U *prdytbl;
- #else
- INT16U *prdytbl;
- #endif
- OSRdyGrp = 0; /* Clear the ready list */
- prdytbl = &OSRdyTbl[0];
- for (i = 0; i < OS_RDY_TBL_SIZE; i++) {
- *prdytbl++ = 0;
- }
- OSPrioCur = 0;
- OSPrioHighRdy = 0;
- OSTCBHighRdy = (OS_TCB *)0;
- OSTCBCur = (OS_TCB *)0;
- }
系统就绪任务表OSRdyTbl[OS_RDY_TBL_SIZE]
#if OS_LOWEST_PRIO <= 63
OS_EXT INT8U OSRdyGrp; /* Ready list group */
OS_EXT INT8U OSRdyTbl[OS_RDY_TBL_SIZE]; /* Table of tasks which are ready to run */
#else
OS_EXT INT16U OSRdyGrp; /* Ready list group */
OS_EXT INT16U OSRdyTbl[OS_RDY_TBL_SIZE]; /* Table of tasks which are ready to run */
#endif
阅读(2671) | 评论(0) | 转发(1) |