ucos2 OSEventPendMulti 详解
这个函数的作用: 等待多个事件的挂起
INT16U OSEventPendMulti (OS_EVENT **pevents_pend, OS_EVENT **pevents_rdy, void **pmsgs_rdy, INT16U timeout, INT8U *perr)
{
OS_EVENT **pevents; //定义变量用来存放传进来的 pevents_pend
OS_EVENT *pevent;
#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0))
OS_Q
pq;
#endif
BOOLEAN events_rdy;
INT16U events_rdy_nbr;
INT8U events_stat;
#if (OS_CRITICAL_METHOD == 3) /
Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
#if (OS_ARG_CHK_EN > 0)
if (perr == (INT8U
)0) { /
Validate ‘perr’ */
return (0);
}
if (pevents_pend == (OS_EVENT *
)0) { /
Validate ‘pevents_pend’ */
*perr = OS_ERR_PEVENT_NULL;
return (0);
}
if (pevents_rdy == (OS_EVENT *
)0) { /
Validate ‘pevents_rdy’ */
*perr = OS_ERR_PEVENT_NULL;
return (0);
}
if (pmsgs_rdy == (void *
)0) { /
Validate ‘pmsgs_rdy’ */
*perr = OS_ERR_PEVENT_NULL;
return (0);
}
#endif
//从这里开始正题来了
第一段
*pevents_rdy = (OS_EVENT *)0; /* Init array to NULL in case of errors */
pevents = pevents_pend;
pevent = *pevents;
== 第一次遍历所有的event 检查传进来的event是不是都合法 如果中间出现了信号量 、消息队列、邮箱以外的事件 程序就退出==
while (pevent != (OS_EVENT *)0)
{
switch (pevent->OSEventType)
{
#if (OS_SEM_EN > 0)
case OS_EVENT_TYPE_SEM:
break;
#endif
#if (OS_MBOX_EN > 0)
case OS_EVENT_TYPE_MBOX:
break;
#endif
#if ((OS_Q_EN > 0) && (OS_MAX_QS > 0))
case OS_EVENT_TYPE_Q:
break;
#endif
case OS_EVENT_TYPE_MUTEX:
case OS_EVENT_TYPE_FLAG:
default:
*perr = OS_ERR_EVENT_TYPE;
return (0);
}