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 E_SEM_IIC 182 }eSemId; 183 184 typedef enum _SEM_DbgLvl 185 { 186 E_SEM_DBGLVL_NONE = 0, /// no debug message 187 E_SEM_DBGLVL_WARNING, /// show warning only 188 E_SEM_DBGLVL_ERROR, /// show error only 189 E_SEM_DBGLVL_INFO, /// show error & informaiton 190 E_SEM_DBGLVL_ALL, /// show error, information & funciton name 191 }SEM_DbgLvl; 192 193 //------------------------------------------------------------------------------------------------- 194 // Extern Functions 195 //------------------------------------------------------------------------------------------------- 196 //------------------------------------------------------------------------------------------------- 197 /// Set IR enable function. 198 /// @ingroup G_SEM_INIT 199 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 200 /// @return E_IR_OK: Success 201 /// @return E_IR_FAIL or other values: Failure 202 //------------------------------------------------------------------------------------------------- 203 MS_BOOL MDrv_SEM_Init(void); 204 //------------------------------------------------------------------------------------------------- 205 /// Set IR enable function. 206 /// @ingroup G_SEM_CONTROL 207 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 208 /// @return E_IR_OK: Success 209 /// @return E_IR_FAIL or other values: Failure 210 //------------------------------------------------------------------------------------------------- 211 MS_BOOL MDrv_SEM_Get_Resource(MS_U8 u8SemID, MS_U16 u16ResId); 212 //------------------------------------------------------------------------------------------------- 213 /// Set IR enable function. 214 /// @ingroup G_SEM_CONTROL 215 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 216 /// @return E_IR_OK: Success 217 /// @return E_IR_FAIL or other values: Failure 218 //------------------------------------------------------------------------------------------------- 219 MS_BOOL MDrv_SEM_Free_Resource(MS_U8 u8SemID, MS_U16 u16ResId); 220 //------------------------------------------------------------------------------------------------- 221 /// Set IR enable function. 222 /// @ingroup G_SEM_CONTROL 223 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 224 /// @return E_IR_OK: Success 225 /// @return E_IR_FAIL or other values: Failure 226 //------------------------------------------------------------------------------------------------- 227 MS_BOOL MDrv_SEM_Reset_Resource(MS_U8 u8SemID); 228 //------------------------------------------------------------------------------------------------- 229 /// Set IR enable function. 230 /// @ingroup G_SEM_CONTROL 231 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 232 /// @return E_IR_OK: Success 233 /// @return E_IR_FAIL or other values: Failure 234 //------------------------------------------------------------------------------------------------- 235 MS_BOOL MDrv_SEM_Get_ResourceID(MS_U8 u8SemID, MS_U16* pu16ResId); 236 //------------------------------------------------------------------------------------------------- 237 /// Set IR enable function. 238 /// @ingroup G_SEM_CONTROL 239 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 240 /// @return E_IR_OK: Success 241 /// @return E_IR_FAIL or other values: Failure 242 //------------------------------------------------------------------------------------------------- 243 MS_U32 MDrv_SEM_Get_Num(void); 244 //------------------------------------------------------------------------------------------------- 245 /// Set IR enable function. 246 /// @ingroup G_SEM_COMMON 247 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 248 /// @return E_IR_OK: Success 249 /// @return E_IR_FAIL or other values: Failure 250 //------------------------------------------------------------------------------------------------- 251 MS_BOOL MDrv_SEM_GetLibVer(const MSIF_Version **ppVersion); 252 //------------------------------------------------------------------------------------------------- 253 /// Set IR enable function. 254 /// @ingroup G_SEM_COMMON 255 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 256 /// @return E_IR_OK: Success 257 /// @return E_IR_FAIL or other values: Failure 258 //------------------------------------------------------------------------------------------------- 259 MS_U32 MDrv_SEM_SetPowerState(EN_POWER_MODE u16PowerState); 260 //------------------------------------------------------------------------------------------------- 261 /// Set IR enable function. 262 /// @ingroup G_SEM_CONTROL 263 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 264 /// @return E_IR_OK: Success 265 /// @return E_IR_FAIL or other values: Failure 266 //------------------------------------------------------------------------------------------------- 267 MS_BOOL MDrv_SEM_Lock(eSemId eSemId, MS_U32 u32WaitMs); 268 //------------------------------------------------------------------------------------------------- 269 /// Set IR enable function. 270 /// @ingroup G_SEM_CONTROL 271 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 272 /// @return E_IR_OK: Success 273 /// @return E_IR_FAIL or other values: Failure 274 //------------------------------------------------------------------------------------------------- 275 MS_BOOL MDrv_SEM_Unlock(eSemId eSemId); 276 //------------------------------------------------------------------------------------------------- 277 /// Set IR enable function. 278 /// @ingroup G_SEM_CONTROL 279 /// @param bEnable \b IN: TRUE: enable IR, FALSE: disable IR 280 /// @return E_IR_OK: Success 281 /// @return E_IR_FAIL or other values: Failure 282 //------------------------------------------------------------------------------------------------- 283 MS_BOOL MDrv_SEM_Delete(eSemId eSemId); 284 285 //------------------------------------------------------------------------------------------------- 286 /// Set SEM debug function level. 287 /// @ingroup G_SEM_COMMON 288 /// @param eLevel \b IN: E_SEM_DBGLVL_NONE/E_SEM_DBGLVL_WARNING/E_SEM_DBGLVL_ERROR/E_SEM_DBGLVL_INFO/E_SEM_DBGLVL_ALL 289 /// @return TRUE: Success 290 /// @return other values: Failure 291 //------------------------------------------------------------------------------------------------- 292 MS_BOOL MDrv_SEM_SetDbgLevel(SEM_DbgLvl eLevel); 293 294 //============================================================================== 295 // Semaphore Usage in Utopia 296 // See halSEM.c 297 //============================================================================== 298 299 #ifdef __cplusplus 300 } // closing brace for extern "C" 301 #endif 302 303 #endif // #ifndef __DRV_SEM_H__ 304