目录
事件标志组标志置1或清0
cpp
OS_FLAGS OSFlagPost (OS_FLAG_GRP *pgrp,
OS_FLAGS flags,
INT8U opt,
INT8U *perr)
{
OS_FLAG_NODE *pnode;
BOOLEAN sched;
OS_FLAGS flags_cur;
OS_FLAGS flags_rdy;
BOOLEAN rdy;
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0u;
#endif
#ifdef OS_SAFETY_CRITICAL
if (perr == (INT8U *)0)
{
OS_SAFETY_CRITICAL_EXCEPTION();
return ((OS_FLAGS)0);
}
#endif
#if OS_ARG_CHK_EN > 0u
if (pgrp == (OS_FLAG_GRP *)0) /* Validate 'pgrp' */
{
*perr = OS_ERR_FLAG_INVALID_PGRP;
return ((OS_FLAGS)0);
}
#endif
if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) /* Make sure we are pointing to an event flag grp */
{
*perr = OS_ERR_EVENT_TYPE;
return ((OS_FLAGS)0);
}
/*$PAGE*/
OS_ENTER_CRITICAL();
switch (opt)
{
case OS_FLAG_CLR:
pgrp->OSFlagFlags &= (OS_FLAGS)~flags; /* Clear the flags specified in the group */
break;
case OS_FLAG_SET:
pgrp->OSFlagFlags |= flags; /* Set the flags specified in the group */
break;
default:
OS_EXIT_CRITICAL(); /* INVALID option */
*perr = OS_ERR_FLAG_INVALID_OPT;
return ((OS_FLAGS)0);
}
sched = OS_FALSE; /* Indicate that we don't need rescheduling */
pnode = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;
while (pnode != (OS_FLAG_NODE *)0) /* Go through all tasks waiting on event flag(s) */
{
switch (pnode->OSFlagNodeWaitType)
{
case OS_FLAG_WAIT_SET_ALL: /* See if all req. flags are set for current node */
flags_rdy = (OS_FLAGS) (pgrp->OSFlagFlags & pnode->OSFlagNodeFlags);
if (flags_rdy == pnode->OSFlagNodeFlags) /* Make task RTR, event(s) Rx'd */
{
rdy = OS_FlagTaskRdy (pnode, flags_rdy, OS_STAT_PEND_OK);
if (rdy == OS_TRUE)
{
sched = OS_TRUE; /* When done we will reschedule */
}
}
break;
case OS_FLAG_WAIT_SET_ANY: /* See if any flag set */
flags_rdy = (OS_FLAGS) (pgrp->OSFlagFlags & pnode->OSFlagNodeFlags);
if (flags_rdy != (OS_FLAGS)0) /* Make task RTR, event(s) Rx'd */
{
rdy = OS_FlagTaskRdy (pnode, flags_rdy, OS_STAT_PEND_OK);
if (rdy == OS_TRUE)
{
sched = OS_TRUE; /* When done we will reschedule */
}
}
break;
#if OS_FLAG_WAIT_CLR_EN > 0u
case OS_FLAG_WAIT_CLR_ALL: /* See if all req. flags are set for current node */
flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
if (flags_rdy == pnode->OSFlagNodeFlags) /* Make task RTR, event(s) Rx'd */
{
rdy = OS_FlagTaskRdy (pnode, flags_rdy, OS_STAT_PEND_OK);
if (rdy == OS_TRUE)
{
sched = OS_TRUE; /* When done we will reschedule */
}
}
break;
case OS_FLAG_WAIT_CLR_ANY: /* See if any flag set */
flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
if (flags_rdy != (OS_FLAGS)0) /* Make task RTR, event(s) Rx'd */
{
rdy = OS_FlagTaskRdy (pnode, flags_rdy, OS_STAT_PEND_OK);
if (rdy == OS_TRUE)
{
sched = OS_TRUE; /* When done we will reschedule */
}
}
break;
#endif
default:
OS_EXIT_CRITICAL();
*perr = OS_ERR_FLAG_WAIT_TYPE;
return ((OS_FLAGS)0);
}
pnode = (OS_FLAG_NODE *)pnode->OSFlagNodeNext; /* Point to next task waiting for event flag(s) */
}
OS_EXIT_CRITICAL();
if (sched == OS_TRUE)
{
OS_Sched();
}
OS_ENTER_CRITICAL();
flags_cur = pgrp->OSFlagFlags;
OS_EXIT_CRITICAL();
*perr = OS_ERR_NONE;
return (flags_cur);
}
事件标志组获取/无等待
cpp
#if OS_FLAG_ACCEPT_EN > 0u
OS_FLAGS OSFlagAccept (OS_FLAG_GRP *pgrp,
OS_FLAGS flags,
INT8U wait_type,
INT8U *perr)
{
OS_FLAGS flags_rdy;
INT8U result;
BOOLEAN consume;
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0u;
#endif
#ifdef OS_SAFETY_CRITICAL
if (perr == (INT8U *)0)
{
OS_SAFETY_CRITICAL_EXCEPTION();
return ((OS_FLAGS)0);
}
#endif
#if OS_ARG_CHK_EN > 0u
if (pgrp == (OS_FLAG_GRP *)0) /* Validate 'pgrp' */
{
*perr = OS_ERR_FLAG_INVALID_PGRP;
return ((OS_FLAGS)0);
}
#endif
if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) /* Validate event block type */
{
*perr = OS_ERR_EVENT_TYPE;
return ((OS_FLAGS)0);
}
result = (INT8U) (wait_type & OS_FLAG_CONSUME);
if (result != (INT8U)0) /* See if we need to consume the flags */
{
wait_type &= ~OS_FLAG_CONSUME;
consume = OS_TRUE;
}
else
{
consume = OS_FALSE;
}
/*$PAGE*/
*perr = OS_ERR_NONE; /* Assume NO error until proven otherwise. */
OS_ENTER_CRITICAL();
switch (wait_type)
{
case OS_FLAG_WAIT_SET_ALL: /* See if all required flags are set */
flags_rdy = (OS_FLAGS) (pgrp->OSFlagFlags & flags); /* Extract only the bits we want */
if (flags_rdy == flags) /* Must match ALL the bits that we want */
{
if (consume == OS_TRUE) /* See if we need to consume the flags */
{
pgrp->OSFlagFlags &= (OS_FLAGS)~flags_rdy; /* Clear ONLY the flags we wanted */
}
}
else
{
*perr = OS_ERR_FLAG_NOT_RDY;
}
OS_EXIT_CRITICAL();
break;
case OS_FLAG_WAIT_SET_ANY:
flags_rdy = (OS_FLAGS) (pgrp->OSFlagFlags & flags); /* Extract only the bits we want */
if (flags_rdy != (OS_FLAGS)0) /* See if any flag set */
{
if (consume == OS_TRUE) /* See if we need to consume the flags */
{
pgrp->OSFlagFlags &= (OS_FLAGS)~flags_rdy; /* Clear ONLY the flags we got */
}
}
else
{
*perr = OS_ERR_FLAG_NOT_RDY;
}
OS_EXIT_CRITICAL();
break;
#if OS_FLAG_WAIT_CLR_EN > 0u
case OS_FLAG_WAIT_CLR_ALL: /* See if all required flags are cleared */
flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
if (flags_rdy == flags) /* Must match ALL the bits that we want */
{
if (consume == OS_TRUE) /* See if we need to consume the flags */
{
pgrp->OSFlagFlags |= flags_rdy; /* Set ONLY the flags that we wanted */
}
}
else
{
*perr = OS_ERR_FLAG_NOT_RDY;
}
OS_EXIT_CRITICAL();
break;
case OS_FLAG_WAIT_CLR_ANY:
flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
if (flags_rdy != (OS_FLAGS)0) /* See if any flag cleared */
{
if (consume == OS_TRUE) /* See if we need to consume the flags */
{
pgrp->OSFlagFlags |= flags_rdy; /* Set ONLY the flags that we got */
}
}
else
{
*perr = OS_ERR_FLAG_NOT_RDY;
}
OS_EXIT_CRITICAL();
break;
#endif
default:
OS_EXIT_CRITICAL();
flags_rdy = (OS_FLAGS)0;
*perr = OS_ERR_FLAG_WAIT_TYPE;
break;
}
return (flags_rdy);
}
#endif
事件标志组状态查询
cpp
#if OS_FLAG_QUERY_EN > 0u
OS_FLAGS OSFlagQuery (OS_FLAG_GRP *pgrp,
INT8U *perr)
{
OS_FLAGS flags;
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0u;
#endif
#ifdef OS_SAFETY_CRITICAL
if (perr == (INT8U *)0)
{
OS_SAFETY_CRITICAL_EXCEPTION();
return ((OS_FLAGS)0);
}
#endif
#if OS_ARG_CHK_EN > 0u
if (pgrp == (OS_FLAG_GRP *)0) /* Validate 'pgrp' */
{
*perr = OS_ERR_FLAG_INVALID_PGRP;
return ((OS_FLAGS)0);
}
#endif
if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) /* Validate event block type */
{
*perr = OS_ERR_EVENT_TYPE;
return ((OS_FLAGS)0);
}
OS_ENTER_CRITICAL();
flags = pgrp->OSFlagFlags;
OS_EXIT_CRITICAL();
*perr = OS_ERR_NONE;
return (flags); /* Return the current value of the event flags */
}
#endif
设置事件标志组命名
cpp
#if OS_FLAG_NAME_EN > 0u
void OSFlagNameSet (OS_FLAG_GRP *pgrp,
INT8U *pname,
INT8U *perr)
{
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0u;
#endif
#ifdef OS_SAFETY_CRITICAL
if (perr == (INT8U *)0)
{
OS_SAFETY_CRITICAL_EXCEPTION();
return;
}
#endif
#if OS_ARG_CHK_EN > 0u
if (pgrp == (OS_FLAG_GRP *)0) /* Is 'pgrp' a NULL pointer? */
{
*perr = OS_ERR_FLAG_INVALID_PGRP;
return;
}
if (pname == (INT8U *)0) /* Is 'pname' a NULL pointer? */
{
*perr = OS_ERR_PNAME_NULL;
return;
}
#endif
if (OSIntNesting > 0u) /* See if trying to call from an ISR */
{
*perr = OS_ERR_NAME_SET_ISR;
return;
}
OS_ENTER_CRITICAL();
if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG)
{
OS_EXIT_CRITICAL();
*perr = OS_ERR_EVENT_TYPE;
return;
}
pgrp->OSFlagName = pname;
OS_EXIT_CRITICAL();
*perr = OS_ERR_NONE;
return;
}
#endif
获取事件标志组命名
cpp
#if OS_FLAG_NAME_EN > 0u
INT8U OSFlagNameGet (OS_FLAG_GRP *pgrp,
INT8U **pname,
INT8U *perr)
{
INT8U len;
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0u;
#endif
#ifdef OS_SAFETY_CRITICAL
if (perr == (INT8U *)0)
{
OS_SAFETY_CRITICAL_EXCEPTION();
return (0u);
}
#endif
#if OS_ARG_CHK_EN > 0u
if (pgrp == (OS_FLAG_GRP *)0) /* Is 'pgrp' a NULL pointer? */
{
*perr = OS_ERR_FLAG_INVALID_PGRP;
return (0u);
}
if (pname == (INT8U **)0) /* Is 'pname' a NULL pointer? */
{
*perr = OS_ERR_PNAME_NULL;
return (0u);
}
#endif
if (OSIntNesting > 0u) /* See if trying to call from an ISR */
{
*perr = OS_ERR_NAME_GET_ISR;
return (0u);
}
OS_ENTER_CRITICAL();
if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG)
{
OS_EXIT_CRITICAL();
*perr = OS_ERR_EVENT_TYPE;
return (0u);
}
*pname = pgrp->OSFlagName;
len = OS_StrLen (*pname);
OS_EXIT_CRITICAL();
*perr = OS_ERR_NONE;
return (len);
}
#endif