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
29
30
31
32
33
34
35
38
39
40
41
42
44
60
61
63
67
68
70
75
76
85
86
90
91
95
96
/* ... */
#include "osi/mutex.h"
static osi_mutex_t gl_mutex;
/* ... */
int osi_mutex_new(osi_mutex_t *mutex)
{
int xReturn = -1;
*mutex = xSemaphoreCreateMutex();
if (*mutex != NULL) {
xReturn = 0;
}{...}
return xReturn;
}{ ... }
/* ... */
int osi_mutex_lock(osi_mutex_t *mutex, uint32_t timeout)
{
int ret = 0;
if (timeout == OSI_MUTEX_MAX_TIMEOUT) {
if (xSemaphoreTake(*mutex, portMAX_DELAY) != pdTRUE) {
ret = -1;
}{...}
}{...} else {
if (xSemaphoreTake(*mutex, timeout / portTICK_PERIOD_MS) != pdTRUE) {
ret = -2;
}{...}
}{...}
return ret;
}{ ... }
/* ... */
void osi_mutex_unlock(osi_mutex_t *mutex)
{
xSemaphoreGive(*mutex);
}{ ... }
/* ... */
void osi_mutex_free(osi_mutex_t *mutex)
{
vSemaphoreDelete(*mutex);
*mutex = NULL;
}{ ... }
int osi_mutex_global_init(void)
{
gl_mutex = xSemaphoreCreateRecursiveMutex();
if (gl_mutex == NULL) {
return -1;
}{...}
return 0;
}{ ... }
void osi_mutex_global_deinit(void)
{
vSemaphoreDelete(gl_mutex);
}{ ... }
void osi_mutex_global_lock(void)
{
xSemaphoreTakeRecursive(gl_mutex, portMAX_DELAY);
}{ ... }
void osi_mutex_global_unlock(void)
{
xSemaphoreGiveRecursive(gl_mutex);
}{ ... }