📄 os_flag.lst
字号:
/*$PAGE*/
/*
*********************************************************************************************************
* ASSIGN A NAME TO AN EVENT FLAG GROUP
*
* Description: This function assigns a name to an event flag group.
*
* Arguments : pgrp is a pointer to the event flag group.
*
* pname is a pointer to an ASCII string that will be used as the name of the event flag
* group. The string must be able to hold at least OS_FLAG_NAME_SIZE characters.
*
* err is a pointer to an error code that can contain one of the following values:
*
* OS_NO_ERR if the requested task is resumed
* OS_ERR_EVENT_TYPE if 'pevent' is not pointing to an event flag group
* OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
* OS_FLAG_INVALID_PGRP if you passed a NULL pointer for 'pgrp'
*
* Returns : None
*********************************************************************************************************
*/
#if OS_FLAG_NAME_SIZE > 0
void OSFlagNameSet (OS_FLAG_GRP *pgrp, char *pname, INT8U *err) KCREENTRANT
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT8U len;
C51 COMPILER V8.05a OS_FLAG 04/11/2007 16:19:49 PAGE 8
OS_ENTER_CRITICAL();
#if OS_ARG_CHK_EN > 0
if (pgrp == (OS_FLAG_GRP *)0) { /* Is 'pgrp' a NULL pointer? */
OS_EXIT_CRITICAL(); /* Yes */
*err = OS_FLAG_INVALID_PGRP;
return;
}
if (pname == (char *)0) { /* Is 'pname' a NULL pointer? */
OS_EXIT_CRITICAL(); /* Yes */
*err = OS_ERR_PNAME_NULL;
return;
}
#endif
if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {
OS_EXIT_CRITICAL();
*err = OS_ERR_EVENT_TYPE;
return;
}
len = strlen(pname); /* Can we fit the string in the storage area? */
if (len > (OS_FLAG_NAME_SIZE - 1)) { /* No */
OS_EXIT_CRITICAL();
*err = OS_ERR_FLAG_NAME_TOO_LONG;
return;
}
(void)strcpy(pgrp->OSFlagName, pname); /* Yes, copy name from OS_FLAG_GRP */
OS_EXIT_CRITICAL();
*err = OS_NO_ERR;
return;
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* WAIT ON AN EVENT FLAG GROUP
*
* Description: This function is called to wait for a combination of bits to be set in an event flag
* group. Your application can wait for ANY bit to be set or ALL bits to be set.
*
* Arguments : pgrp is a pointer to the desired event flag group.
*
* flags Is a bit pattern indicating which bit(s) (i.e. flags) you wish to wait for.
* The bits you want are specified by setting the corresponding bits in
* 'flags'. e.g. if your application wants to wait for bits 0 and 1 then
* 'flags' would contain 0x03.
*
* wait_type specifies whether you want ALL bits to be set or ANY of the bits to be set.
* You can specify the following argument:
*
* OS_FLAG_WAIT_CLR_ALL You will wait for ALL bits in 'mask' to be clear (0)
* OS_FLAG_WAIT_SET_ALL You will wait for ALL bits in 'mask' to be set (1)
* OS_FLAG_WAIT_CLR_ANY You will wait for ANY bit in 'mask' to be clear (0)
* OS_FLAG_WAIT_SET_ANY You will wait for ANY bit in 'mask' to be set (1)
*
* NOTE: Add OS_FLAG_CONSUME if you want the event flag to be 'consumed' by
* the call. Example, to wait for any flag in a group AND then clear
* the flags that are present, set 'wait_type' to:
*
* OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME
*
C51 COMPILER V8.05a OS_FLAG 04/11/2007 16:19:49 PAGE 9
* timeout is an optional timeout (in clock ticks) that your task will wait for the
* desired bit combination. If you specify 0, however, your task will wait
* forever at the specified event flag group or, until a message arrives.
*
* err is a pointer to an error code and can be:
* OS_NO_ERR The desired bits have been set within the specified
* 'timeout'.
* OS_ERR_PEND_ISR If you tried to PEND from an ISR
* OS_FLAG_INVALID_PGRP If 'pgrp' is a NULL pointer.
* OS_ERR_EVENT_TYPE You are not pointing to an event flag group
* OS_TIMEOUT The bit(s) have not been set in the specified
* 'timeout'.
* OS_FLAG_ERR_WAIT_TYPE You didn't specify a proper 'wait_type' argument.
*
* Returns : The new state of the flags in the event flag group when the task is resumed or,
* 0 if a timeout or an error occurred.
*
* Called from: Task ONLY
*********************************************************************************************************
*/
OS_FLAGS OSFlagPend (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT16U timeout, INT8U *err) KCRE
-ENTRANT
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OS_FLAG_NODE node;
OS_FLAGS flags_cur;
OS_FLAGS flags_rdy;
BOOLEAN consume;
if (OSIntNesting > 0) { /* See if called from ISR ... */
*err = OS_ERR_PEND_ISR; /* ... can't PEND from an ISR */
return ((OS_FLAGS)0);
}
#if OS_ARG_CHK_EN > 0
if (pgrp == (OS_FLAG_GRP *)0) { /* Validate 'pgrp' */
*err = OS_FLAG_INVALID_PGRP;
return ((OS_FLAGS)0);
}
#endif
if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Validate event block type */
*err = OS_ERR_EVENT_TYPE;
return ((OS_FLAGS)0);
}
if (wait_type & OS_FLAG_CONSUME) { /* See if we need to consume the flags */
wait_type &= ~OS_FLAG_CONSUME;
consume = TRUE;
} else {
consume = FALSE;
}
/*$PAGE*/
OS_ENTER_CRITICAL();
switch (wait_type) {
case OS_FLAG_WAIT_SET_ALL: /* See if all required flags are set */
flags_rdy = pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
if (flags_rdy == flags) { /* Must match ALL the bits that we want */
if (consume == TRUE) { /* See if we need to consume the flags */
pgrp->OSFlagFlags &= ~flags_rdy; /* Clear ONLY the flags that we wanted */
}
C51 COMPILER V8.05a OS_FLAG 04/11/2007 16:19:49 PAGE 10
OSTCBCur->OSTCBFlagsRdy = flags_rdy; /* Save flags that were ready */
flags_cur = pgrp->OSFlagFlags; /* Will return the state of the group */
OS_EXIT_CRITICAL(); /* Yes, condition met, return to caller */
*err = OS_NO_ERR;
return (flags_cur);
} else { /* Block task until events occur or timeout */
OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
OS_EXIT_CRITICAL();
}
break;
case OS_FLAG_WAIT_SET_ANY:
flags_rdy = pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
if (flags_rdy != (OS_FLAGS)0) { /* See if any flag set */
if (consume == TRUE) { /* See if we need to consume the flags */
pgrp->OSFlagFlags &= ~flags_rdy; /* Clear ONLY the flags that we got */
}
OSTCBCur->OSTCBFlagsRdy = flags_rdy; /* Save flags that were ready */
flags_cur = pgrp->OSFlagFlags; /* Will return the state of the group */
OS_EXIT_CRITICAL(); /* Yes, condition met, return to caller */
*err = OS_NO_ERR;
return (flags_cur);
} else { /* Block task until events occur or timeout */
OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
OS_EXIT_CRITICAL();
}
break;
#if OS_FLAG_WAIT_CLR_EN > 0
case OS_FLAG_WAIT_CLR_ALL: /* See if all required flags are cleared */
flags_rdy = ~pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
if (flags_rdy == flags) { /* Must match ALL the bits that we want */
if (consume == TRUE) { /* See if we need to consume the flags */
pgrp->OSFlagFlags |= flags_rdy; /* Set ONLY the flags that we wanted */
}
OSTCBCur->OSTCBFlagsRdy = flags_rdy; /* Save flags that were ready */
flags_cur = pgrp->OSFlagFlags; /* Will return the state of the group */
OS_EXIT_CRITICAL(); /* Yes, condition met, return to caller */
*err = OS_NO_ERR;
return (flags_cur);
} else { /* Block task until events occur or timeout */
OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
OS_EXIT_CRITICAL();
}
break;
case OS_FLAG_WAIT_CLR_ANY:
flags_rdy = ~pgrp->OSFlagFlags & flags; /* Extract only the bits we want */
if (flags_rdy != (OS_FLAGS)0) { /* See if any flag cleared */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -