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