1 /***************************************************************************//** 2 * \file cy_ipc_sema.h 3 * \version 1.91 4 * 5 * \brief 6 * Header file for IPC SEM functions 7 * 8 ******************************************************************************** 9 * \copyright 10 * Copyright (c) (2020-2022), Cypress Semiconductor Corporation (an Infineon company) or 11 * an affiliate of Cypress Semiconductor Corporation. 12 * SPDX-License-Identifier: Apache-2.0 13 * 14 * Licensed under the Apache License, Version 2.0 (the "License"); 15 * you may not use this file except in compliance with the License. 16 * You may obtain a copy of the License at 17 * 18 * http://www.apache.org/licenses/LICENSE-2.0 19 * 20 * Unless required by applicable law or agreed to in writing, software 21 * distributed under the License is distributed on an "AS IS" BASIS, 22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 * See the License for the specific language governing permissions and 24 * limitations under the License. 25 *******************************************************************************/ 26 27 #ifndef CY_IPC_SEMA_H 28 #define CY_IPC_SEMA_H 29 30 /******************************************************************************/ 31 /* Include files */ 32 /******************************************************************************/ 33 34 #include "cy_device.h" 35 36 #if defined (CY_IP_M4CPUSS) || defined (CY_IP_M7CPUSS) || (defined (CY_IP_MXIPC) && (CY_IPC_INSTANCES > 1U)) 37 38 #include "cy_ipc_drv.h" 39 #include <stdbool.h> 40 41 /** 42 * \addtogroup group_ipc_sema IPC semaphores layer (IPC_SEMA) 43 * \{ 44 * The semaphores layer functions made use of a single IPC channel to allow 45 * multiple semaphores that can be used by system or user function calls. 46 * 47 * Include cy_ipc_sema.h. Alternatively include cy_pdl.h 48 * to get access to all functions and declarations in the PDL. 49 * 50 * By default, there are 128 semaphores provided, although the user may modify 51 * the default value to any number, limited only by SRAM. 52 * 53 * \defgroup group_ipc_sema_macros Macros 54 * Macro definitions are used in the driver 55 * 56 * \defgroup group_ipc_sema_functions Functions 57 * Functions are used in the driver 58 * 59 * \defgroup group_ipc_sema_enums Enumerated Types 60 * Enumerations are used in the driver 61 * \} 62 * 63 * \addtogroup group_ipc_sema_macros 64 * \{ 65 */ 66 67 /** Software PDL driver ID for IPC semaphore functions */ 68 #define CY_IPC_SEMA_RTN (0x0100UL) 69 /** Return prefix for IPC semaphore function status codes */ 70 #define CY_IPC_SEMA_ID_INFO (uint32_t)( CY_IPC_ID_INFO | CY_IPC_SEMA_RTN) 71 /** Return prefix for IPC semaphore function warning return values */ 72 #define CY_IPC_SEMA_ID_WARNING (uint32_t)( CY_IPC_ID_WARNING | CY_IPC_SEMA_RTN) 73 /** Return prefix for IPC semaphore function error return values */ 74 #define CY_IPC_SEMA_ID_ERROR (uint32_t)( CY_IPC_ID_ERROR | CY_IPC_SEMA_RTN) 75 76 #define CY_IPC_SEMA_PER_WORD (uint32_t)32u /**< 32 semaphores per word */ 77 78 #if defined(CY_IPC_SECURE_SEMA_DEVICE) || defined(CY_DOXYGEN) 79 /** Convert normal to secure semaphore number */ 80 #define CY_IPC_SEMA_SEC(sema) (0x10000000UL | (sema)) 81 /** Check valid secure semaphore */ 82 #define CY_IPC_SEMA_IS_SEC(sema) (((sema) & 0x10000000UL) != 0UL) 83 /** Returns normal semaphore number */ 84 #define CY_IPC_SEMA_GET_NUM(sema) ((sema) & (~(0x10000000UL))) 85 #endif /* CY_IPC_SECURE_SEMA_DEVICE */ 86 87 /** \} group_ipc_sema_macros */ 88 89 /** 90 * \addtogroup group_ipc_sema_enums 91 * \{ 92 */ 93 94 /** Return constants for IPC semaphores functions. */ 95 typedef enum 96 { 97 /** No error has occurred */ 98 CY_IPC_SEMA_SUCCESS = (uint32_t)(0UL), 99 /** Semaphores IPC channel has already been locked */ 100 CY_IPC_SEMA_ERROR_LOCKED = (uint32_t)(CY_IPC_SEMA_ID_ERROR | 1UL), 101 /** Semaphores IPC channel is unlocked */ 102 CY_IPC_SEMA_ERROR_UNLOCKED = (uint32_t)(CY_IPC_SEMA_ID_ERROR | 2UL), 103 /** Semaphore API bad parameter */ 104 CY_IPC_SEMA_BAD_PARAM = (uint32_t)(CY_IPC_SEMA_ID_ERROR | 3UL), 105 /** Semaphore API return when semaphore number is out of the range */ 106 CY_IPC_SEMA_OUT_OF_RANGE = (uint32_t)(CY_IPC_SEMA_ID_ERROR | 4UL), 107 108 /** Semaphore API return when IPC channel was not acquired */ 109 CY_IPC_SEMA_NOT_ACQUIRED = (uint32_t)(CY_IPC_SEMA_ID_INFO | 2UL), 110 /** Semaphore API return status when semaphore channel is busy or locked 111 * by another process */ 112 CY_IPC_SEMA_LOCKED = (uint32_t)(CY_IPC_SEMA_ID_INFO | 3UL), 113 /** Semaphore status return that the semaphore is set */ 114 CY_IPC_SEMA_STATUS_LOCKED = (uint32_t)(CY_IPC_SEMA_ID_INFO | 1UL), 115 /** Semaphore status return that the semaphore is cleared */ 116 CY_IPC_SEMA_STATUS_UNLOCKED = (uint32_t)(CY_IPC_SEMA_ID_INFO | 0UL) 117 } cy_en_ipcsema_status_t; 118 119 120 /** IPC semaphore control data structure. */ 121 typedef struct 122 { 123 /** Maximum semaphores in system */ 124 uint32_t maxSema; 125 /** Pointer to semaphores array */ 126 uint32_t *arrayPtr; 127 #if defined (CY_IP_MXIPC) && (CY_IPC_INSTANCES > 1U) 128 /** Pointer to secure semaphores array */ 129 uint32_t *arrayPtr_sec; 130 #endif 131 } cy_stc_ipc_sema_t; 132 133 /** \} group_ipc_sema_enums */ 134 135 /** 136 * \addtogroup group_ipc_sema_functions 137 * \{ 138 */ 139 140 #ifdef __cplusplus 141 extern "C" { 142 #endif 143 144 cy_en_ipcsema_status_t Cy_IPC_Sema_Init (uint32_t ipcChannel, uint32_t count, uint32_t memPtr[]); 145 cy_en_ipcsema_status_t Cy_IPC_Sema_InitExt(uint32_t ipcChannel, cy_stc_ipc_sema_t *ipcSema); 146 cy_en_ipcsema_status_t Cy_IPC_Sema_Set (uint32_t semaNumber, bool preemptable); 147 cy_en_ipcsema_status_t Cy_IPC_Sema_Clear (uint32_t semaNumber, bool preemptable); 148 cy_en_ipcsema_status_t Cy_IPC_Sema_Status (uint32_t semaNumber); 149 uint32_t Cy_IPC_Sema_GetMaxSems(void); 150 151 #ifdef __cplusplus 152 } 153 #endif 154 155 /** \} group_ipc_sema_functions */ 156 157 #endif /* CY_IP_M4CPUSS || CY_IP_M7CPUSS || (defined (CY_IP_MXIPC) && (CY_IPC_INSTANCES > 1U)) */ 158 159 #endif /* CY_IPC_SEMA_H */ 160 161 /* [] END OF FILE */ 162