ucos源码分析(一)

本文记录了一位电子信息工程专业大三学生初次尝试分析UCOS嵌入式系统源码的过程。作者在学习Linux和驱动知识受阻后,决定通过调试和追踪来深入理解UCOS。开发环境为Linux+eclipse,并将从main函数开始逐步解析源码。
摘要由CSDN通过智能技术生成

时间: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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值