1 /**
2  * @file    sema.h
3  * @brief   Semaphore (SEMA) function prototypes and data types.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 /* Define to prevent redundant inclusion */
27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_SEMA_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_SEMA_H_
29 
30 /* **** Includes **** */
31 #include "mxc_sys.h"
32 #include "sema_regs.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /**
39  * @defgroup sema Semaphore (SEMA)
40  * @ingroup periphlibs
41  * @{
42  */
43 
44 /* **** Definitions **** */
45 
46 /* **** Function Prototypes **** */
47 
48 /**
49  * @brief     Initialize the semaphore peripheral
50  * @return    #E_NO_ERROR if semaphore acquired.
51  */
52 int MXC_SEMA_Init(void);
53 
54 /**
55  * @brief     Attempt to get a semaphore.
56  * @param     sema   Number of semaphore you are trying to get.
57  * @return    #E_NO_ERROR if semaphore acquired. #E_BUSY if semaphore is already locked.
58  */
59 int MXC_SEMA_GetSema(unsigned sema);
60 
61 /**
62  * @brief     Check a semaphore.
63  * @param     sema   Number of semaphore you want to check.
64  * @return    #E_NO_ERROR if semaphore is free. #E_BUSY if semaphore is already locked.
65  * @note      Will not be atomic if you call this function and then attempt to SEMA_GetSema().
66  */
67 int MXC_SEMA_CheckSema(unsigned sema);
68 
69 /**
70  * @brief     Check all semaphores.
71  * @return    Status of all semaphores. Each semaphore will be represented by 1 bit.
72  * @note      Will not be atomic if you call this function and then attempt to SEMA_GetSema().
73  */
74 uint32_t MXC_SEMA_Status(void);
75 
76 /**
77  * @brief     Frees the semaphore.
78  * @param     sema   Number of semaphore want to free.
79  */
80 void MXC_SEMA_FreeSema(unsigned sema);
81 
82 /**
83  * @brief     Shutdown the semaphore peripheral
84  * @return    #E_NO_ERROR if semaphore acquired.
85  */
86 int MXC_SEMA_Shutdown(void);
87 
88 /**@} end of group sema */
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_SEMA_H_
95