1 /* 2 * Copyright 2017, NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #include <FreeRTOS.h> 10 #include <semphr.h> 11 12 #include "srtm_mutex.h" 13 14 /******************************************************************************* 15 * Definitions 16 ******************************************************************************/ 17 18 /******************************************************************************* 19 * Prototypes 20 ******************************************************************************/ 21 22 /******************************************************************************* 23 * Variables 24 ******************************************************************************/ 25 26 /******************************************************************************* 27 * Code 28 ******************************************************************************/ 29 #if defined(SRTM_STATIC_API) && SRTM_STATIC_API SRTM_Mutex_Create(srtm_mutex_buf_t * stack)30srtm_mutex_t SRTM_Mutex_Create(srtm_mutex_buf_t *stack) 31 { 32 return xSemaphoreCreateMutexStatic(stack); 33 } 34 #else SRTM_Mutex_Create(void)35srtm_mutex_t SRTM_Mutex_Create(void) 36 { 37 return xSemaphoreCreateMutex(); 38 } 39 #endif 40 SRTM_Mutex_Destroy(srtm_mutex_t mutex)41void SRTM_Mutex_Destroy(srtm_mutex_t mutex) 42 { 43 assert(mutex != NULL); 44 45 vSemaphoreDelete(mutex); 46 } 47 SRTM_Mutex_Lock(srtm_mutex_t mutex)48srtm_status_t SRTM_Mutex_Lock(srtm_mutex_t mutex) 49 { 50 assert(mutex != NULL); 51 52 if (xSemaphoreTake(mutex, portMAX_DELAY) == pdFALSE) 53 { 54 return SRTM_Status_Error; 55 } 56 57 return SRTM_Status_Success; 58 } 59 SRTM_Mutex_Unlock(srtm_mutex_t mutex)60srtm_status_t SRTM_Mutex_Unlock(srtm_mutex_t mutex) 61 { 62 assert(mutex != NULL); 63 64 if (xSemaphoreGive(mutex) == pdFALSE) 65 { 66 return SRTM_Status_Error; 67 } 68 69 return SRTM_Status_Success; 70 } 71