时间:2018.01.27 本人目前是大三学生 电子信息工程专业,在大学前俩年的时间,一直在使用和学习单片机,不过也仅仅是从51到32,马上要面临就业,最近开始学习linux ,驱动方面知识,看了几天视频,感觉看不下去了,昨晚突发奇想,下载了ucos的源码,想要分析一下这个小的嵌入式系统。本人将从头开始,通过调试追踪,对源代码进行细致分析。
希望自己可以坚持下去。开发环境是linux+eclipse 仿真来运行程序。
下面进入正题,大家接触过C语言,单片机的同学都知道,程序的入口是main函数,当然在单片机中会有一些堆栈初始化以及中断向量设置我们现在不关注,
下面是这个程序的main函数;
int main (void)
{
OS_ERR err;
OSInit(&err); /* Initialize "uC/OS-III, The Real-Time Kernel" */
OSTaskCreate((OS_TCB *)&App_TaskStartTCB, /* Create the start task */
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR ) App_TaskStart,
(void *) 0,
(OS_PRIO ) APP_CFG_TASK_START_PRIO,
(CPU_STK *)&App_TaskStartStk[0],
(CPU_STK )(APP_CFG_TASK_START_STK_SIZE / 10u),
(CPU_STK_SIZE) APP_CFG_TASK_START_STK_SIZE,
(OS_MSG_QTY ) 0,
(OS_TICK ) 0,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */
while(DEF_ON){ /* Should Never Get Here */
};
}
OSInit(&err); /* Initialize "uC/OS-III, The Real-Time Kernel" */
osInit(&err); 这是main函数中运行的第一个函数,下面是这个函数的实现 在os_core.c文件中
/*
************************************************************************************************************************
* INITIALIZATION
*
* Description: This function is used to initialize the internals of uC/OS-III and MUST be called prior to
* creating any uC/OS-III object and, prior to calling OSStart().
*
* Arguments : p_err is a pointer to a variable that will contain an error code returned by this function.
*
* OS_ERR_NONE Initialization was successful
* Other Other OS_ERR_xxx depending on the sub-functions called by OSInit().
* Returns : none
************************************************************************************************************************
*/
void OSInit (OS_ERR *p_err)
{
#if (OS_CFG_ISR_STK_SIZE > 0u)
CPU_STK *p_stk;
CPU_STK_SIZE size;
#endif
#ifdef OS_SAFETY_CRITICAL
if (p_err == DEF_NULL) {
OS_SAFETY_CRITICAL_EXCEPTION();
return;
}
#endif
OSInitHook(); /* Call port specific initialization code */
OSIntNestingCtr = 0u; /* Clear the interrupt nesting counter */
OSRunning = OS_STATE_OS_STOPPED; /* Indicate that multitasking not started */
OSSchedLockNestingCtr = 0u; /* Clear the scheduling lock counter */
OSTCBCurPtr = DEF_NULL; /* Initialize OS_TCB pointers to a known state */
OSTCBHighRdyPtr = DEF_NULL;
OSPrioCur = 0u; /* Initialize priority variables to a known state */
OSPrioHighRdy = 0u;
#if (OS_CFG_ISR_POST_DEFERRED_EN == DEF_ENABLED)
OSPrioSaved = 0u;
#endif
#if (OS_CFG_S