-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
199 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2024, sakumisu | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include "chry_mempool.h" | ||
#include "stdlib.h" | ||
|
||
chry_mempool_osal_sem_t chry_mempool_osal_sem_create(uint32_t max_count) | ||
{ | ||
return (chry_mempool_osal_sem_t)1; | ||
} | ||
|
||
void chry_mempool_osal_sem_delete(chry_mempool_osal_sem_t sem) | ||
{ | ||
} | ||
|
||
int chry_mempool_osal_sem_take(chry_mempool_osal_sem_t sem, uint32_t timeout) | ||
{ | ||
return 0; | ||
} | ||
|
||
int chry_mempool_osal_sem_give(chry_mempool_osal_sem_t sem) | ||
{ | ||
return 0; | ||
} | ||
|
||
void *chry_mempool_osal_malloc(size_t size) | ||
{ | ||
return malloc(size); | ||
} | ||
|
||
void chry_mempool_osal_free(void *ptr) | ||
{ | ||
free(ptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2024, sakumisu | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include "chry_mempool.h" | ||
#include <rtthread.h> | ||
#include <rthw.h> | ||
|
||
chry_mempool_osal_sem_t chry_mempool_osal_sem_create(uint32_t max_count) | ||
{ | ||
return (chry_mempool_osal_sem_t)rt_sem_create("chry_mempoolh_sem", max_count, RT_IPC_FLAG_FIFO); | ||
} | ||
|
||
void chry_mempool_osal_sem_delete(chry_mempool_osal_sem_t sem) | ||
{ | ||
rt_sem_delete((rt_sem_t)sem); | ||
} | ||
|
||
int chry_mempool_osal_sem_take(chry_mempool_osal_sem_t sem, uint32_t timeout) | ||
{ | ||
int ret = 0; | ||
rt_err_t result = RT_EOK; | ||
|
||
if (timeout == 0xfffffff) { | ||
result = rt_sem_take((rt_sem_t)sem, RT_WAITING_FOREVER); | ||
} else { | ||
result = rt_sem_take((rt_sem_t)sem, rt_tick_from_millisecond(timeout)); | ||
} | ||
if (result == -RT_ETIMEOUT) { | ||
ret = -1; | ||
} else if (result == -RT_ERROR) { | ||
ret = -1; | ||
} else { | ||
ret = 0; | ||
} | ||
|
||
return (int)ret; | ||
} | ||
|
||
int chry_mempool_osal_sem_give(chry_mempool_osal_sem_t sem) | ||
{ | ||
return (int)rt_sem_release((rt_sem_t)sem); | ||
} | ||
|
||
void *chry_mempool_osal_malloc(size_t size) | ||
{ | ||
return rt_malloc(size); | ||
} | ||
|
||
void chry_mempool_osal_free(void *ptr) | ||
{ | ||
rt_free(ptr); | ||
} |