Zephyr Project API 4.0.0
A Scalable Open Source RTOS
|
Macros | |
#define | SYS_SEM_DEFINE(_name, _initial_count, _count_limit) |
Statically define and initialize a sys_sem. | |
#define | SYS_SEM_LOCK_BREAK continue |
Leaves a code block guarded with SYS_SEM_LOCK after releasing the lock. | |
#define | SYS_SEM_LOCK(sem) |
Guards a code block with the given sys_sem, automatically acquiring the semaphore before executing the code block. | |
Functions | |
int | sys_sem_init (struct sys_sem *sem, unsigned int initial_count, unsigned int limit) |
Initialize a semaphore. | |
int | sys_sem_give (struct sys_sem *sem) |
Give a semaphore. | |
int | sys_sem_take (struct sys_sem *sem, k_timeout_t timeout) |
Take a sys_sem. | |
unsigned int | sys_sem_count_get (struct sys_sem *sem) |
Get sys_sem's value. | |
#define SYS_SEM_DEFINE | ( | _name, | |
_initial_count, | |||
_count_limit | |||
) |
#include <include/zephyr/sys/sem.h>
Statically define and initialize a sys_sem.
The semaphore can be accessed outside the module where it is defined using:
Route this to memory domains using K_APP_DMEM().
_name | Name of the semaphore. |
_initial_count | Initial semaphore count. |
_count_limit | Maximum permitted semaphore count. |
#define SYS_SEM_LOCK | ( | sem | ) |
#include <include/zephyr/sys/sem.h>
Guards a code block with the given sys_sem, automatically acquiring the semaphore before executing the code block.
The semaphore will be released either when reaching the end of the code block or when leaving the block with SYS_SEM_LOCK_BREAK.
Example usage:
Behind the scenes this pattern expands to a for-loop whose body is executed exactly once:
sem | Semaphore (sys_sem) used to guard the enclosed code block. |
#define SYS_SEM_LOCK_BREAK continue |
#include <include/zephyr/sys/sem.h>
Leaves a code block guarded with SYS_SEM_LOCK after releasing the lock.
See SYS_SEM_LOCK for details.
#include <include/zephyr/sys/sem.h>
Get sys_sem's value.
This routine returns the current value of sem.
sem | Address of the sys_sem. |
int sys_sem_give | ( | struct sys_sem * | sem | ) |
#include <include/zephyr/sys/sem.h>
Give a semaphore.
This routine gives sem, unless the semaphore is already at its maximum permitted count.
sem | Address of the semaphore. |
0 | Semaphore given. |
-EINVAL | Parameter address not recognized. |
-EACCES | Caller does not have enough access. |
-EAGAIN | Count reached Maximum permitted count and try again. |
#include <include/zephyr/sys/sem.h>
Initialize a semaphore.
This routine initializes a semaphore instance, prior to its first use.
sem | Address of the semaphore. |
initial_count | Initial semaphore count. |
limit | Maximum permitted semaphore count. |
0 | Initial success. |
-EINVAL | Bad parameters, the value of limit should be located in (0, INT_MAX] and initial_count shouldn't be greater than limit. |
int sys_sem_take | ( | struct sys_sem * | sem, |
k_timeout_t | timeout | ||
) |
#include <include/zephyr/sys/sem.h>
Take a sys_sem.
This routine takes sem.
sem | Address of the sys_sem. |
timeout | Waiting period to take the sys_sem, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | sys_sem taken. |
-EINVAL | Parameter address not recognized. |
-ETIMEDOUT | Waiting period timed out. |
-EACCES | Caller does not have enough access. |