1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
39
40
41
42
46
47
54
55
71
72
73
/* ... */
#include "osi/semaphore.h"
int osi_sem_new(osi_sem_t *sem, uint32_t max_count, uint32_t init_count)
{
int ret = -1;
if (sem) {
*sem = xSemaphoreCreateCounting(max_count, init_count);
if ((*sem) != NULL) {
ret = 0;
}{...}
}{...}
return ret;
}{ ... }
void osi_sem_give(osi_sem_t *sem)
{
xSemaphoreGive(*sem);
}{ ... }
/* ... */
int
osi_sem_take(osi_sem_t *sem, uint32_t timeout)
{
int ret = 0;
if (timeout == OSI_SEM_MAX_TIMEOUT) {
if (xSemaphoreTake(*sem, portMAX_DELAY) != pdTRUE) {
ret = -1;
}{...}
}{...} else {
if (xSemaphoreTake(*sem, timeout / portTICK_PERIOD_MS) != pdTRUE) {
ret = -2;
}{...}
}{...}
return ret;
}{ ... }
void osi_sem_free(osi_sem_t *sem)
{
vSemaphoreDelete(*sem);
*sem = NULL;
}{ ... }