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_MAX32665_SEMA_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_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 /* **** Definitions **** */ 46 47 /* **** Function Prototypes **** */ 48 49 /** 50 * @brief Initialize the semaphore peripheral 51 * @return #E_NO_ERROR if semaphore acquired. 52 */ 53 int MXC_SEMA_Init(void); 54 55 /** 56 * @brief Attempt to get a semaphore. 57 * @param sema Number of semaphore you are trying to get. 58 * @return #E_NO_ERROR if semaphore acquired. #E_BUSY if semaphore is already locked. 59 */ 60 int MXC_SEMA_GetSema(unsigned sema); 61 62 /** 63 * @brief Check a semaphore. 64 * @param sema Number of semaphore you want to check. 65 * @return #E_NO_ERROR if semaphore is free. #E_BUSY if semaphore is already locked. 66 * @note Will not be atomic if you call this function and then attempt to MXC_SEMA_GetSema(). 67 */ 68 int MXC_SEMA_CheckSema(unsigned sema); 69 70 /** 71 * @brief Check all semaphores. 72 * @return Status of all semaphores. Each semaphore will be represented by 1 bit. 73 * @note Will not be atomic if you call this function and then attempt to MXC_SEMA_GetSema(). 74 */ 75 uint32_t MXC_SEMA_Status(void); 76 77 /** 78 * @brief Frees the semaphore. 79 * @param sema Number of semaphore want to free. 80 */ 81 void MXC_SEMA_FreeSema(unsigned sema); 82 83 /** 84 * @brief Shutdown the semaphore peripheral 85 * @return #E_NO_ERROR if semaphore released. 86 */ 87 int MXC_SEMA_Shutdown(void); 88 89 /**@} end of group sema */ 90 91 #ifdef __cplusplus 92 } 93 #endif 94 95 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_SEMA_H_ 96