⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_core.c

📁 UCOSII源代码中文注释版
💻 C
📖 第 1 页 / 共 5 页
字号:
*
* Arguments  : none
*
* Returns    : none
*********************************************************************************************************
*/
/*
*********************************************************************************************************
                                                         虚拟函数?
描述:此函数不做任务事情,由OSTaskDel().调用
参数:无
返回:无
*********************************************************************************************************
*/


#if OS_TASK_DEL_EN > 0
void  OS_Dummy (void)
{           //不做任何事
}
#endif

/*$PAGE*/
/*
*********************************************************************************************************
*                             MAKE TASK READY TO RUN BASED ON EVENT OCCURING
*
* Description: This function is called by other uC/OS-II services and is used to ready a task that was
*              waiting for an event to occur.
*
* Arguments  : pevent    is a pointer to the event control block corresponding to the event.
*
*              msg       is a pointer to a message.  This pointer is used by message oriented services
*                        such as MAILBOXEs and QUEUEs.  The pointer is not used when called by other
*                        service functions.
*
*              msk       is a mask that is used to clear the status byte of the TCB.  For example,
*                        OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
*
* Returns    : none
*
* Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
                                                     基于事件发生使任务准备运行
描述:该函数由UCOS其它服务调用,用于使一个任务就绪,等待一个事件发生
参数:pevent:指向对应事件的ECB的指针
                 msg:消息指针,由邮箱队列等消息定向服务使用,该指针不能由其它
                              服务函数调用
                msk:是用于清除TCB状态字节的掩码,比如:
                             OSSemPost() 将传递TAT_SEM, OSMboxPost() 将传递OS_STAT_MBOX

这个函数看得不是很懂
*********************************************************************************************************
*/
#if OS_EVENT_EN > 0  
//能使队列代码产生&&申请队列控制块最大数不为零||能使邮箱代码产生||
//能使信号量代码产生||能使互斥量代码产生 

INT8U  OS_EventTaskRdy (OS_EVENT *pevent, void *msg, INT8U msk)
{
    OS_TCB *ptcb;
    INT8U   x;
    INT8U   y;
    INT8U   bitx;
    INT8U   bity;
    INT8U   prio;


    y    = OSUnMapTbl[pevent->OSEventGrp];            /* Find highest prio. task waiting for message   */
    bity = OSMapTbl[y];//寻找等待消息的最高优先级任务
    x    = OSUnMapTbl[pevent->OSEventTbl[y]];
    bitx = OSMapTbl[x];
    prio = (INT8U)((y << 3) + x);                     /* Find priority of task getting the msg         */
    if ((pevent->OSEventTbl[y] &= ~bitx) == 0x00) {   /* Remove this task from the waiting list        */
		//将此任务从等待列表中移除。
        pevent->OSEventGrp &= ~bity;                  /* Clr group bit if this was only task pending   */
		//如果是唯一挂起的任务,那么清除组位,
    }
    ptcb                 =  OSTCBPrioTbl[prio];       /* Point to this task's OS_TCB                   */
	//指针指向当前任务的OS_TCB 
    ptcb->OSTCBDly       =  0;                        /* Prevent OSTimeTick() from readying task       */
	//防止时钟节拍使任务就绪?这样就行?
    ptcb->OSTCBEventPtr  = (OS_EVENT *)0;             /* Unlink ECB from this task                     */
	//从这样任务上断开ECB
#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0)
    ptcb->OSTCBMsg       = msg;                       /* Send message directly to waiting task         */
//将消息直接发送到等待的任务
#else
    msg                  = msg;                       /* Prevent compiler warning if not used          */
//防止编译器警告
#endif
    ptcb->OSTCBStat     &= ~msk;                      /* Clear bit associated with event type          */
//事件状态位清除
    if (ptcb->OSTCBStat == OS_STAT_RDY) {             /* See if task is ready (could be susp'd)        */
		//如果任务就绪,(不能被挂起)
        OSRdyGrp        |=  bity;                     /* Put task in the ready to run list             */
        OSRdyTbl[y]     |=  bitx;
    }
    return (prio);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
*                                   MAKE TASK WAIT FOR EVENT TO OCCUR
*
* Description: This function is called by other uC/OS-II services to suspend a task because an event has
*              not occurred.
*
* Arguments  : pevent   is a pointer to the event control block for which the task will be waiting for.
*
* Returns    : none
*
* Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
                                  使任务等待事件发生
描述:由ucosII服务程序调用去挂起一个任务因为一个事件还没有发生
参数:pevent  指向将要等待的任务的ECB的指针
返回:无
备注:ucos内部调用,其它应用程序不能调用它
*********************************************************************************************************
*/

#if OS_EVENT_EN > 0
#define  OS_EVENT_EN       (((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0) || (OS_SEM_EN > 0) || (OS_MUTEX_EN > 0))
//能使队列代码产生&&申请队列控制块最大数不为零||能使邮箱代码产生||
//能使信号量代码产生||能使互斥量代码产生 

void  OS_EventTaskWait (OS_EVENT *pevent)
{
    OSTCBCur->OSTCBEventPtr = pevent;            /* Store pointer to event control block in TCB        */
//保存ECB指针到TCB
    if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0x00) {   /* Task no longer ready      */
		//如果任务没有就绪(那就挂起吗?)
        OSRdyGrp &= ~OSTCBCur->OSTCBBitY;        /* Clear event grp bit if this was only task pending  */
		//如果是没有一个任务挂起的话就清除事件群位。
    }
    pevent->OSEventTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX;          /* Put task in waiting list  */
    pevent->OSEventGrp                   |= OSTCBCur->OSTCBBitY;
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
*                              MAKE TASK READY TO RUN BASED ON EVENT TIMEOUT
*
* Description: This function is called by other uC/OS-II services to make a task ready to run because a
*              timeout occurred.
*
* Arguments  : pevent   is a pointer to the event control block which is readying a task.
*
* Returns    : none
*
* Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
                                                             当事件超时,让任务准备运行
描述:由于超时发生,由ucos调用让个任务准备运行,
参数:pevent:就绪任务的ECB指针
返回:无
备注:ucos内部函数,其它应用函数不能调用。
*********************************************************************************************************
*/
#if OS_EVENT_EN > 0
void  OS_EventTO (OS_EVENT *pevent)
{
    if ((pevent->OSEventTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0x00) {
        pevent->OSEventGrp &= ~OSTCBCur->OSTCBBitY;
    }//如果一组中没有一个任务挂起就清除该组
    OSTCBCur->OSTCBStat     = OS_STAT_RDY;       /* Set status to ready         */
	//将当前任务设置为即将运行
    OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;     /* No longer waiting for event   */
	//运行就不再等待事物了
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
*                                 INITIALIZE EVENT CONTROL BLOCK'S WAIT LIST
*
* Description: This function is called by other uC/OS-II services to initialize the event wait list.
*
* Arguments  : pevent    is a pointer to the event control block allocated to the event.
*
* Returns    : none
*
* Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
                                                        初始化ECB等待列表
描述:由ucos调用初始化事件等待列表
参数:pevent:指向指定事件的ECB的指针
返回:无
备注:内部函数,应用函数不能调用
*********************************************************************************************************
*/
#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0) || (OS_SEM_EN > 0) || (OS_MUTEX_EN > 0)
void  OS_EventWaitListInit (OS_EVENT *pevent)
{
    INT8U  *ptbl;


    pevent->OSEventGrp = 0x00;                   /* No task waiting on event     */
	//初始化时事件中无等待的任务
    ptbl               = &pevent->OSEventTbl[0];//取地址

#if OS_EVENT_TBL_SIZE > 0//不采用循环的原因是这样运行速度更快
    *ptbl++            = 0x00;
#endif

#if OS_EVENT_TBL_SIZE > 1
    *ptbl++            = 0x00;
#endif

#if OS_EVENT_TBL_SIZE > 2
    *ptbl++            = 0x00;
#endif

#if OS_EVENT_TBL_SIZE > 3
    *ptbl++            = 0x00;
#endif

#if OS_EVENT_TBL_SIZE > 4
    *ptbl++            = 0x00;
#endif

#if OS_EVENT_TBL_SIZE > 5
    *ptbl++            = 0x00;
#endif

#if OS_EVENT_TBL_SIZE > 6
    *ptbl++            = 0x00;
#endif

#if OS_EVENT_TBL_SIZE > 7
    *ptbl              = 0x00;
#endif
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
*                                             INITIALIZATION
*                           INITIALIZE THE FREE LIST OF EVENT CONTROL BLOCKS
*
* Description: This function is called by OSInit() to initialize the free list of event control blocks.
*
* Arguments  : none
*
* Returns    : none
描述:初始化事件控制块空闲列表
参数:无
返回:无
*********************************************************************************************************
*/

static  void  OS_InitEventList (void)
{
#if (OS_EVENT_EN > 0) && (OS_MAX_EVENTS > 0)
#if (OS_MAX_EVENTS > 1)//如果任务数大于一
    INT16U     i;
    OS_EVENT  *pevent1;
    OS_EVENT  *pevent2;


    pevent1 = &OSEventTbl[0];//事件控制块方框表
    pevent2 = &OSEventTbl[1];
    for (i = 0; i < (OS_MAX_EVENTS - 1); i++) {                  /* Init. list of free EVENT control blocks  */
		//初始化空ECB链表
        pevent1->OSEventType = OS_EVENT_TYPE_UNUSED;//状态设置为挂起
        pevent1->OSEventPtr  = pevent2;//把它们链起来。接起来
        pevent1++;
        pevent2++;//加吧,加吧,加到OS_MAX_EVENTS - 1
    }
    pevent1->OSEventType = OS_EVENT_TYPE_UNUSED;
    pevent1->OSEventPtr  = (OS_EVENT *)0;//前趋指向零指针
    OSEventFreeList      = &OSEventTbl[0];//空表指向OSEventTbl第一个

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -