OSFlagPost()
OS_FLAGS OSFlagPost (OS_FLAG_GRP *p_grp,
OS_FLAGS flags,
OS_OPT opt,
OS_ERR *p_err)
File |
Called from |
Code enabled by |
os_flag.c |
Task or ISR |
OS_CFG_FLAG_EN |
You can set or clear event flag bits by calling OSFlagPost(). The bits set or cleared are specified in a bit mask (i.e., the flags argument). OSFlagPost() readies each task that has its desired bits satisfied by this call. The caller can set or clear bits that are already set or cleared.
Arguments
p_grp
is a pointer to the event flag group.
flags
specifies which bits to be set or cleared. If opt is OS_OPT_POST_FLAG_SET, each bit that is set in flags will set the corresponding bit in the event flag group. For example to set bits 0, 4, and 5, you would set flags to 0x31 (note that bit 0 is the least significant bit). If opt is OS_OPT_POST_FLAG_CLR, each bit that is set in flags will clear the corresponding bit in the event flag group. For example to clear bits 0, 4, and 5, you would specify flags as 0x31 (again, bit 0 is the least significant bit).
opt
indicates whether the flags are set (OS_OPT_POST_FLAG_SET) or cleared (OS_OPT_POST_FLAG_CLR).
The caller may also “add” OS_OPT_POST_NO_SCHED so that µC/OS-III will not call the scheduler after the post.
p_err
is a pointer to an error code and can be:
Returned Value
The new value of the event flags.
Notes/Warnings
- Event flag groups must be created before they are used.
- The execution time of this function depends on the number of tasks waiting on the event flag group. However, the execution time is still deterministic.
- Although the example below shows that we are posting from a task, OSFlagPost() can also be called from an ISR.
Example
#define ENGINE_OIL_PRES_OK 0x01 #define ENGINE_OIL_TEMP_OK 0x02 #define ENGINE_START 0x04
OS_FLAG_GRP EngineStatusFlags;
void TaskX (void *p_arg) { OS_ERR err; OS_FLAGS flags;
(void)&p_arg; while (DEF_ON) { : : flags = OSFlagPost(&EngineStatusFlags, ENGINE_START, OS_OPT_POST_FLAG_SET, &err); /* Check ’err” */ : : } } |