void OSSemCreate (OS_SEM *p_sem,
CPU_CHAR *p_name,
OS_SEM_CTR cnt,
OS_ERR *p_err)
File | Called from | Code enabled by |
---|---|---|
| Task or startup code |
|
...
Description
Initializes a semaphore. Semaphores are used when a task wants exclusive access to a resource, needs to synchronize its activities with an ISR or a task, or is waiting until an event occurs. You would use a semaphore to signal the occurrence of an event to one or multiple tasks, and use mutexes to guard share resources. However, technically, semaphores allow for both.
Files
os.h/os_sem.c
Prototype
Arguments
p_sem
is a pointer to the semaphore control block. It is assumed that storage for the semaphore will be allocated in the application. In other words, you need to declare a “global” variable as follows, and pass a pointer to this variable to OSSemCreate()
:
...
If OS_SAFETY_CRITICAL_IEC61508
is defined: you called this after calling OSSafetyCriticalStart()
and thus you are no longer allowed to create additional kernel objects.
Returned Value
None
Required Configuration
OS_CFG_SEM_EN
must be enabled in os_cfg.h. Refer to uC-OS-III Configuration Manual
Callers
Application.
Notes/Warnings
- Semaphores must be created before they are used.