From d478152762013975551e1af154df42987596c9a6 Mon Sep 17 00:00:00 2001 From: Caoruihong Date: Tue, 10 Aug 2021 23:10:30 +0800 Subject: [PATCH] feat(cmsis): support max_count for osSemaphoreNew Signed-off-by: Caoruihong Change-Id: Iacb6cb7771ae32ea1ca645c72fda241e8e85d422 --- kal/cmsis/cmsis_liteos2.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kal/cmsis/cmsis_liteos2.c b/kal/cmsis/cmsis_liteos2.c index 19f11903..afe7a8b1 100644 --- a/kal/cmsis/cmsis_liteos2.c +++ b/kal/cmsis/cmsis_liteos2.c @@ -1087,8 +1087,9 @@ osStatus_t osMutexDelete(osMutexId_t mutex_id) osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) { - UINT32 uwRet; + UINT32 uwRet = LOS_NOK; UINT32 uwSemId; + UINT32 intSave; UNUSED(attr); @@ -1096,14 +1097,16 @@ osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const return (osSemaphoreId_t)NULL; } - if (1 == max_count) { - uwRet = LOS_BinarySemCreate((UINT16)initial_count, &uwSemId); - } else { + if (max_count > 0 && max_count <= OS_SEM_COUNTING_MAX_COUNT) { uwRet = LOS_SemCreate((UINT16)initial_count, &uwSemId); } if (uwRet == LOS_OK) { - return (osSemaphoreId_t)(GET_SEM(uwSemId)); + osSemaphoreId_t semaphore_id = (osSemaphoreId_t)(GET_SEM(uwSemId)); + intSave = LOS_IntLock(); + ((LosSemCB *)semaphore_id)->maxSemCount = max_count; + LOS_IntRestore(intSave); + return semaphore_id; } else { return (osSemaphoreId_t)NULL; }