1 /*
2  * Copyright 2017, NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef __SRTM_SEM_H__
10 #define __SRTM_SEM_H__
11 
12 #include <srtm_defs.h>
13 
14 /*!
15  * @addtogroup srtm
16  * @{
17  */
18 
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 /**
23  * @brief SRTM semaphore handle
24  */
25 typedef void *srtm_sem_t;
26 
27 /*******************************************************************************
28  * API
29  ******************************************************************************/
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /*!
35  * @brief Create a semaphore.
36  *
37  * @param maxCount maximum count value of the semaphore.
38  * @param initCount initial count value of the semaphore.
39  * @param stack Stack for semaphore data.
40  * @return Created semaphore handle, or NULL on failure.
41  */
42 #if defined(SRTM_STATIC_API) && SRTM_STATIC_API
43 srtm_sem_t SRTM_Sem_Create(uint32_t maxCount, uint32_t initCount, srtm_sem_buf_t *stack);
44 #else
45 srtm_sem_t SRTM_Sem_Create(uint32_t maxCount, uint32_t initCount);
46 #endif
47 
48 /*!
49  * @brief Destroy the semaphore.
50  *
51  * @param sem The semaphore to destroy.
52  */
53 void SRTM_Sem_Destroy(srtm_sem_t sem);
54 
55 /*!
56  * @brief Posts a semaphore.
57  *
58  * @param sem Semaphore handle
59  * @return SRTM_Status_Success on success and others on failure.
60  */
61 srtm_status_t SRTM_Sem_Post(srtm_sem_t sem);
62 
63 /*!
64  * @brief Waits on a semaphore.
65  *
66  * @param sem Semaphore handle
67  * @param timeout   The maximum milliseconds to wait for the semaphore.
68  * @return SRTM_Status_Success on success, SRTM_Status_Timeout on timeout.
69  */
70 srtm_status_t SRTM_Sem_Wait(srtm_sem_t sem, uint32_t timeout);
71 
72 #ifdef __cplusplus
73 }
74 #endif
75 
76 /*! @} */
77 
78 #endif /* __SRTM_SEM_H__ */
79