-
Notifications
You must be signed in to change notification settings - Fork 1
/
chry_mempool_osal_freertos.c
54 lines (46 loc) · 1.32 KB
/
chry_mempool_osal_freertos.c
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright (c) 2024, sakumisu
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "chry_mempool.h"
#include <FreeRTOS.h>
#include "semphr.h"
chry_mempool_osal_sem_t chry_mempool_osal_sem_create(uint32_t max_count)
{
return (chry_mempool_osal_sem_t)xSemaphoreCreateCounting(max_count, 0);
}
void chry_mempool_osal_sem_delete(chry_mempool_osal_sem_t sem)
{
vSemaphoreDelete((SemaphoreHandle_t)sem);
}
int chry_mempool_osal_sem_take(chry_mempool_osal_sem_t sem, uint32_t timeout)
{
if (timeout == 0xffffffff) {
return (xSemaphoreTake((SemaphoreHandle_t)sem, portMAX_DELAY) == pdPASS) ? 0 : -1;
} else {
return (xSemaphoreTake((SemaphoreHandle_t)sem, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -1;
}
}
int chry_mempool_osal_sem_give(chry_mempool_osal_sem_t sem)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
int ret;
if (xPortIsInsideInterrupt()) {
ret = xSemaphoreGiveFromISR((SemaphoreHandle_t)sem, &xHigherPriorityTaskWoken);
if (ret == pdPASS) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
} else {
ret = xSemaphoreGive((SemaphoreHandle_t)sem);
}
return (ret == pdPASS) ? 0 : -1;
}
void *chry_mempool_osal_malloc(size_t size)
{
return pvPortMalloc(size);
}
void chry_mempool_osal_free(void *ptr)
{
vPortFree(ptr);
}