xref: /utopia/UTPA2-700.0.x/projects/tmplib/include/drvSEM.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 
79 //////////////////////////////////////////////////////////////////////////////////////////////////
80 ///
81 /// @file   drvSEM.h
82 /// @brief  SEM Driver Interface
83 /// @author MStar Semiconductor Inc.
84 ///////////////////////////////////////////////////////////////////////////////////////////////////
85 
86 
87 /*! \defgroup G_SEM SEM interface
88     \ingroup  G_PERIPHERAL
89 
90     \brief
91 
92     a semaphore is a variable or abstract data type that is used
93     for controlling access, by multiple processes, to a common
94     resource in a concurrent system such as a multiprogramming
95     operating system.
96 
97     <b>Features</b>
98     - SEM initialize
99     - SEM resource manager
100     - SEAM lock & unlock
101 
102     <b> Operation Code Flow: </b> \n
103     -# SEM initilize
104     -# Get resource
105     -# Lock
106     -# UnLock
107 
108     \defgroup G_SEM_INIT Initialization Task relative
109     \ingroup  G_SEM
110     \defgroup G_SEM_COMMON Common Task relative
111     \ingroup  G_SEM
112     \defgroup G_SEM_CONTROL Control relative
113     \ingroup  G_SEM
114     \defgroup G_SEM_INT  Interrupt relative
115     \ingroup  G_SEM
116     \defgroup G_SEM_ToBeModified GPIO api to be modified
117     \ingroup  G_SEM
118     \defgroup G_SEM_ToBeRemove GPIO api to be removed
119     \ingroup  G_SEM
120 */
121 
122 #ifndef __DRV_SEM_H__
123 #define __DRV_SEM_H__
124 
125 #include "MsCommon.h"
126 
127 #ifdef __cplusplus
128 extern "C"
129 {
130 #endif
131 
132 #define SEM_DRV_VERSION                 /* Character String for DRV/API version             */  \
133     MSIF_TAG,                           /* 'MSIF'                                           */  \
134     MSIF_CLASS,                         /* '00'                                             */  \
135     MSIF_CUS,                           /* 0x0000                                           */  \
136     MSIF_MOD,                           /* 0x0000                                           */  \
137     MSIF_CHIP,                                                                                  \
138     MSIF_CPU,                                                                                   \
139     {'S','E','M','_'},                  /* IP__                                             */  \
140     {'0','1'},                          /* 0.0 ~ Z.Z                                        */  \
141     {'0','1'},                          /* 00 ~ 99                                          */  \
142     {'0','0','2','6','4','8','8','5'},  /* CL#                                              */  \
143     MSIF_OS
144 
145 //-------------------------------------------------------------------------------------------------
146 //  Local Defines
147 //-------------------------------------------------------------------------------------------------
148 #define SEM_PM51_ID                    0x01
149 #define SEM_AEON_ID                    0x02
150 #define SEM_ARM_MIPS_ID                0x03
151 
152 #if (defined(MCU_AEON))
153     #define    SEM_RESOURCE_ID         SEM_AEON_ID
154 #else
155     #define    SEM_RESOURCE_ID         SEM_ARM_MIPS_ID
156 #endif
157 
158 #define SEM_WAIT_FOREVER               (0xffffff00)
159 #define SEM_ID_PREFIX                  (0x36970000)
160 
161 
162 //-------------------------------------------------------------------------------------------------
163 // Type and Structure Declaration
164 //-------------------------------------------------------------------------------------------------
165 typedef enum
166 {
167     E_SEM_NONE = SEM_ID_PREFIX,
168     E_SEM_DUMMY,
169     E_SEM_GE0,
170     E_SEM_GE1,
171     E_SEM_BDMA,
172     E_SEM_PM,
173     E_SEM_MBX_RECV,
174     E_SEM_MBX_SEND,
175     E_SEM_TEE,
176     E_SEM_USER0,
177     E_SEM_USER1,
178     E_SEM_USER2,
179     E_SEM_USER3,
180     E_SEM_CA
181 }eSemId;
182 
183 typedef enum _SEM_DbgLvl
184 {
185     E_SEM_DBGLVL_NONE = 0,      /// no debug message
186     E_SEM_DBGLVL_WARNING,       /// show warning only
187     E_SEM_DBGLVL_ERROR,         /// show error only
188     E_SEM_DBGLVL_INFO,          /// show error & informaiton
189     E_SEM_DBGLVL_ALL,           /// show error, information & funciton name
190 }SEM_DbgLvl;
191 
192 //-------------------------------------------------------------------------------------------------
193 // Extern Functions
194 //-------------------------------------------------------------------------------------------------
195 //-------------------------------------------------------------------------------------------------
196 /// Set IR enable function.
197 /// @ingroup G_SEM_INIT
198 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
199 /// @return E_IR_OK: Success
200 /// @return E_IR_FAIL or other values: Failure
201 //-------------------------------------------------------------------------------------------------
202 MS_BOOL MDrv_SEM_Init(void);
203 //-------------------------------------------------------------------------------------------------
204 /// Set IR enable function.
205 /// @ingroup G_SEM_CONTROL
206 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
207 /// @return E_IR_OK: Success
208 /// @return E_IR_FAIL or other values: Failure
209 //-------------------------------------------------------------------------------------------------
210 MS_BOOL MDrv_SEM_Get_Resource(MS_U8 u8SemID, MS_U16 u16ResId);
211 //-------------------------------------------------------------------------------------------------
212 /// Set IR enable function.
213 /// @ingroup G_SEM_CONTROL
214 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
215 /// @return E_IR_OK: Success
216 /// @return E_IR_FAIL or other values: Failure
217 //-------------------------------------------------------------------------------------------------
218 MS_BOOL MDrv_SEM_Free_Resource(MS_U8 u8SemID, MS_U16 u16ResId);
219 //-------------------------------------------------------------------------------------------------
220 /// Set IR enable function.
221 /// @ingroup G_SEM_CONTROL
222 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
223 /// @return E_IR_OK: Success
224 /// @return E_IR_FAIL or other values: Failure
225 //-------------------------------------------------------------------------------------------------
226 // MS_BOOL MDrv_SEM_Reset_Resource(MS_U8 u8SemID);
227 //-------------------------------------------------------------------------------------------------
228 /// Set IR enable function.
229 /// @ingroup G_SEM_CONTROL
230 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
231 /// @return E_IR_OK: Success
232 /// @return E_IR_FAIL or other values: Failure
233 //-------------------------------------------------------------------------------------------------
234 // MS_BOOL MDrv_SEM_Get_ResourceID(MS_U8 u8SemID, MS_U16* pu16ResId);
235 //-------------------------------------------------------------------------------------------------
236 /// Set IR enable function.
237 /// @ingroup G_SEM_CONTROL
238 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
239 /// @return E_IR_OK: Success
240 /// @return E_IR_FAIL or other values: Failure
241 //-------------------------------------------------------------------------------------------------
242 // MS_U32 MDrv_SEM_Get_Num(void);
243 //-------------------------------------------------------------------------------------------------
244 /// Set IR enable function.
245 /// @ingroup G_SEM_COMMON
246 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
247 /// @return E_IR_OK: Success
248 /// @return E_IR_FAIL or other values: Failure
249 //-------------------------------------------------------------------------------------------------
250 // MS_BOOL MDrv_SEM_GetLibVer(const MSIF_Version **ppVersion);
251 //-------------------------------------------------------------------------------------------------
252 /// Set IR enable function.
253 /// @ingroup G_SEM_COMMON
254 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
255 /// @return E_IR_OK: Success
256 /// @return E_IR_FAIL or other values: Failure
257 //-------------------------------------------------------------------------------------------------
258 // MS_U32 MDrv_SEM_SetPowerState(EN_POWER_MODE u16PowerState);
259 //-------------------------------------------------------------------------------------------------
260 /// Set IR enable function.
261 /// @ingroup G_SEM_CONTROL
262 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
263 /// @return E_IR_OK: Success
264 /// @return E_IR_FAIL or other values: Failure
265 //-------------------------------------------------------------------------------------------------
266 MS_BOOL MDrv_SEM_Lock(eSemId eSemId, MS_U32 u32WaitMs);
267 //-------------------------------------------------------------------------------------------------
268 /// Set IR enable function.
269 /// @ingroup G_SEM_CONTROL
270 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
271 /// @return E_IR_OK: Success
272 /// @return E_IR_FAIL or other values: Failure
273 //-------------------------------------------------------------------------------------------------
274 MS_BOOL MDrv_SEM_Unlock(eSemId eSemId);
275 //-------------------------------------------------------------------------------------------------
276 /// Set IR enable function.
277 /// @ingroup G_SEM_CONTROL
278 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR
279 /// @return E_IR_OK: Success
280 /// @return E_IR_FAIL or other values: Failure
281 //-------------------------------------------------------------------------------------------------
282 // MS_BOOL MDrv_SEM_Delete(eSemId eSemId);
283 
284 //-------------------------------------------------------------------------------------------------
285 /// Set SEM debug function level.
286 /// @ingroup G_SEM_COMMON
287 /// @param eLevel \b IN: E_SEM_DBGLVL_NONE/E_SEM_DBGLVL_WARNING/E_SEM_DBGLVL_ERROR/E_SEM_DBGLVL_INFO/E_SEM_DBGLVL_ALL
288 /// @return TRUE: Success
289 /// @return other values: Failure
290 //-------------------------------------------------------------------------------------------------
291 // MS_BOOL MDrv_SEM_SetDbgLevel(SEM_DbgLvl eLevel);
292 
293 //==============================================================================
294 // Semaphore Usage in Utopia
295 // See halSEM.c
296 //==============================================================================
297 
298 #ifdef __cplusplus
299 } // closing brace for extern "C"
300 #endif
301 
302 #endif // #ifndef __DRV_SEM_H__
303