Zephyr API Documentation
3.6.99
A Scalable Open Source RTOS
|
Macros | |
#define | K_SEM_MAX_LIMIT UINT_MAX |
Maximum limit value allowed for a semaphore. | |
#define | K_SEM_DEFINE(name, initial_count, count_limit) |
Statically define and initialize a semaphore. | |
Functions | |
int | k_sem_init (struct k_sem *sem, unsigned int initial_count, unsigned int limit) |
Initialize a semaphore. | |
int | k_sem_take (struct k_sem *sem, k_timeout_t timeout) |
Take a semaphore. | |
void | k_sem_give (struct k_sem *sem) |
Give a semaphore. | |
void | k_sem_reset (struct k_sem *sem) |
Resets a semaphore's count to zero. | |
unsigned int | k_sem_count_get (struct k_sem *sem) |
Get a semaphore's count. | |
#define K_SEM_DEFINE | ( | name, | |
initial_count, | |||
count_limit | |||
) |
#include <zephyr/kernel.h>
Statically define and initialize a semaphore.
The semaphore can be accessed outside the module where it is defined using:
name | Name of the semaphore. |
initial_count | Initial semaphore count. |
count_limit | Maximum permitted semaphore count. |
#define K_SEM_MAX_LIMIT UINT_MAX |
#include <zephyr/kernel.h>
Maximum limit value allowed for a semaphore.
This is intended for use when a semaphore does not have an explicit maximum limit, and instead is just used for counting purposes.
unsigned int k_sem_count_get | ( | struct k_sem * | sem | ) |
#include <zephyr/kernel.h>
Get a semaphore's count.
This routine returns the current count of sem.
sem | Address of the semaphore. |
void k_sem_give | ( | struct k_sem * | sem | ) |
#include <zephyr/kernel.h>
Give a semaphore.
This routine gives sem, unless the semaphore is already at its maximum permitted count.
sem | Address of the semaphore. |
#include <zephyr/kernel.h>
Initialize a semaphore.
This routine initializes a semaphore object, prior to its first use.
sem | Address of the semaphore. |
initial_count | Initial semaphore count. |
limit | Maximum permitted semaphore count. |
0 | Semaphore created successfully |
-EINVAL | Invalid values |
void k_sem_reset | ( | struct k_sem * | sem | ) |
#include <zephyr/kernel.h>
Resets a semaphore's count to zero.
This routine sets the count of sem to zero. Any outstanding semaphore takes will be aborted with -EAGAIN.
sem | Address of the semaphore. |
int k_sem_take | ( | struct k_sem * | sem, |
k_timeout_t | timeout | ||
) |
#include <zephyr/kernel.h>
Take a semaphore.
This routine takes sem.
sem | Address of the semaphore. |
timeout | Waiting period to take the semaphore, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Semaphore taken. |
-EBUSY | Returned without waiting. |
-EAGAIN | Waiting period timed out, or the semaphore was reset during the waiting period. |