...
Files
os.h/os_sem.c
Prototype
Code Block |
---|
void OSSemCreate (OS_SEM *p_sem,
CPU_CHAR *p_name,
OS_SEM_CTR cnt,
OS_ERR *p_err) |
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()
:
...
- Semaphores must be created before they are used.
Example Usage
Code Block | ||
---|---|---|
| ||
OS_SEM SwSem;
void main (void)
{
OS_ERR err;
:
OSInit(&err); /* Initialize µC/OS-III */
:
:
OSSemCreate(&SwSem, /* Create Switch Semaphore */
"Switch Semaphore",
0,
&err);
/* Check "err" */
:
:
OSStart(&err); /* Start Multitasking */
} |