...
Files
os.h/os_sem.c
Prototype
Code Block |
---|
OS_SEM_CTR OSSemPost (OS_SEM *p_sem,
OS_OPT opt,
OS_ERR *p_err) |
Arguments
p_sem
is a pointer to the semaphore.
...
If OS_CFG_ARG_CHK_EN
is set to 1
DEF_ENABLED
in os_cfg.h
: if p_sem
is a NULL
pointer.
...
If OS_CFG_OBJ_TYPE_CHK_EN
is set to 1
in DEF_ENABLED
in os_cfg.h
: if p_sem
is not pointing to a semaphore.
OS_ERR_OPT_INVALID
If OS_CFG_ARG_CHK_EN
is set to DEF_ENABLED
in os_cfg.h
: if a valid option is not specified.
OS_ERR_OS_NOT_RUNNING
If OS_CFG_INVALID_OS_CALLS_CHK_EN
is set to DEF_ENABLED
in os_cfg.h
: if µC/OS-III is not running yet.
OS_ERR_SEM_OVF
If the post would have caused the semaphore counter to overflow.
...
OS_CFG_SEM_EN
must be enabled in os_cfg.h
. Refer to uCµC-OS-III Configuration Manual.
Callers
Application and ISRs.
...
- Semaphores must be created before they are used.
- You can also post to a semaphore from an ISR but the semaphore must be used as a signaling mechanism and not to protect a shared resource.
Example Usage
Code Block | ||
---|---|---|
| ||
OS_SEM SwSem;
void TaskX (void *p_arg)
{
OS_ERR err;
OS_SEM_CTR ctr;
(void)&p_arg;
while (DEF_ON) {
:
:
ctr = OSSemPost(&SwSem,
OS_OPT_POST_1 + OS_OPT_POST_NO_SCHED,
&err);
/* Check "err" */
:
:
}
} |