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_MAX32680_SEMA_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32680_SEMA_H_ 29 30 /* **** Includes **** */ 31 #include "mxc_device.h" 32 #include "mxc_sys.h" 33 #include "sema_regs.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** 40 * @defgroup sema Semaphore (SEMA) 41 * @ingroup periphlibs 42 * @{ 43 */ 44 45 /* **** Function Prototypes **** */ 46 47 /** 48 * @brief Initialize the semaphore peripheral 49 * @return #E_NO_ERROR if semaphore acquired. 50 */ 51 int MXC_SEMA_Init(void); 52 53 /** 54 * @brief Attempt to get a semaphore. 55 * @param sema Number of semaphore you are trying to get. 56 * @return #E_NO_ERROR if semaphore acquired. #E_BUSY if semaphore is already locked. 57 */ 58 int MXC_SEMA_GetSema(unsigned sema); 59 60 /** 61 * @brief Check a semaphore. 62 * @param sema Number of semaphore you want to check. 63 * @return #E_NO_ERROR if semaphore is free. #E_BUSY if semaphore is already locked. 64 * @note Will not be atomic if you call this function and then attempt to MXC_SEMA_GetSema(). 65 */ 66 int MXC_SEMA_CheckSema(unsigned sema); 67 68 /** 69 * @brief Check all semaphores. 70 * @return Status of all semaphores. Each semaphore will be represented by 1 bit. 71 * @note Will not be atomic if you call this function and then attempt to MXC_SEMA_GetSema(). 72 */ 73 uint32_t MXC_SEMA_Status(void); 74 75 /** 76 * @brief Frees the semaphore. 77 * @param sema Number of semaphore want to free. 78 */ 79 void MXC_SEMA_FreeSema(unsigned sema); 80 81 /** 82 * @brief Shutdown the semaphore peripheral 83 * @return #E_NO_ERROR if semaphore released. 84 */ 85 int MXC_SEMA_Shutdown(void); 86 87 /**@} end of group sema */ 88 89 #ifdef __cplusplus 90 } 91 #endif 92 93 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32680_SEMA_H_ 94