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 // Copyright (c) 2008-2009 MStar Semiconductor, Inc. 81 // All rights reserved. 82 // 83 // Unless otherwise stipulated in writing, any and all information contained 84 // herein regardless in any format shall remain the sole proprietary of 85 // MStar Semiconductor Inc. and be kept in strict confidence 86 // ("MStar Confidential Information") by the recipient. 87 // Any unauthorized act including without limitation unauthorized disclosure, 88 // copying, use, reproduction, sale, distribution, modification, disassembling, 89 // reverse engineering and compiling of the contents of MStar Confidential 90 // Information is unlawful and strictly prohibited. MStar hereby reserves the 91 // rights to any and all damages, losses, costs and expenses resulting therefrom. 92 // 93 //////////////////////////////////////////////////////////////////////////////// 94 95 /////////////////////////////////////////////////////////////////////////////////////////////////// 96 /// 97 /// @file MsOS.h 98 /// @brief MStar OS Wrapper 99 /// @author MStar Semiconductor Inc. 100 /////////////////////////////////////////////////////////////////////////////////////////////////// 101 102 /*! \defgroup SYS SYS modules 103 104 * \defgroup MSOS MsOS interface (MsOS.h) 105 * \ingroup SYS 106 107 \brief 108 109 MsOS is an OS abstraction layer, which is for utopia drivers 110 not to consider different system API usage on each platform 111 112 <b> Features </b> 113 114 - Memory pool 115 - Task 116 - Lock 117 - Event 118 - Timer 119 - Queue 120 - Interrupt 121 - Cache 122 - Mpool 123 - Ion 124 - Share memory 125 126 <b> Diagram </b> 127 \image html msos_1.png 128 129 * \defgroup MsOS_BASIC MsOS Module basic 130 * \ingroup MSOS 131 132 * \defgroup MsOS_Task MsOS OS Platform relative 133 * \ingroup MSOS 134 135 * \defgroup MsOS_MPool MPool relative 136 * \ingroup MSOS 137 138 * \defgroup MsOS_Interrupt interrupt relative 139 * \ingroup MSOS 140 141 * \defgroup MsOS_Interrupt_NOS interrupt relative for non-OS support 142 * \ingroup MSOS 143 144 * \defgroup MsOS_ION MsOS ION driver 145 * \ingroup MSOS 146 147 * \defgroup MsOS_ToBeModified MsOS api to be modified 148 * \ingroup MSOS 149 150 * \defgroup MsOS_ToBeRemove MsOS api to be removed 151 * \ingroup MSOS 152 */ 153 154 #ifndef _MS_OS_H_ 155 #define _MS_OS_H_ 156 157 #ifdef __cplusplus 158 extern "C" 159 { 160 #endif 161 162 #if defined(MSOS_TYPE_LINUX_KERNEL) 163 #include <linux/kernel.h> 164 #include <linux/interrupt.h> 165 #include <linux/irq.h> 166 #endif 167 168 #include "MsTypes.h" 169 #include "MsIRQ.h" 170 //------------------------------------------------------------------------------------------------- 171 // Defines 172 //------------------------------------------------------------------------------------------------- 173 #define MSIF_MSOS_LIB_CODE {'M','S','O','S'} //Lib code 174 #define MSIF_MSOS_LIBVER {'0','1'} //LIB version 175 #define MSIF_MSOS_BUILDNUM {'0','1'} //Build Number 176 #define MSIF_MSOS_CHANGELIST {'0','0','0','0','0','0','0','0'} //P4 ChangeList Number 177 178 #define MSOS_DRV_VERSION /* Character String for DRV/API version */ \ 179 MSIF_TAG, /* 'MSIF' */ \ 180 MSIF_CLASS, /* '00' */ \ 181 MSIF_CUS, /* 0x0000 */ \ 182 MSIF_MOD, /* 0x0000 */ \ 183 MSIF_CHIP, \ 184 MSIF_CPU, \ 185 MSIF_MSOS_LIB_CODE, /* IP__ */ \ 186 MSIF_MSOS_LIBVER, /* 0.0 ~ Z.Z */ \ 187 MSIF_MSOS_BUILDNUM, /* 00 ~ 99 */ \ 188 MSIF_MSOS_CHANGELIST, /* CL# */ \ 189 MSIF_OS 190 191 #define MSOS_TASK_MAX (32+120) 192 #define MSOS_MEMPOOL_MAX (8+64) 193 #define MSOS_FIXSIZE_MEMPOOL_MAX (8) 194 #define MSOS_SEMAPHORE_MAX (32+150) 195 #define MSOS_MUTEX_MAX (64+240) 196 #define MSOS_EVENTGROUP_MAX (64) 197 #define MSOS_TIMER_MAX (32) 198 #define MSOS_QUEUE_MAX (16+60) 199 #define MSOS_CONDITION_MAX (64+240) 200 201 #define MSOS_OS_MALLOC (0x7654FFFF) 202 #define MSOS_MALLOC_ID (0x0000FFFF) 203 204 //------------------------------------------------------------------------------------------------- 205 // Macros 206 //------------------------------------------------------------------------------------------------- 207 //time and clock macros 208 #define TICK_PER_ONE_MS (1) //Note: confirm Kernel fisrt 209 #define MSOS_WAIT_FOREVER (0xffffff00/TICK_PER_ONE_MS) 210 211 #ifdef MSOS_PERF_DEBUG 212 #define MSOS_PERF_PROFILE_DECL() MS_U32 u32time1=0, u32time2=0 213 #define MSOS_PERF_PROFILE_ON() u32time1 = MsOS_GetSystemTime() 214 #define MSOS_PERF_PROFILE_OFF() u32time2 = MsOS_GetSystemTime(); \ 215 printf("[MSOS_DBG]%s:%d takes %6dms\n",__FILE__, __LINE__, u32time2-u32time1) 216 #else 217 #define MSOS_PERF_PROFILE_DECL() 218 #define MSOS_PERF_PROFILE_ON() 219 #define MSOS_PERF_PROFILE_OFF() 220 #endif 221 222 //------------------------------------------------------------------------------------------------- 223 // Type and Structure Declaration 224 //------------------------------------------------------------------------------------------------- 225 #if defined (MSOS_TYPE_ECOS) || defined (MSOS_TYPE_LINUX) || defined (MSOS_TYPE_NOS) || defined (MSOS_TYPE_UCOS) || defined (MSOS_TYPE_NUTTX) 226 227 //compatible with Nucleus's task_entry 228 typedef void ( *TaskEntry ) (MS_VIRT argc, void *argv); ///< Task entry function argc: pass additional data to task entry; argv: not used by eCos 229 typedef void ( *InterruptCb ) (InterruptNum eIntNum); ///< Interrupt callback function 230 typedef void ( *SignalCb ) (MS_U32 u32Signals); ///< Signal callback function 231 typedef void ( *TimerCb ) (MS_U32 u32StTimer, MS_U32 u32TimerID); ///< Timer callback function u32StTimer: not used; u32TimerID: Timer ID 232 233 typedef struct { 234 volatile MS_S32 s32Value; 235 } MsOS_Atomic; 236 237 238 #ifdef MSOS_TYPE_UCOS 239 /// Task priority 240 typedef enum 241 { 242 E_TASK_PRI_SYS = 0, ///< System priority task ( interrupt level driver, e.g. TSP, SMART ) 243 E_TASK_PRI_HIGHEST = 16, ///< Highest priority task ( background monitor driver, e.g. DVBC, HDMI ) 244 E_TASK_PRI_HIGH = 32, ///< High priority task ( service task ) 245 E_TASK_PRI_MEDIUM = 48, ///< Medium priority task ( application task ) 246 E_TASK_PRI_LOW = 64, ///< Low priority task ( nonbusy application task ) 247 E_TASK_PRI_LOWEST = 96, ///< Lowest priority task ( idle application task ) 248 } TaskPriority; 249 #elif defined(MSOS_TYPE_NUTTX) 250 /// Task priority 251 typedef enum 252 { 253 E_TASK_PRI_SYS = 255, 254 E_TASK_PRI_HIGHEST = 255, 255 E_TASK_PRI_HIGH = 178, 256 E_TASK_PRI_MEDIUM = 100, 257 E_TASK_PRI_LOW = 50, 258 E_TASK_PRI_LOWEST = 1, 259 } TaskPriority; 260 #else 261 /// Task priority 262 typedef enum 263 { 264 E_TASK_PRI_SYS = 0, ///< System priority task ( interrupt level driver, e.g. TSP, SMART ) 265 E_TASK_PRI_HIGHEST = 4, ///< Highest priority task ( background monitor driver, e.g. DVBC, HDMI ) 266 E_TASK_PRI_HIGH = 8, ///< High priority task ( service task ) 267 E_TASK_PRI_MEDIUM = 12, ///< Medium priority task ( application task ) 268 E_TASK_PRI_LOW = 16, ///< Low priority task ( nonbusy application task ) 269 E_TASK_PRI_LOWEST = 24, ///< Lowest priority task ( idle application task ) 270 } TaskPriority; 271 #endif 272 273 274 /// Suspend type 275 typedef enum 276 { 277 E_MSOS_PRIORITY, ///< Priority-order suspension 278 E_MSOS_FIFO, ///< FIFO-order suspension 279 } MsOSAttribute; 280 281 /// Message size type 282 typedef enum 283 { 284 E_MSG_FIXED_SIZE, ///< Fixed size message 285 E_MSG_VAR_SIZE, ///< Variable size message 286 } MessageType; 287 288 /// Event mode 289 typedef enum 290 { 291 E_AND, ///< Specify all of the requested events are require. 292 E_OR, ///< Specify any of the requested events are require. 293 E_AND_CLEAR, ///< Specify all of the requested events are require. If the request are successful, clear the event. 294 E_OR_CLEAR, ///< Specify any of the requested events are require. If the request are successful, clear the event. 295 } EventWaitMode; 296 297 typedef enum 298 { 299 E_IRQ_DISABLE = 0, // reserve for MsOS_DisableInterrupt 300 E_IRQ_ENABLE = 1, // reserve for MsOS_EnableInterrupt 301 E_IRQ_ACK = 2, 302 E_IRQ_COMPLETE = 3, 303 E_IRQ_DEBUG_STATUS_FLOW = 4, 304 E_IRQ_DEBUG_DISABLE = 1 << 31, 305 } IrqDebugOpt; 306 307 typedef struct 308 { 309 MS_S32 iId; 310 MS_U32 uPoolSize; 311 MS_U32 u32MinAllocation; 312 MS_U32 u32Addr; 313 MsOSAttribute eAttribute; 314 char szName[16]; 315 } MemoryPool_Info, *PMemoryPool_Info; 316 317 typedef struct 318 { 319 MS_S32 iId; 320 TaskPriority ePriority; 321 void *pStack; 322 MS_U32 u32StackSize; 323 char szName[16]; 324 } Task_Info, *PTask_Info; 325 326 typedef struct 327 { 328 unsigned long long LX_MEM_ADDR; 329 unsigned long long LX_MEM_LENGTH; 330 unsigned long long LX_MEM2_ADDR; 331 unsigned long long LX_MEM2_LENGTH; 332 unsigned long long EMAC_ADDR; 333 unsigned long long EMAC_LENGTH; 334 unsigned long long DRAM_ADDR; 335 unsigned long long DRAM_LENGTH; 336 unsigned long long BB_ADDR; 337 unsigned long long BB_LENGTH; 338 unsigned long long MPOOL_MEM_ADDR; 339 unsigned long long MPOOL_MEM_LENGTH; 340 unsigned long long G3D_MEM0_ADDR; 341 unsigned long long G3D_MEM0_LENGTH; 342 unsigned long long G3D_MEM1_ADDR; 343 unsigned long long G3D_MEM1_LENGTH; 344 unsigned long long G3D_CMDQ_ADDR; 345 unsigned long long G3D_CMDQ_LENGTH; 346 }IO_Sys_Info_t; 347 348 typedef struct 349 { 350 unsigned int u32Addr; 351 unsigned int u32Size; 352 unsigned int u32Interval; 353 unsigned char u8MiuSel; 354 unsigned int bcached; 355 } KDrvMPool_Info_t; 356 357 #elif defined (MSOS_TYPE_LINUX_KERNEL) 358 359 //#include <linux/kernel.h> 360 //#include <linux/interrupt.h> 361 362 typedef void ( *TaskEntry ) (MS_U32 argc, void *argv); ///< Task entry function argc: pass additional data to task entry; argv: not used by eCos 363 typedef void ( *InterruptCb ) (InterruptNum eIntNum); ///< Interrupt callback function 364 typedef void ( *SignalCb ) (MS_U32 u32Signals); ///< Signal callback function 365 typedef void ( *TimerCb ) (MS_U32 u32StTimer, MS_U32 u32TimerID); ///< Timer callback function u32StTimer: not used; u32TimerID: Timer ID 366 367 #if 0 368 typedef enum 369 { 370 E_IRQ_DISABLE = 0 << 0, // reserve for MsOS_DisableInterrupt 371 E_IRQ_ENABLE = 1 << 0, // reserve for MsOS_EnableInterrupt 372 E_IRQ_ACK = 1 << 1, 373 E_IRQ_DEBUG_STATUS_FLOW = 1 << 2, 374 E_IRQ_DEBUG_DISABLE = 1 << 31, 375 } IrqDebugOpt; 376 #endif 377 378 /// Task priority 379 typedef enum 380 { 381 E_TASK_PRI_SYS = 0, ///< System priority task ( interrupt level driver, e.g. TSP, SMART ) 382 E_TASK_PRI_HIGHEST = 4, ///< Highest priority task ( background monitor driver, e.g. DVBC, HDMI ) 383 E_TASK_PRI_HIGH = 8, ///< High priority task ( service task ) 384 E_TASK_PRI_MEDIUM = 12, ///< Medium priority task ( application task ) 385 E_TASK_PRI_LOW = 16, ///< Low priority task ( nonbusy application task ) 386 E_TASK_PRI_LOWEST = 24, ///< Lowest priority task ( idle application task ) 387 } TaskPriority; 388 389 /// Suspend type 390 typedef enum 391 { 392 E_MSOS_PRIORITY, ///< Priority-order suspension 393 E_MSOS_FIFO, ///< FIFO-order suspension 394 } MsOSAttribute; 395 396 /// Message size type 397 typedef enum 398 { 399 E_MSG_FIXED_SIZE, ///< Fixed size message 400 E_MSG_VAR_SIZE, ///< Variable size message 401 } MessageType; 402 403 /// Event mode 404 typedef enum 405 { 406 E_AND, ///< Specify all of the requested events are require. 407 E_OR, ///< Specify any of the requested events are require. 408 E_AND_CLEAR, ///< Specify all of the requested events are require. If the request are successful, clear the event. 409 E_OR_CLEAR, ///< Specify any of the requested events are require. If the request are successful, clear the event. 410 } EventWaitMode; 411 412 typedef struct 413 { 414 MS_S32 iId; 415 MS_U32 uPoolSize; 416 MS_U32 u32MinAllocation; 417 MS_U32 u32Addr; 418 MsOSAttribute eAttribute; 419 char szName[16]; 420 } MemoryPool_Info, *PMemoryPool_Info; 421 422 typedef struct 423 { 424 MS_S32 iId; 425 TaskPriority ePriority; 426 void *pStack; 427 MS_U32 u32StackSize; 428 char szName[16]; 429 } Task_Info, *PTask_Info; 430 431 typedef struct 432 { 433 unsigned int LX_MEM_ADDR; 434 unsigned int LX_MEM_LENGTH; 435 unsigned int LX_MEM2_ADDR; 436 unsigned int LX_MEM2_LENGTH; 437 unsigned int EMAC_ADDR; 438 unsigned int EMAC_LENGTH; 439 unsigned int DRAM_ADDR; 440 unsigned int DRAM_LENGTH; 441 unsigned int BB_ADDR; 442 unsigned int BB_LENGTH; 443 unsigned int MPOOL_MEM_ADDR; 444 unsigned int MPOOL_MEM_LENGTH; 445 unsigned int G3D_MEM0_ADDR; 446 unsigned int G3D_MEM0_LENGTH; 447 unsigned int G3D_MEM1_ADDR; 448 unsigned int G3D_MEM1_LENGTH; 449 unsigned int G3D_CMDQ_ADDR; 450 unsigned int G3D_CMDQ_LENGTH; 451 }IO_Sys_Info_t; 452 453 typedef struct 454 { 455 unsigned int u32Addr; 456 unsigned int u32Size; 457 unsigned int u32Interval; 458 unsigned char u8MiuSel; 459 unsigned int bcached; 460 } KDrvMPool_Info_t; 461 462 typedef struct 463 { 464 MS_U32 mpool_base; 465 MS_U32 mpool_size; 466 MS_U32 mmap_offset; 467 MS_U32 mmap_size; 468 MS_U32 mmap_interval; 469 MS_U8 mmap_miusel; 470 unsigned int u8MapCached; 471 MS_BOOL setflag; 472 }MMAP_FileData; 473 474 #elif defined (MSOS_TYPE_XXX) 475 476 #error "The OS is not supported now ..." 477 478 #endif 479 480 //------------------------------------------------------------------------------------------------- 481 // Extern Functions 482 //------------------------------------------------------------------------------------------------- 483 // 484 // Init 485 // 486 487 //------------------------------------------------------------------------------------------------- 488 /// Initialize MsOS 489 /// @ingroup MsOS_BASIC 490 /// @return TRUE : succeed 491 /// @return FALSE : fail 492 //------------------------------------------------------------------------------------------------- 493 MS_BOOL MsOS_Init (void); 494 495 //------------------------------------------------------------------------------------------------- 496 /// Initialize MsOS for STR Init 497 /// @ingroup MsOS_ToBeRemove 498 /// @return TRUE : succeed 499 /// @return FALSE : fail 500 //------------------------------------------------------------------------------------------------- 501 // MS_BOOL MsOS_Init_str (void); 502 503 //------------------------------------------------------------------------------------------------- 504 /// Initialize MsOS for Fastboot Init 505 /// @ingroup MsOS_ToBeRemove 506 /// @return TRUE : succeed 507 /// @return FALSE : fail 508 //------------------------------------------------------------------------------------------------- 509 // MS_BOOL MsOS_Init_Fastboot (void); 510 511 512 //------------------------------------------------------------------------------------------------- 513 /// Create a variable-size memory pool dynamically 514 /// @ingroup MsOS_MPool 515 /// @param u32PoolSize \b IN: pool size in bytes 516 /// @param u32MinAllocation \b IN: not used 517 /// @param pPoolAddr \b IN: starting address for the memory pool 518 /// @param eAttribute \b IN: only E_MSOS_FIFO - suspended in FIFO order 519 /// @param pPoolName \b IN: not used 520 /// @return >=0 : assigned memory pool ID 521 /// @return < 0 : fail 522 //------------------------------------------------------------------------------------------------- 523 MS_S32 MsOS_CreateMemoryPool (MS_U32 u32PoolSize, 524 MS_U32 u32MinAllocation, 525 void * pPoolAddr, 526 MsOSAttribute eAttribute, 527 char *pPoolName); 528 529 //------------------------------------------------------------------------------------------------- 530 /// Delete a variable-size memory pool 531 /// @ingroup MsOS_MPool 532 /// @param s32PoolId \b IN: pool ID 533 /// @return TRUE : succeed 534 /// @return FALSE : fail 535 //------------------------------------------------------------------------------------------------- 536 MS_BOOL MsOS_DeleteMemoryPool (MS_S32 s32PoolId); 537 538 //------------------------------------------------------------------------------------------------- 539 /// Get the information of a variable-size memory pool 540 /// @ingroup MsOS_MPool 541 /// @param s32PoolId \b IN: memory pool ID 542 /// @param pPoolAddr \b OUT: holding the starting address for the memory pool 543 /// @param pu32PoolSize \b OUT: holding the total size of the memory pool 544 /// @param pu32FreeSize \b OUT: holding the available free size of the memory pool 545 /// @param pu32LargestFreeBlockSize \b OUT: holding the size of the largest free block 546 /// @return TRUE : succeed 547 /// @return FALSE : the pool has not been created 548 //------------------------------------------------------------------------------------------------- 549 MS_BOOL MsOS_InfoMemoryPool (MS_S32 s32PoolId, 550 void **pPoolAddr, 551 MS_U32 *pu32PoolSize, 552 MS_U32 *pu32FreeSize, 553 MS_U32 *pu32LargestFreeBlockSize); 554 555 //------------------------------------------------------------------------------------------------- 556 /// Allocate a memory block with 16-Byte aligned starting address from the variable-size memory pool 557 /// @ingroup MsOS_MPool 558 /// @param u32Size \b IN: request size 559 /// @param s32PoolId \b IN: memory pool ID 560 /// @return NULL : not enough available memory 561 /// @return Otherwise : pointer to the allocated memory block 562 //------------------------------------------------------------------------------------------------- 563 void * MsOS_AllocateMemory (MS_U32 u32Size, MS_S32 s32PoolId); 564 565 //void * MsOS_AllocateAlignedMemory (MS_U32 u32Size, MS_U32 u32AlignedByte, MS_S32 s32PoolId); 566 //------------------------------------------------------------------------------------------------- 567 /// Reallocate a block of memory with 4-byte aligned start address from the variable-size memory pool 568 /// @ingroup MsOS_MPool 569 /// @param pOrgAddress \b IN: points to the beginning of the original memory block 570 /// @param u32NewSize \b IN: size of new memory block 571 /// @param s32PoolId \b IN: memory pool ID 572 /// @return NULL : not enough available memory to expand the block or u32NewSize == 0 && pOrgAddress != NULL 573 /// @return Otherwise : pointer to the reallocated (and possibly moved) memory block 574 // @note reference realloc in malloc.cxx 575 //------------------------------------------------------------------------------------------------- 576 void * MsOS_ReallocateMemory (void *pOrgAddress, MS_U32 u32NewSize, MS_S32 s32PoolId); 577 578 //------------------------------------------------------------------------------------------------- 579 /// Free a memory block from the variable-size memory pool 580 /// @ingroup MsOS_MPool 581 /// @param pAddress \b IN: pointer to previously allocated memory block 582 /// @param s32PoolId \b IN: memory pool ID 583 /// @return TRUE : succeed 584 /// @return FALSE : fail 585 //------------------------------------------------------------------------------------------------- 586 MS_BOOL MsOS_FreeMemory (void *pAddress, MS_S32 s32PoolId); 587 588 //------------------------------------------------------------------------------------------------- 589 /// Todo: no contant on MsOS_linux.c, please review it 590 /// @ingroup MsOS_ToBeRemove 591 //------------------------------------------------------------------------------------------------- 592 MS_S32 MsOS_CreateFixSizeMemoryPool (MS_U32 u32PoolSize, 593 MS_U32 u32BlockSize, 594 void * pPoolAddr, 595 MsOSAttribute eAttribute, 596 char *pPoolName); 597 598 //------------------------------------------------------------------------------------------------- 599 /// Todo: no contant on MsOS_linux.c, please review it 600 /// @ingroup MsOS_ToBeRemove 601 //------------------------------------------------------------------------------------------------- 602 MS_BOOL MsOS_DeleteFixSizeMemoryPool (MS_S32 s32PoolId); 603 604 //------------------------------------------------------------------------------------------------- 605 /// Todo: no contant on MsOS_linux.c, please review it 606 /// @ingroup MsOS_ToBeRemove 607 //------------------------------------------------------------------------------------------------- 608 MS_BOOL MsOS_InfoFixSizeMemoryPool (MS_S32 s32PoolId, 609 void **pPoolAddr, 610 MS_U32 *pu32PoolSize, 611 MS_U32 *pu32FreeSize, 612 MS_U32 *pu32LargestFreeBlockSize); 613 614 //------------------------------------------------------------------------------------------------- 615 /// Todo: no contant on MsOS_linux.c, please review it 616 /// @ingroup MsOS_ToBeRemove 617 //------------------------------------------------------------------------------------------------- 618 void * MsOS_AllocateFixSizeMemory (MS_S32 s32PoolId); 619 620 //------------------------------------------------------------------------------------------------- 621 /// Todo: no contant on MsOS_linux.c, please review it 622 /// @ingroup MsOS_ToBeRemove 623 //------------------------------------------------------------------------------------------------- 624 MS_BOOL MsOS_FreeFixSizeMemory (void *pAddress, MS_S32 s32PoolId); 625 626 //------------------------------------------------------------------------------------------------- 627 /// Create a task 628 /// @ingroup MsOS_Task 629 /// @param pTaskEntry \b IN: task entry point 630 /// @param u32TaskEntryData \b IN: task entry data: a pointer to some static data, or a 631 /// small integer, or NULL if the task does not require any additional data. 632 /// @param eTaskPriority \b IN: task priority 633 /// @param bAutoStart \b IN: start immediately or later 634 /// @param pStackBase \b IN: task stack 635 /// @param u32StackSize \b IN: stack size 636 /// @param pTaskName \b IN: task name 637 /// @return >=0 : assigned Task ID 638 /// @return < 0 : fail 639 //------------------------------------------------------------------------------------------------- 640 MS_S32 MsOS_CreateTask (TaskEntry pTaskEntry, 641 MS_VIRT u32TaskEntryData, 642 TaskPriority eTaskPriority, 643 MS_BOOL bAutoStart, 644 void * pStackEntry, 645 MS_U32 u32StackSize, 646 char *pTaskName); 647 648 //------------------------------------------------------------------------------------------------- 649 /// Delete a previously created task1 650 /// @ingroup MsOS_ToBeRemove 651 /// @param s32TaskId \b IN: task ID 652 /// @return TRUE : succeed 653 /// @return FALSE : fail 654 //------------------------------------------------------------------------------------------------- 655 MS_BOOL MsOS_DeleteTask (MS_S32 s32TaskId); 656 657 //------------------------------------------------------------------------------------------------- 658 /// Yield the execution right to ready tasks with "the same" priority 659 /// @ingroup MsOS_Task 660 /// @return None 661 //------------------------------------------------------------------------------------------------- 662 void MsOS_YieldTask (void); 663 664 //------------------------------------------------------------------------------------------------- 665 /// Suspend the calling task for u32Ms milliseconds 666 /// @ingroup MsOS_Task 667 /// @param u32Ms \b IN: delay 1 ~ MSOS_WAIT_FOREVER ms 668 /// @return None 669 /// @note Not allowed in interrupt context; otherwise, exception will occur. 670 //------------------------------------------------------------------------------------------------- 671 void MsOS_DelayTask (MS_U32 u32Ms); 672 673 //------------------------------------------------------------------------------------------------- 674 /// Delay for u32Us microseconds 675 /// @ingroup MsOS_Task 676 /// @param u32Us \b IN: delay 0 ~ 999 us 677 /// @return None 678 /// @note implemented by "busy waiting". Plz call MsOS_DelayTask directly for ms-order delay 679 //------------------------------------------------------------------------------------------------- 680 void MsOS_DelayTaskUs (MS_U32 u32Us); 681 682 //------------------------------------------------------------------------------------------------- 683 /// Delay Poll for u32Us microseconds 684 /// @ingroup MsOS_Task 685 /// @param u32Us \b IN: delay 0 ~ 999 us 686 /// @return None 687 /// @note implemented by "busy waiting". Plz call MsOS_DelayTask directly for ms-order delay 688 //------------------------------------------------------------------------------------------------- 689 void MsOS_DelayTaskUs_Poll(MS_U32 u32Us); 690 691 //------------------------------------------------------------------------------------------------- 692 /// Resume the specified suspended task 693 /// @ingroup MsOS_Task 694 /// @param s32TaskId \b IN: Task ID 695 /// @return TRUE : succeed 696 /// @return FALSE : fail 697 /// @note This API is not supported in Linux 698 //------------------------------------------------------------------------------------------------- 699 MS_BOOL MsOS_ResumeTask (MS_S32 s32TaskId); 700 701 //------------------------------------------------------------------------------------------------- 702 /// Suspend the specified task 703 /// @ingroup MsOS_Task 704 /// @param s32TaskId \b IN: Task ID 705 /// @return TRUE : succeed 706 /// @return FALSE : fail 707 /// @note This API is not supported in Linux 708 //------------------------------------------------------------------------------------------------- 709 MS_BOOL MsOS_SuspendTask (MS_S32 s32TaskId); 710 711 //------------------------------------------------------------------------------------------------- 712 /// Get current task ID 713 /// @ingroup MsOS_Task 714 /// @return >=0 : current task ID 715 /// @return <0 : fail 716 //------------------------------------------------------------------------------------------------- 717 MS_S32 MsOS_InfoTaskID (void); 718 719 //------------------------------------------------------------------------------------------------- 720 /// Get thread ID of current thread/process in OS 721 /// @ingroup MsOS_Task 722 /// @return : current thread ID 723 //------------------------------------------------------------------------------------------------- 724 MS_S32 MsOS_GetOSThreadID (void); 725 726 // 727 // Mutex 728 // 729 #define MSOS_PROCESS_PRIVATE 0x00000000 730 #define MSOS_PROCESS_SHARED 0x00000001 731 #define MAX_MUTEX_NAME_LENGTH 50 732 733 //------------------------------------------------------------------------------------------------- 734 /// Create a mutex in the unlocked state1 735 /// @ingroup MsOS_Task 736 /// @param eAttribute \b IN: E_MSOS_FIFO: suspended in FIFO order 737 /// @param pMutexName \b IN: mutex name 738 /// @param u32Flag \b IN: process data shared flag 739 /// @return >=0 : assigned mutex Id 740 /// @return <0 : fail 741 /// @note A mutex has the concept of an owner, whereas a semaphore does not. 742 /// A mutex provides priority inheritance protocol against proiorty inversion, whereas a binary semaphore does not. 743 //------------------------------------------------------------------------------------------------- 744 MS_S32 MsOS_CreateMutex ( MsOSAttribute eAttribute, char *pMutexName, MS_U32 u32Flag); 745 746 //------------------------------------------------------------------------------------------------- 747 /// Delete the specified mutex 748 /// @ingroup MsOS_Task 749 /// @param s32MutexId \b IN: mutex ID 750 /// @return TRUE : succeed 751 /// @return FALSE : fail 752 /// @note It is important that the mutex be in the unlocked state when it is 753 /// destroyed, or else the behavior is undefined. 754 //------------------------------------------------------------------------------------------------- 755 MS_BOOL MsOS_DeleteMutex (MS_S32 s32MutexId); 756 757 //------------------------------------------------------------------------------------------------- 758 /// Attempt to lock a mutex 759 /// @ingroup MsOS_Task 760 /// @param s32MutexId \b IN: mutex ID 761 /// @param u32WaitMs \b IN: 0 ~ MSOS_WAIT_FOREVER: suspend time (ms) if the mutex is locked 762 /// @return TRUE : succeed 763 /// @return FALSE : fail 764 //------------------------------------------------------------------------------------------------- 765 MS_BOOL MsOS_ObtainMutex (MS_S32 s32MutexId, MS_U32 u32WaitMs); 766 767 //------------------------------------------------------------------------------------------------- 768 /// Attempt to unlock a mutex 769 /// @ingroup MsOS_Task 770 /// @param s32MutexId \b IN: mutex ID 771 /// @return TRUE : succeed 772 /// @return FALSE : fail 773 /// @note Only the owner thread of the mutex can unlock it. 774 //------------------------------------------------------------------------------------------------- 775 MS_BOOL MsOS_ReleaseMutex (MS_S32 s32MutexId); 776 777 //------------------------------------------------------------------------------------------------- 778 /// Get a mutex informaton 779 /// @ingroup MsOS_Task 780 /// @param s32MutexId \b IN: mutex ID 781 /// @param peAttribute \b OUT: ptr to suspended mode: E_MSOS_FIFO / E_MSOS_PRIORITY 782 /// @param pMutexName \b OUT: ptr to mutex name 783 /// @return TRUE : succeed 784 /// @return FALSE : the mutex has not been created. 785 //------------------------------------------------------------------------------------------------- 786 MS_BOOL MsOS_InfoMutex (MS_S32 s32MutexId, MsOSAttribute *peAttribute, char *pMutexName); 787 788 //------------------------------------------------------------------------------------------------- 789 /// Create a semaphore 790 /// @ingroup MsOS_Task 791 /// @param u32InitCnt \b IN: initial semaphore value 792 /// @param eAttribute \b IN: E_MSOS_FIFO suspended in FIFO order 793 /// @param pSemaphoreName \b IN: semaphore name 794 /// @return >=0 : assigned Semaphore Id 795 /// @return <0 : fail 796 /// @note A semaphore does not have the concept of an owner; it is possible for one thread to lock a 797 /// binary semaphore and another thread to unlock it. 798 //------------------------------------------------------------------------------------------------- 799 MS_S32 MsOS_CreateSemaphore (MS_U32 u32InitCnt, 800 MsOSAttribute eAttribute, 801 char *pName); 802 803 //------------------------------------------------------------------------------------------------- 804 /// Delete the specified semaphore 805 /// @ingroup MsOS_Task 806 /// @param s32SemaphoreId \b IN: semaphore ID 807 /// @return TRUE : succeed 808 /// @return FALSE : fail 809 /// @note It is important that there are not any threads waiting on the semaphore 810 /// when this function is called or the behavior is undefined. 811 //------------------------------------------------------------------------------------------------- 812 MS_BOOL MsOS_DeleteSemaphore (MS_S32 s32SemaphoreId); 813 814 //------------------------------------------------------------------------------------------------- 815 /// Attempt to decrement a semaphore count 816 /// @ingroup MsOS_Task 817 /// @param s32SemaphoreId \b IN: semaphore ID 818 /// @param u32WaitMs \b IN: 0 ~ MSOS_WAIT_FOREVER: suspend time (ms) if the semaphore count = 0 819 /// @return TRUE : succeed 820 /// @return FALSE : fail 821 //------------------------------------------------------------------------------------------------- 822 MS_BOOL MsOS_ObtainSemaphore (MS_S32 s32SemaphoreId, MS_U32 u32WaitMs); 823 824 //------------------------------------------------------------------------------------------------- 825 /// Increase a semaphore count 826 /// @ingroup MsOS_Task 827 /// @param s32SemaphoreId \b IN: semaphore ID 828 /// @return TRUE : succeed 829 /// @return FALSE : fail 830 /// @note It's possible for any thread to increase the semaphore count 831 //------------------------------------------------------------------------------------------------- 832 MS_BOOL MsOS_ReleaseSemaphore (MS_S32 s32SemaphoreId); 833 834 //------------------------------------------------------------------------------------------------- 835 /// Get a semaphore informaton 836 /// @ingroup MsOS_Task 837 /// @param s32SemaphoreId \b IN: semaphore ID 838 /// @param pu32InitCnt \b OUT: ptr to initial semaphore value 839 /// @param peAttribute \b OUT: ptr to suspended mode: E_MSOS_FIFO / E_MSOS_PRIORITY 840 /// @param pSemaphoreName \b OUT: ptr to semaphore name 841 /// @return TRUE : succeed 842 /// @return FALSE : the semaphore has not been created. 843 //------------------------------------------------------------------------------------------------- 844 MS_BOOL MsOS_InfoSemaphore (MS_S32 s32SemaphoreId, MS_U32 *pu32Cnt, MsOSAttribute *peAttribute, char *pSemaphoreName); 845 846 //------------------------------------------------------------------------------------------------- 847 /// Create an event group 848 /// @ingroup MsOS_Task 849 /// @param pEventName \b IN: event group name 850 /// @return >=0 : assigned Event Id 851 /// @return <0 : fail 852 //------------------------------------------------------------------------------------------------- 853 MS_S32 MsOS_CreateEventGroup (char *pName); 854 855 //------------------------------------------------------------------------------------------------- 856 /// Delete the event group 857 /// @ingroup MsOS_Task 858 /// @param s32EventGroupId \b IN: event group ID 859 /// @return TRUE : succeed 860 /// @return FALSE : fail, sb is waiting for the event flag 861 /// @note event group that are being waited on must not be deleted 862 //------------------------------------------------------------------------------------------------- 863 MS_BOOL MsOS_DeleteEventGroup (MS_S32 s32EventGroupId); 864 865 //------------------------------------------------------------------------------------------------- 866 /// Set the event flag (bitwise OR w/ current value) in the specified event group 867 /// @ingroup MsOS_Task 868 /// @param s32EventGroupId \b IN: event group ID 869 /// @param u32EventFlag \b IN: event flag value 870 /// @return TRUE : succeed 871 /// @return FALSE : fail 872 //------------------------------------------------------------------------------------------------- 873 MS_BOOL MsOS_SetEvent (MS_S32 s32EventGroupId, MS_U32 u32EventFlag); 874 875 //------------------------------------------------------------------------------------------------- 876 /// Clear the specified event flag (bitwise XOR operation) in the specified event group 877 /// @ingroup MsOS_Task 878 /// @param s32EventGroupId \b IN: event group ID 879 /// @param u32EventFlag \b IN: event flag value 880 /// @return TRUE : succeed 881 /// @return FALSE : fail 882 //------------------------------------------------------------------------------------------------- 883 MS_BOOL MsOS_ClearEvent (MS_S32 s32EventGroupId, MS_U32 u32EventFlag); 884 885 //------------------------------------------------------------------------------------------------- 886 /// Wait for the specified event flag combination from the event group 887 /// @ingroup MsOS_Task 888 /// @param s32EventGroupId \b IN: event group ID 889 /// @param u32WaitEventFlag \b IN: wait event flag value 890 /// @param pu32RetrievedEventFlag \b OUT: retrieved event flag value 891 /// @param eWaitMode \b IN: E_AND/E_OR/E_AND_CLEAR/E_OR_CLEAR 892 /// @param u32WaitMs \b IN: 0 ~ MSOS_WAIT_FOREVER: suspend time (ms) if the event is not ready 893 /// @return TRUE : succeed 894 /// @return FALSE : fail 895 //------------------------------------------------------------------------------------------------- 896 MS_BOOL MsOS_WaitEvent (MS_S32 s32EventGroupId, 897 MS_U32 u32WaitEventFlag, 898 MS_U32 *pu32RetrievedEventFlag, 899 EventWaitMode eWaitMode, 900 MS_U32 u32WaitMs); 901 902 MS_S32 MsOS_WaitEvent_Interrupt (MS_S32 s32EventGroupId, 903 MS_U32 u32WaitEventFlag, 904 MS_U32 *pu32RetrievedEventFlag, 905 EventWaitMode eWaitMode, 906 MS_U32 u32WaitMs); 907 908 /* 909 // 910 // Signal management 911 // 912 MS_BOOL MsOS_CreateSignal (SignalCb pSignalCb); 913 914 MS_BOOL MsOS_ControlSignals (MS_U32 u32SignalMask); 915 916 MS_BOOL MsOS_SendSignals (MS_S32 s32TaskId, MS_U32 u32Signal); 917 918 MS_U32 MsOS_ReceiveSignals (void); 919 */ 920 921 // 922 // Timer management 923 // 924 MS_S32 MsOS_CreateTimer (TimerCb pTimerCb, 925 MS_U32 u32FirstTimeMs, 926 MS_U32 u32PeriodTimeMs, 927 MS_BOOL bStartTimer, 928 char *pName); 929 930 //------------------------------------------------------------------------------------------------- 931 /// Delete the Timer 932 /// @ingroup MsOS_Task 933 /// @param s32TimerId \b IN: Timer ID 934 /// @return TRUE : succeed 935 /// @return FALSE : fail 936 //------------------------------------------------------------------------------------------------- 937 MS_BOOL MsOS_DeleteTimer (MS_S32 s32TimerId); 938 939 //------------------------------------------------------------------------------------------------- 940 /// Start the Timer 941 /// @ingroup MsOS_Task 942 /// @param s32TimerId \b IN: Timer ID 943 /// @return TRUE : succeed 944 /// @return FALSE : fail 945 //------------------------------------------------------------------------------------------------- 946 MS_BOOL MsOS_StartTimer (MS_S32 s32TimerId); 947 948 //------------------------------------------------------------------------------------------------- 949 /// Stop the Timer 950 /// @ingroup MsOS_Task 951 /// @param s32TimerId \b IN: Timer ID 952 /// @return TRUE : succeed 953 /// @return FALSE : fail 954 /// @note MsOS_StopTimer then MsOS_StartTimer => The timer will trigger at the same relative 955 /// intervals that it would have if it had not been disabled. 956 //------------------------------------------------------------------------------------------------- 957 MS_BOOL MsOS_StopTimer (MS_S32 s32TimerId); 958 959 //------------------------------------------------------------------------------------------------- 960 /// Reset a Timer & reset the expiration periods 961 /// @ingroup MsOS_Task 962 /// @param s32TimerId \b IN: Timer ID 963 /// @param u32FirstTimeMs \b IN: first ms for timer expiration 964 /// @param u32PeriodTimeMs \b IN: periodic ms for timer expiration after first expiration 965 /// 0: one shot timer 966 /// @param bStartTimer \b IN: TRUE: activates the timer after it is created 967 /// FALSE: leaves the timer disabled after it is created 968 /// @return TRUE : succeed 969 /// @return FALSE : fail 970 //------------------------------------------------------------------------------------------------- 971 MS_BOOL MsOS_ResetTimer (MS_S32 s32TimerId, 972 MS_U32 u32FirstTimeMs, 973 MS_U32 u32PeriodTimeMs, 974 MS_BOOL bStartTimer); 975 976 //------------------------------------------------------------------------------------------------- 977 /// Get current system time in ms 978 /// @ingroup MsOS_Task 979 /// @return system time in ms 980 //------------------------------------------------------------------------------------------------- 981 MS_U32 MsOS_GetSystemTime (void); 982 983 //------------------------------------------------------------------------------------------------- 984 ///[OBSOLETE] 985 /// @ingroup MsOS_Task 986 /// Time difference between current time and task time 987 /// @return system time diff in ms 988 //------------------------------------------------------------------------------------------------- 989 MS_U32 MsOS_Timer_DiffTimeFromNow(MS_U32 u32TaskTimer); ///[OBSOLETE] 990 991 //------------------------------------------------------------------------------------------------- 992 ///[OBSOLETE] 993 /// @ingroup MsOS_Task 994 /// Time difference between setting time and task time 995 /// @return system time diff in ms 996 //------------------------------------------------------------------------------------------------- 997 MS_U32 MsOS_Timer_DiffTime(MS_U32 u32Timer, MS_U32 u32TaskTimer); ///[OBSOLETE] 998 //MS_BOOL MsOS_SetSystemTime (MS_U32 u32SystemTime); 999 1000 //------------------------------------------------------------------------------------------------- 1001 /// Create a Queue 1002 /// @ingroup MsOS_Task 1003 /// @param pStartAddr \b IN: It is useless now, can pass NULL. 1004 /// @param u32QueueSize \b IN: queue size (byte unit) : now fixed as 1005 /// CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE * u32MessageSize 1006 /// @param eMessageType \b IN: E_MSG_FIXED_SIZE / E_MSG_VAR_SIZE 1007 /// @param u32MessageSize \b IN: message size (byte unit) for E_MSG_FIXED_SIZE 1008 /// max message size (byte unit) for E_MSG_VAR_SIZE 1009 /// @param eAttribute \b IN: E_MSOS_FIFO suspended in FIFO order 1010 /// @param pQueueName \b IN: queue name 1011 /// @return assigned message queue ID 1012 /// @return < 0 - fail 1013 //------------------------------------------------------------------------------------------------- 1014 MS_S32 MsOS_CreateQueue (void *pStartAddr, 1015 MS_U32 u32QueueSize, 1016 MessageType eMessageType, 1017 MS_U32 u32MessageSize, 1018 MsOSAttribute eAttribute, 1019 char *pQueueName); 1020 1021 //------------------------------------------------------------------------------------------------- 1022 /// Delete the Queue 1023 /// @ingroup MsOS_Task 1024 /// @param s32QueueId \b IN: Queue ID 1025 /// @return TRUE : succeed 1026 /// @return FALSE : fail 1027 /// @note It is important that there are not any threads blocked on the queue 1028 /// when this function is called or the behavior is undefined. 1029 //------------------------------------------------------------------------------------------------- 1030 MS_BOOL MsOS_DeleteQueue (MS_S32 s32QueueId); 1031 1032 //------------------------------------------------------------------------------------------------- 1033 /// Send a message to the end of the specified queue 1034 /// @ingroup MsOS_Task 1035 /// @param s32QueueId \b IN: Queue ID 1036 /// @param pu8Message \b IN: ptr to msg to send. NULL ptr is not allowed 1037 /// @param u32Size \b IN: msg size (byte) 1038 /// @param u32WaitMs \b IN: 0 ~ MSOS_WAIT_FOREVER: suspend time (ms) if the queue is full 1039 /// @return TRUE : succeed 1040 /// @return FALSE : fail 1041 //------------------------------------------------------------------------------------------------- 1042 MS_BOOL MsOS_SendToQueue (MS_S32 s32QueueId, MS_U8 *pu8Message, MS_U32 u32Size, MS_U32 u32WaitMs); 1043 1044 //------------------------------------------------------------------------------------------------- 1045 /// Receive a message from the specified queue 1046 /// @ingroup MsOS_Task 1047 /// @param s32QueueId \b IN: Queue ID 1048 /// @param pu8Message \b OUT: msg destination 1049 /// @param u32IntendedSize \b IN: intended msg size (byte unit) to receive: 1050 /// @param pu32ActualSize \b OUT: actual msg size (byte unit) received 1051 /// @param u32WaitMs \b IN: 0 ~ MSOS_WAIT_FOREVER: suspend time (ms) if the queue is empty 1052 /// @return TRUE : succeed 1053 /// @return FALSE : fail 1054 //------------------------------------------------------------------------------------------------- 1055 MS_BOOL MsOS_RecvFromQueue (MS_S32 s32QueueId, MS_U8 *pu8Message, MS_U32 u32IntendedSize, MS_U32 *pu32ActualSize, MS_U32 u32WaitMs); 1056 1057 //------------------------------------------------------------------------------------------------- 1058 /// Receive a message from the specified queue 1059 /// @ingroup MsOS_Task 1060 /// @param s32QueueId \b IN: Queue ID 1061 /// @param pu8Message \b OUT: msg destination 1062 /// @param u32IntendedSize \b IN: intended msg size (byte unit) to receive: 1063 /// @param pu32ActualSize \b OUT: actual msg size (byte unit) received 1064 /// @return TRUE : succeed 1065 /// @return FALSE : fail 1066 //------------------------------------------------------------------------------------------------- 1067 MS_BOOL MsOS_PeekFromQueue (MS_S32 s32QueueId, MS_U8 *pu8Message, MS_U32 u32IntendedSize, MS_U32 *pu32ActualSize); 1068 1069 //------------------------------------------------------------------------------------------------- 1070 /// Attach the interrupt callback function to interrupt # 1071 /// @ingroup MsOS_Interrupt 1072 /// @param eIntNum \b IN: Interrupt number in enumerator InterruptNum 1073 /// @param pIntCb \b IN: Interrupt callback function 1074 /// @return TRUE : succeed 1075 /// @return FALSE : fail 1076 //------------------------------------------------------------------------------------------------- 1077 MS_BOOL MsOS_AttachInterrupt (InterruptNum eIntNum, InterruptCb pIntCb); 1078 1079 //------------------------------------------------------------------------------------------------- 1080 /// Attach the interrupt callback function to interrupt # 1081 /// @ingroup MsOS_Interrupt 1082 /// @param eIntNum \b IN: Interrupt number in enumerator InterruptNum 1083 /// @param pIntCb \b IN: Interrupt callback function 1084 /// @return TRUE : succeed 1085 /// @return FALSE : fail 1086 //------------------------------------------------------------------------------------------------- 1087 MS_BOOL MsOS_AttachInterrupt_Shared (InterruptNum eIntNum, InterruptCb pIntCb); 1088 1089 //------------------------------------------------------------------------------------------------- 1090 /// Detach the interrupt callback function from interrupt # 1091 /// @ingroup MsOS_Interrupt 1092 /// @param eIntNum \b IN: Interrupt number in enumerator InterruptNum 1093 /// @return TRUE : succeed 1094 /// @return FALSE : fail 1095 //------------------------------------------------------------------------------------------------- 1096 MS_BOOL MsOS_DetachInterrupt (InterruptNum eIntNum); 1097 1098 //------------------------------------------------------------------------------------------------- 1099 /// Enable (unmask) the interrupt # 1100 /// @ingroup MsOS_Interrupt 1101 /// @param eIntNum \b IN: Interrupt number in enumerator InterruptNum 1102 /// @return TRUE : succeed 1103 /// @return FALSE : fail 1104 //------------------------------------------------------------------------------------------------- 1105 MS_BOOL MsOS_EnableInterrupt (InterruptNum eIntNum); 1106 1107 //------------------------------------------------------------------------------------------------- 1108 /// Debug the interrupt # 1109 /// @ingroup MsOS_Interrupt 1110 /// @param eIntNum \b IN: Interrupt number in enumerator InterruptNum 1111 /// @param IrqDebugOpt \n IN: Debug option 1112 /// @return TRUE : succeed 1113 /// @return FALSE : fail 1114 //------------------------------------------------------------------------------------------------- 1115 MS_BOOL MsOS_DebugInterrupt (InterruptNum eIntNum, IrqDebugOpt eIrqDebugOpt); 1116 1117 //------------------------------------------------------------------------------------------------- 1118 /// Disable (mask) the interrupt # 1119 /// @ingroup MsOS_Interrupt 1120 /// @param eIntNum \b IN: Interrupt number in enumerator InterruptNum 1121 /// @return TRUE : succeed 1122 //------------------------------------------------------------------------------------------------- 1123 MS_BOOL MsOS_DisableInterrupt (InterruptNum eIntNum); 1124 1125 //------------------------------------------------------------------------------------------------- 1126 /// Notify the interrupt complete # 1127 /// @ingroup MsOS_Interrupt 1128 /// @param eIntNum \b IN: Interrupt number in enumerator InterruptNum 1129 /// @return TRUE : succeed 1130 //------------------------------------------------------------------------------------------------- 1131 MS_BOOL MsOS_CompleteInterrupt (InterruptNum eIntNum); 1132 1133 //------------------------------------------------------------------------------------------------- 1134 /// In Interuupt Context or not 1135 /// @ingroup MsOS_Interrupt 1136 /// @return TRUE : Yes 1137 /// @return FALSE : No 1138 //------------------------------------------------------------------------------------------------- 1139 MS_BOOL MsOS_In_Interrupt (void); 1140 1141 //------------------------------------------------------------------------------------------------- 1142 /// Disable all interrupts (including timer interrupt), the scheduler is disabled. 1143 /// @ingroup MsOS_Interrupt 1144 /// @return Interrupt register value before all interrupts disable 1145 //------------------------------------------------------------------------------------------------- 1146 MS_U32 MsOS_DisableAllInterrupts(void); 1147 1148 //------------------------------------------------------------------------------------------------- 1149 /// Restore the interrupts from last MsOS_DisableAllInterrupts. 1150 /// @ingroup MsOS_Interrupt 1151 /// @param u32OldInterrupts \b IN: Interrupt register value from @ref MsOS_DisableAllInterrupts 1152 /// @return TRUE : succeed 1153 //------------------------------------------------------------------------------------------------- 1154 MS_BOOL MsOS_RestoreAllInterrupts(MS_U32 u32OldInterrupts); 1155 1156 //------------------------------------------------------------------------------------------------- 1157 /// Enable all CPU interrupts. 1158 /// @ingroup MsOS_Interrupt 1159 /// @return TRUE : succeed 1160 //------------------------------------------------------------------------------------------------- 1161 MS_BOOL MsOS_EnableAllInterrupts(void); 1162 1163 1164 1165 #if defined(__aeon__) 1166 typedef enum { 1167 E_EXCEPTION_BUS_ERROR = 2, 1168 E_EXCEPTION_DATA_PAGE_FAULT, 1169 E_EXCEPTION_INSTRUCTION_PAGE_FAULT, 1170 E_EXCEPTION_TICK_TIMER, ///< tick timer, do not use directly 1171 E_EXCEPTION_UNALIGNED_ACCESS, 1172 E_EXCEPTION_ILLEGAL_INSTRUCTION, 1173 E_EXCEPTION_EXTERNAL_INTERRUPT, ///< external interrupt, do not use directly 1174 E_EXCEPTION_DTLB_MISS, 1175 E_EXCEPTION_ITLB_MISS, 1176 E_EXCEPTION_RANGE, 1177 E_EXCEPTION_SYSCALL, ///< caused by l.sys 1178 E_EXCEPTION_RESERVED, 1179 E_EXCEPTION_TRAP, ///< caused by l.trap 1180 E_EXCEPTION_MAX = E_EXCEPTION_TRAP, 1181 } MHAL_EXCEPTION_TYPE; 1182 1183 typedef enum { 1184 E_INTERRUPT_TICK_TIMER, //< risc32 builtin tick timer 1185 #if defined(MSOS_TYPE_NUTTX) 1186 E_INTERRUPT_00 = 0, 1187 #else 1188 E_INTERRUPT_00 = 1, //< PIC interrupt start from 1 for handler performance 1189 #endif 1190 E_INTERRUPT_01, 1191 E_INTERRUPT_02, 1192 E_INTERRUPT_03, 1193 E_INTERRUPT_04, 1194 E_INTERRUPT_05, 1195 E_INTERRUPT_06, 1196 E_INTERRUPT_07, 1197 E_INTERRUPT_08, 1198 E_INTERRUPT_09, 1199 E_INTERRUPT_10, 1200 E_INTERRUPT_11, 1201 E_INTERRUPT_12, 1202 E_INTERRUPT_13, 1203 E_INTERRUPT_14, 1204 E_INTERRUPT_15, 1205 E_INTERRUPT_16, 1206 E_INTERRUPT_17, 1207 E_INTERRUPT_18, 1208 E_INTERRUPT_19, 1209 E_INTERRUPT_20, 1210 E_INTERRUPT_21, 1211 E_INTERRUPT_22, 1212 E_INTERRUPT_23, 1213 E_INTERRUPT_24, 1214 E_INTERRUPT_25, 1215 E_INTERRUPT_26, 1216 E_INTERRUPT_27, 1217 E_INTERRUPT_28, 1218 E_INTERRUPT_29, 1219 E_INTERRUPT_30, 1220 E_INTERRUPT_31, 1221 } MHAL_INTERRUPT_TYPE; 1222 1223 // Aliases for interrupt number 1224 #define E_INTERRUPT_FIQ E_INTERRUPT_02 1225 #define E_INTERRUPT_IRQ E_INTERRUPT_03 1226 #define E_INTERRUPT_UART E_INTERRUPT_19 1227 #define E_INTERRUPT_MAX E_INTERRUPT_31 1228 1229 typedef struct 1230 { 1231 unsigned long r[32]; ///< GPR registers 1232 #ifdef __AEONR2__ 1233 unsigned long machi2; // Highest 32-bits of new 32x32=64 multiplier 1234 #endif 1235 unsigned long machi; // High and low words of 1236 unsigned long maclo; // multiply/accumulate reg 1237 1238 // These are only saved for exceptions and interrupts 1239 int vector; ///< vector number 1240 int sr; ///< status register 1241 unsigned long pc; ///< program counter 1242 1243 // Saved only for exceptions, and not restored when continued: 1244 // Effective address of instruction/data access that caused exception 1245 unsigned long eear; ///< exception effective address 1246 } MHAL_SavedRegisters; 1247 #else 1248 typedef enum { 1249 E_EXCEPTION_DATA_TLBERROR_ACCESS = 1, // TLB modification exception 1250 E_EXCEPTION_DATA_TLBMISS_ACCESS, // TLB miss (Load or IFetch) 1251 E_EXCEPTION_DATA_TLBMISS_WRITE, // TLB miss (Store) 1252 E_EXCEPTION_DATA_UNALIGNED_ACCESS, // Address error (Load or Ifetch) 1253 E_EXCEPTION_DATA_UNALIGNED_WRITE, // Address error (store) 1254 E_EXCEPTION_CODE_ACCESS, // Bus error (Ifetch) 1255 E_EXCEPTION_DATA_ACCESS, // Bus error (data load or store) 1256 E_EXCEPTION_SYSTEM_CALL, // System call 1257 E_EXCEPTION_INSTRUCTION_BP, // Break point 1258 E_EXCEPTION_ILLEGAL_INSTRUCTION, // Reserved instruction 1259 E_EXCEPTION_COPROCESSOR, // Coprocessor unusable 1260 E_EXCEPTION_OVERFLOW, // Arithmetic overflow 1261 E_EXCEPTION_RESERVED_13, // Reserved 1262 E_EXCEPTION_DIV_BY_ZERO, // Division-by-zero [reserved vector] 1263 E_EXCEPTION_FPU, // Floating point exception 1264 E_EXCEPTION_MAX = E_EXCEPTION_FPU, 1265 } MHAL_EXCEPTION_TYPE; 1266 1267 typedef enum { 1268 E_INTERRUPT_02 = 0, 1269 E_INTERRUPT_03, 1270 E_INTERRUPT_04, 1271 E_INTERRUPT_05, 1272 E_INTERRUPT_06, 1273 E_INTERRUPT_07, 1274 } MHAL_INTERRUPT_TYPE; 1275 1276 // Aliases for interrupt number 1277 #define E_INTERRUPT_FIQ E_INTERRUPT_03 1278 #define E_INTERRUPT_IRQ E_INTERRUPT_02 1279 #define E_INTERRUPT_TICK_TIMER E_INTERRUPT_07 1280 #define E_INTERRUPT_MAX E_INTERRUPT_07 1281 #define E_EXCEPTION_TRAP E_EXCEPTION_RESERVED_13 1282 1283 typedef struct 1284 { 1285 // These are common to all saved states 1286 unsigned long d[32]; /* Data regs */ 1287 unsigned long hi; /* hi word of mpy/div reg */ 1288 unsigned long lo; /* lo word of mpy/div reg */ 1289 1290 // The status register contains the interrupt-enable bit which needs 1291 // to be preserved across context switches. 1292 unsigned long sr; /* Status Reg */ 1293 1294 // These are only saved for exceptions and interrupts 1295 unsigned long vector; /* Vector number */ 1296 unsigned long pc; /* Program Counter */ 1297 1298 // These are only saved for exceptions, and are not restored 1299 // when continued. 1300 unsigned long cause; /* Exception cause register */ 1301 unsigned long badvr; /* Bad virtual address reg */ 1302 1303 } MHAL_SavedRegisters; 1304 #endif 1305 1306 #if defined (__arm__) || defined (__aarch64__) 1307 typedef void (*mhal_isr_t)(void); 1308 #else 1309 #if defined(MSOS_TYPE_NUTTX) 1310 typedef int (*mhal_isr_t)(int irq, void *context); 1311 #else 1312 typedef void (*mhal_isr_t)(MHAL_SavedRegisters *regs, MS_U32 vector); 1313 #endif 1314 #endif 1315 1316 //------------------------------------------------------------------------------------------------- 1317 /// Disable the CPU interrupt 1318 /// @ingroup MsOS_ToBeRemove 1319 /// @return Interrupt register value before all interrupts disable 1320 //------------------------------------------------------------------------------------------------- 1321 // MS_U32 MsOS_CPU_DisableInterrupt (void); 1322 1323 //------------------------------------------------------------------------------------------------- 1324 /// Enable the CPU interrupt 1325 /// @ingroup MsOS_Interrupt_NOS 1326 /// @return TRUE : succeed 1327 //------------------------------------------------------------------------------------------------- 1328 MS_BOOL MsOS_CPU_EnableInterrupt (void); 1329 1330 //------------------------------------------------------------------------------------------------- 1331 /// Restore the CPU interrupt from last MsOS_CPU_DisableInterrupts. 1332 /// @ingroup MsOS_Interrupt_NOS 1333 /// @param u32OldInterrupts \b IN: Interrupt register value from @ref MsOS_CPU_DisableInterrupts 1334 /// @return TRUE : succeed 1335 //------------------------------------------------------------------------------------------------- 1336 // MS_BOOL MsOS_CPU_RestoreInterrupt (MS_U32 u32OldInterrupts); 1337 1338 //------------------------------------------------------------------------------------------------- 1339 /// Mask all the CPU interrupt 1340 /// @ingroup MsOS_Interrupt_NOS 1341 /// @return TRUE : succeed 1342 //------------------------------------------------------------------------------------------------- 1343 // MS_BOOL MsOS_CPU_MaskAllInterrupt (void); 1344 1345 //------------------------------------------------------------------------------------------------- 1346 /// Mask the CPU interrupt 1347 /// @ingroup MsOS_Interrupt_NOS 1348 /// @param intr_num \b IN: Interrupt number in enumerator MHAL_INTERRUPT_TYPE 1349 /// @return TRUE : succeed 1350 //------------------------------------------------------------------------------------------------- 1351 MS_BOOL MsOS_CPU_MaskInterrupt (MHAL_INTERRUPT_TYPE intr_num); 1352 1353 //------------------------------------------------------------------------------------------------- 1354 /// UnMask the CPU interrupt 1355 /// @ingroup MsOS_Interrupt_NOS 1356 /// @param intr_num \b IN: Interrupt number in enumerator MHAL_INTERRUPT_TYPE 1357 /// @return TRUE : succeed 1358 //------------------------------------------------------------------------------------------------- 1359 MS_BOOL MsOS_CPU_UnMaskInterrupt (MHAL_INTERRUPT_TYPE intr_num); 1360 1361 //------------------------------------------------------------------------------------------------- 1362 /// Lock the CPU interrupt 1363 /// @ingroup MsOS_Interrupt_NOS 1364 /// @return TRUE : succeed 1365 //------------------------------------------------------------------------------------------------- 1366 // MS_BOOL MsOS_CPU_LockInterrupt (void); 1367 1368 //------------------------------------------------------------------------------------------------- 1369 /// UnLock the CPU interrupt 1370 /// @ingroup MsOS_Interrupt_NOS 1371 /// @return TRUE : succeed 1372 //------------------------------------------------------------------------------------------------- 1373 // MS_BOOL MsOS_CPU_UnLockInterrupt (void); 1374 1375 //------------------------------------------------------------------------------------------------- 1376 /// Attach the CPU interrupt callback function to interrupt # 1377 /// @ingroup MsOS_Interrupt_NOS 1378 /// @param eIntNum \b IN: Interrupt number in enumerator InterruptNum 1379 /// @param pIntCb \b IN: Interrupt callback function 1380 /// @param dat \b IN: Data 1381 /// @return TRUE : succeed 1382 //------------------------------------------------------------------------------------------------- 1383 // MS_BOOL MsOS_CPU_AttachInterrupt (MHAL_INTERRUPT_TYPE intr_num, mhal_isr_t isr, MS_U32 dat); 1384 1385 //------------------------------------------------------------------------------------------------- 1386 /// Detach the CPU interrupt callback function to interrupt # 1387 /// @ingroup MsOS_Interrupt_NOS 1388 /// @param eIntNum \b IN: Interrupt number in enumerator InterruptNum 1389 /// @param pIntCb \b IN: Interrupt callback function 1390 /// @param dat \b IN: Data 1391 /// @return TRUE : succeed 1392 //------------------------------------------------------------------------------------------------- 1393 // MS_BOOL MsOS_CPU_DetachInterrupt (MHAL_INTERRUPT_TYPE intr_num); 1394 1395 //------------------------------------------------------------------------------------------------- 1396 /// Attach the CPU exception callback function to interrupt # 1397 /// @ingroup MsOS_Interrupt_NOS 1398 /// @param eIntNum \b IN: Exception number in enumerator InterruptNum 1399 /// @param pIntCb \b IN: Exception callback function 1400 /// @param dat \b IN: Data 1401 /// @return TRUE : succeed 1402 //------------------------------------------------------------------------------------------------- 1403 // MS_BOOL MsOS_CPU_AttachException (MHAL_EXCEPTION_TYPE expt_num, mhal_isr_t isr, MS_U32 dat); 1404 1405 //------------------------------------------------------------------------------------------------- 1406 /// Detach the CPU exception callback function to interrupt # 1407 /// @ingroup MsOS_Interrupt_NOS 1408 /// @param eIntNum \b IN: Exception number in enumerator InterruptNum 1409 /// @param pIntCb \b IN: Exception callback function 1410 /// @param dat \b IN: Data 1411 /// @return TRUE : succeed 1412 //------------------------------------------------------------------------------------------------- 1413 // MS_BOOL MsOS_CPU_DetachExceptiont (MHAL_EXCEPTION_TYPE expt_num); 1414 1415 //------------------------------------------------------------------------------------------------- 1416 /// Set EBASE 1417 /// @ingroup MsOS_Interrupt_NOS 1418 /// @param u32Addr \b IN: MIPS Code Start Address 1419 /// @return TRUE : succeed 1420 //------------------------------------------------------------------------------------------------- 1421 // MS_BOOL MsOS_CPU_SetEBASE (MS_U32 u32Addr); 1422 1423 //------------------------------------------------------------------------------------------------- 1424 /// Write back if dirty & Invalidate the cache lines in the given range 1425 /// @ingroup MsOS_MPool 1426 /// @param u32Start \b IN: start address (must be 16-B aligned and in cacheable area) 1427 /// @param u32Size \b IN: size (must be 16-B aligned) 1428 /// @return TRUE : succeed 1429 /// @return FALSE : fail due to invalide parameter 1430 //------------------------------------------------------------------------------------------------- 1431 MS_BOOL MsOS_Dcache_Flush( MS_VIRT ptrStart, MS_SIZE tSize ); 1432 1433 //------------------------------------------------------------------------------------------------- 1434 /// Write back if dirty & Invalidate whole the cache 1435 /// @ingroup MsOS_MPool 1436 /// @return TRUE : succeed 1437 /// @return FALSE : fail due to invalide parameter 1438 //------------------------------------------------------------------------------------------------- 1439 // MS_BOOL MsOS_Dcache_Flush_All(void); 1440 1441 //------------------------------------------------------------------------------------------------- 1442 /// Invalidate the cache lines in the given range 1443 /// @ingroup MsOS_MPool 1444 /// @param u32Start \b IN: start address (must be 16-B aligned and in cacheable area) 1445 /// @param u32Size \b IN: size (must be 16-B aligned) 1446 /// @return TRUE : succeed 1447 /// @return FALSE : fail due to invalide parameter 1448 //------------------------------------------------------------------------------------------------- 1449 MS_BOOL MsOS_Dcache_Invalidate( MS_VIRT ptrStart , MS_SIZE tSize ); 1450 1451 //------------------------------------------------------------------------------------------------- 1452 /// Write back if dirty the cache lines in the given range 1453 /// @ingroup MsOS_MPool 1454 /// @param u32Start \b IN: start address (must be 16-B aligned and in cacheable area) 1455 /// @param u32Size \b IN: size (must be 16-B aligned) 1456 /// @return TRUE : succeed 1457 /// @return FALSE : fail due to invalide parameter 1458 //------------------------------------------------------------------------------------------------- 1459 // MS_BOOL MsOS_Dcache_Writeback( MS_VIRT ptrStart , MS_SIZE tSize ); 1460 1461 #if defined(CHIP_T12) || defined(CHIP_T8) || defined(CHIP_J2) || defined(CHIP_A2) || defined(CHIP_A5) || defined(CHIP_A3) || defined(CHIP_Edison) 1462 1463 //------------------------------------------------------------------------------------------------- 1464 /// MsOS_L2Cache_Flush (Detail need to be done.) 1465 /// @ingroup MsOS_ToBeRemove 1466 /// @return TRUE : succeed 1467 /// @return FALSE : fail due to invalide parameter 1468 //------------------------------------------------------------------------------------------------- 1469 MS_BOOL MsOS_L2Cache_Flush(void); 1470 1471 //------------------------------------------------------------------------------------------------- 1472 /// MsOS_ReadMemory (Detail need to be done.) 1473 /// @ingroup MsOS_ToBeRemove 1474 /// @return TRUE : succeed 1475 /// @return FALSE : fail due to invalide parameter 1476 //------------------------------------------------------------------------------------------------- 1477 MS_BOOL MsOS_L2Cache_Read(void); 1478 #endif 1479 1480 // 1481 // CPU relative Operation 1482 // 1483 //------------------------------------------------------------------------------------------------- 1484 /// MsOS_Sync (Detail need to be done.) 1485 /// @ingroup MsOS_ToBeRemove 1486 /// @return TRUE : succeed 1487 /// @return FALSE : fail due to invalide parameter 1488 //------------------------------------------------------------------------------------------------- 1489 void MsOS_Sync(void); 1490 1491 typedef enum //_MsOSMPool_DbgLevel 1492 { 1493 E_MsOSMPool_DBG_Release = 0, 1494 E_MsOSMPool_DBG_L1, // display error msg 1495 } MsOSMPool_DbgLevel; 1496 1497 // Kernel related information 1498 //------------------------------------------------------------------------------------------------- 1499 /// System information 1500 /// @ingroup MsOS_BASIC 1501 /// @param SysInfo \b IN: SysInfo from user 1502 /// @return TRUE(Success), FALSE(Failure) 1503 //------------------------------------------------------------------------------------------------- 1504 MS_BOOL MDrv_SYS_Info(IO_Sys_Info_t* SysInfo); 1505 // MPool Operation 1506 //------------------------------------------------------------------------------------------------- 1507 /// Set MPool Debug level 1508 /// @ingroup MsOS_BASIC 1509 /// @return TRUE(Success), FALSE(Failure) 1510 //------------------------------------------------------------------------------------------------- 1511 void MsOS_MPool_SetDbgLevel(MsOSMPool_DbgLevel DbgLevel); 1512 1513 //------------------------------------------------------------------------------------------------- 1514 /// Check MPool driver is initialized or not 1515 /// @ingroup MsOS_ToBeRemove 1516 /// @return TRUE(Success), FALSE(Failure) 1517 //------------------------------------------------------------------------------------------------- 1518 // MS_BOOL MsOS_MPool_IsInitialized(void); 1519 1520 //------------------------------------------------------------------------------------------------- 1521 /// Init MPool driver 1522 /// @ingroup MsOS_ToBeModified 1523 /// @return TRUE(Success), FALSE(Failure) 1524 //------------------------------------------------------------------------------------------------- 1525 MS_BOOL MsOS_MPool_Init(void); 1526 1527 //------------------------------------------------------------------------------------------------- 1528 /// Check ION driver is initialized or not 1529 /// @ingroup MsOS_ION 1530 /// @return TRUE(Success), FALSE(Failure) 1531 //------------------------------------------------------------------------------------------------- 1532 // MS_BOOL MsOS_ION_IsInitialized(void); 1533 1534 //------------------------------------------------------------------------------------------------- 1535 /// Init ION driver 1536 /// @ingroup MsOS_ION 1537 /// @return TRUE(Success), FALSE(Failure) 1538 //------------------------------------------------------------------------------------------------- 1539 // MS_BOOL MsOS_ION_Init(void); 1540 1541 //------------------------------------------------------------------------------------------------- 1542 /// Setting MPool driver 1543 /// @ingroup MsOS_MPool 1544 /// @param pAddrVirt \b IN: Virtual address that get from kernel mpool driver 1545 /// @param pu32AddrPhys \b IN: Physical address about to be mapped 1546 /// @param pu32Size \b IN: Size that to be mapped 1547 /// @param bNonCache \b IN: Is Non-cache or not (1:Non-cache, 0:Cache) 1548 /// @return TRUE : succeed 1549 /// @return FALSE : fail due to invalide parameter 1550 //------------------------------------------------------------------------------------------------- 1551 MS_BOOL MsOS_MPool_Get(void** pAddrVirt, MS_U32* pu32AddrPhys, MS_U32* pu32Size, MS_BOOL bNonCache); 1552 1553 //------------------------------------------------------------------------------------------------- 1554 /// Close MPool driver 1555 /// @ingroup MsOS_MPool 1556 /// @return TRUE : succeed 1557 /// @return FALSE : fail due to invalide parameter 1558 //------------------------------------------------------------------------------------------------- 1559 MS_BOOL MsOS_MPool_Close(void); 1560 1561 //------------------------------------------------------------------------------------------------- 1562 /// Get MPool information (Total mapping/Used VA/Free VA) 1563 /// @ingroup MsOS_MPool 1564 /// @return TRUE : succeed 1565 /// @return FALSE : fail due to invalide parameter 1566 //------------------------------------------------------------------------------------------------- 1567 // void MsOS_MPool_InfoMsg(MS_U8 u8MsgType); 1568 1569 //------------------------------------------------------------------------------------------------- 1570 /// Close ION driver 1571 /// @ingroup MsOS_ION 1572 /// @return TRUE : succeed 1573 /// @return FALSE : fail due to invalide parameter 1574 //------------------------------------------------------------------------------------------------- 1575 // MS_BOOL MsOS_ION_Close(void); 1576 1577 //------------------------------------------------------------------------------------------------- 1578 /// Get Physical address from user by using Virtual address 1579 /// @ingroup MsOS_ToBeRemove 1580 /// @param pAddrVirt \b IN: Virtual address 1581 /// @return TRUE : succeed 1582 /// @return FALSE : fail due to invalide parameter 1583 //------------------------------------------------------------------------------------------------- 1584 MS_PHY MsOS_MPool_VA2PA(MS_VIRT pAddrVirt); 1585 1586 //------------------------------------------------------------------------------------------------- 1587 /// Get Virtual address from user by using Physical address (Non-Cache) 1588 /// @ingroup MsOS_ToBeRemove 1589 /// @param pAddrPhys \b IN: Physical address 1590 /// @return TRUE : succeed 1591 /// @return FALSE : fail due to invalide parameter 1592 //------------------------------------------------------------------------------------------------- 1593 MS_VIRT MsOS_MPool_PA2KSEG1(MS_PHY pAddrPhys); 1594 1595 //------------------------------------------------------------------------------------------------- 1596 /// Get Virtual address from user by using Physical address (Cache) 1597 /// @ingroup MsOS_ToBeRemove 1598 /// @param pAddrPhys \b IN: Physical address 1599 /// @return TRUE : succeed 1600 /// @return FALSE : fail due to invalide parameter 1601 //------------------------------------------------------------------------------------------------- 1602 MS_VIRT MsOS_MPool_PA2KSEG0(MS_PHY pAddrPhys); 1603 1604 //------------------------------------------------------------------------------------------------- 1605 /// Write back if dirty & Invalidate the cache lines in the given range 1606 /// @ingroup MsOS_ToBeRemove 1607 /// @param pAddrVirt \b IN: start address (must be 16-B aligned and in cacheable area) 1608 /// @param u32Size \b IN: size (must be 16-B aligned) 1609 /// @return TRUE : succeed 1610 /// @return FALSE : fail due to invalide parameter 1611 //------------------------------------------------------------------------------------------------- 1612 MS_BOOL MsOS_MPool_Dcache_Flush(MS_VIRT pAddrVirt, MS_SIZE tSize); // the input address should be user mode cacheable address 1613 1614 //------------------------------------------------------------------------------------------------- 1615 /// Write back if dirty & Invalidate whole the cache 1616 /// @ingroup MsOS_ToBeRemove 1617 /// @return TRUE : succeed 1618 /// @return FALSE : fail due to invalide parameter 1619 //------------------------------------------------------------------------------------------------- 1620 MS_BOOL MsOS_MPool_Dcache_Flush_All(void); 1621 1622 //------------------------------------------------------------------------------------------------- 1623 /// Mapping MPool driver 1624 /// @ingroup MsOS_MPool 1625 /// @param u8MiuSel \b IN: Virtual address that get from kernel mpool driver 1626 /// @param u32Offset \b IN: Physical address about to be mapped 1627 /// @param u32MapSize \b IN: Size that to be mapped 1628 /// @param bNonCache \b IN: Is Non-cache or not (1:Non-cache, 0:Cache) 1629 /// @return TRUE : succeed 1630 /// @return FALSE : fail due to invalide parameter 1631 //------------------------------------------------------------------------------------------------- 1632 MS_BOOL MsOS_MPool_Mapping(MS_U8 u8MiuSel, MS_SIZE tOffset, MS_SIZE tMapSize, MS_BOOL bNonCache); 1633 1634 //------------------------------------------------------------------------------------------------- 1635 /// Unmapping MPool driver 1636 /// @ingroup MsOS_MPool 1637 /// @param u32VirtStart \b IN: Virtual address that get from kernel mpool driver 1638 /// @param u32MapSize \b IN: The size that to be unmapped 1639 /// @return TRUE : succeed 1640 /// @return FALSE : fail due to invalide parameter 1641 //------------------------------------------------------------------------------------------------- 1642 MS_BOOL MsOS_MPool_UnMapping(MS_VIRT ptrVirtStart, MS_SIZE tMapSize); 1643 1644 //------------------------------------------------------------------------------------------------- 1645 /// Mapping MPool driver (dynamc) 1646 /// @ingroup MsOS_ToBeRemove 1647 /// @param u8MiuSel \b IN: Virtual address that get from kernel mpool driver 1648 /// @param u32Offset \b IN: Physical address about to be mapped 1649 /// @param u32MapSize \b IN: Size that to be mapped 1650 /// @param bNonCache \b IN: Is Non-cache or not (1:Non-cache, 0:Cache) 1651 /// @return TRUE : succeed 1652 /// @return FALSE : fail due to invalide parameter 1653 //------------------------------------------------------------------------------------------------- 1654 MS_BOOL MsOS_MPool_Mapping_Dynamic(MS_U8 u8MiuSel, MS_SIZE u32Offset, MS_SIZE u32MapSize, MS_BOOL bNonCache); 1655 1656 //------------------------------------------------------------------------------------------------- 1657 /// Get the size of Linux kernel 1658 /// @ingroup MsOS_ToBeRemove 1659 /// @param lx_addr \b IN: address of lx memory 1660 /// @param lx_size \b IN: size of lx memory 1661 /// @param lx2_addr \b IN: address of lx2 memory 1662 /// @param lx2_size \b IN: size of lx2 memory 1663 /// @return TRUE : succeed 1664 /// @return FALSE : fail due to invalide parameter 1665 //------------------------------------------------------------------------------------------------- 1666 // MS_BOOL MsOS_MPool_Kernel_Detect(MS_PHY *lx_addr, MS_U64 *lx_size, MS_PHY *lx2_addr, MS_U64 *lx2_size); 1667 1668 //------------------------------------------------------------------------------------------------- 1669 /// Set watch point 1670 /// @ingroup MsOS_BASIC 1671 /// @param u32Addr \b IN: address to be set watch point 1672 /// @param u32ASID \b IN: the ASID of process 1673 /// @param u8Global \b IN: Global value 1674 /// @param u8WType \b IN: Watch point type 1675 /// @param u32Mask \b IN: mask 1676 /// @return TRUE : succeed 1677 /// @return FALSE : fail due to invalide parameter 1678 //------------------------------------------------------------------------------------------------- 1679 // MS_BOOL MsOS_MPool_SetWatchPT(MS_VIRT u32Addr, MS_U32 u32ASID, MS_U8 u8Global, MS_U8 u8WType, MS_U32 u32Mask); 1680 1681 //------------------------------------------------------------------------------------------------- 1682 /// Get watch point 1683 /// @ingroup MsOS_BASIC 1684 /// @param str \b IN: Get the watch pointer address 1685 /// @return TRUE : succeed 1686 /// @return FALSE : fail due to invalide parameter 1687 //------------------------------------------------------------------------------------------------- 1688 // MS_BOOL MsOS_MPool_GetWatchPT(char* str); 1689 1690 //------------------------------------------------------------------------------------------------- 1691 /// Set watch point 1692 //------------------------------------------------------------------------------------------------- 1693 //------------------------------------------------------------------------------------------------- 1694 /// ION Mapping (Detail need to be done.) 1695 /// @ingroup MsOS_ION 1696 /// @return TRUE : succeed 1697 /// @return FALSE : fail due to invalide parameter 1698 //------------------------------------------------------------------------------------------------- 1699 // MS_U32 MsOS_ION_Mapping(MS_U32 u32ION_Alloc_Flag, MS_U8 u8ION_FixAddr_MiuSel, MS_U32 u32ION_FixAddrOffset, MS_U32 u32MapSize, MS_U32 u32Driver_Heap_ID, MS_BOOL bNonCache); 1700 1701 #define MsOS_MPool_PA2VA MsOS_MPool_PA2KSEG1 1702 1703 //------------------------------------------------------------------------------------------------- 1704 // /// MsOS_Mapping_SharedMem (Detail need to be done.) 1705 // /// @ingroup MsOS_Task 1706 // /// @return TRUE : succeed 1707 // /// @return FALSE : fail due to invalide parameter 1708 // //------------------------------------------------------------------------------------------------- 1709 // // MS_VIRT MsOS_Mapping_SharedMem(MS_U32 u32ShmSize,MS_BOOL *bInit); 1710 1711 //------------------------------------------------------------------------------------------------- 1712 /// MsOS_CreateNamedMutex (Detail need to be done.) 1713 /// @ingroup MsOS_Task 1714 /// @return TRUE : succeed 1715 /// @return FALSE : fail due to invalide parameter 1716 //------------------------------------------------------------------------------------------------- 1717 MS_S32 MsOS_CreateNamedMutex(MS_S8 *ps8MutexName); 1718 1719 //------------------------------------------------------------------------------------------------- 1720 /// MsOS_LockMutex (Detail need to be done.) 1721 /// @ingroup MsOS_Task 1722 /// @return TRUE : succeed 1723 /// @return FALSE : fail due to invalide parameter 1724 //------------------------------------------------------------------------------------------------- 1725 MS_BOOL MsOS_LockMutex(MS_S32 u32Index,MS_S32 flag); 1726 1727 //------------------------------------------------------------------------------------------------- 1728 /// MsOS_LockMutex (Detail need to be done.) 1729 /// @ingroup MsOS_Task 1730 /// @return TRUE : succeed 1731 /// @return FALSE : fail due to invalide parameter 1732 //------------------------------------------------------------------------------------------------- 1733 MS_BOOL MsOS_UnlockMutex(MS_S32 u32Index,MS_S32 flag); 1734 1735 //------------------------------------------------------------------------------------------------- 1736 // /// MsOS_DeleteNamedMutexbyIndex (Detail need to be done.) 1737 // /// @ingroup MsOS_Task 1738 // /// @return TRUE : succeed 1739 // /// @return FALSE : fail due to invalide parameter 1740 // //------------------------------------------------------------------------------------------------- 1741 // // MS_BOOL MsOS_DeleteNamedMutexbyIndex(MS_S32 u32Index); 1742 1743 //------------------------------------------------------------------------------------------------- 1744 // /// MsOS_MPool_Add_PA2VARange (Detail need to be done.) 1745 // /// @ingroup MsOS_MPool 1746 // /// @return TRUE : succeed 1747 // /// @return FALSE : fail due to invalide parameter 1748 // //------------------------------------------------------------------------------------------------- 1749 // // MS_BOOL __attribute__((weak)) MsOS_MPool_Add_PA2VARange(MS_U64 u64PhysAddr, MS_VIRT u64VirtAddr, MS_SIZE u64MapSize, MS_BOOL bNonCache); 1750 1751 //------------------------------------------------------------------------------------------------- 1752 // /// MsOS_MPool_Remove_PA2VARange (Detail need to be done.) 1753 // /// @ingroup MsOS_MPool 1754 // /// @return TRUE : succeed 1755 // /// @return TRUE : succeed 1756 // /// @return FALSE : fail due to invalide parameter 1757 // //------------------------------------------------------------------------------------------------- 1758 // // MS_BOOL __attribute__((weak)) MsOS_MPool_Remove_PA2VARange(MS_U64 u64PhysAddr, MS_VIRT u64VirtAddr, MS_SIZE u64MapSize, MS_BOOL bNonCache); 1759 // Share memory operation 1760 #define MAX_CLIENT_NAME_LENGTH 50UL 1761 #define MSOS_SHM_QUERY 0x00000000UL 1762 #define MSOS_SHM_CREATE 0x00000001UL 1763 1764 //------------------------------------------------------------------------------------------------- 1765 /// MsOS_SHM_Init (Detail need to be done.) 1766 /// @ingroup MsOS_Task 1767 /// @return TRUE : succeed 1768 /// @return TRUE : succeed 1769 /// @return FALSE : fail due to invalide parameter 1770 //------------------------------------------------------------------------------------------------- 1771 MS_BOOL MsOS_SHM_Init(void); 1772 1773 //------------------------------------------------------------------------------------------------- 1774 /// MsOS_SHM_GetId (Detail need to be done.) 1775 /// @ingroup MsOS_Task 1776 /// @return TRUE : succeed 1777 /// @return FALSE : fail due to invalide parameter 1778 //------------------------------------------------------------------------------------------------- 1779 MS_BOOL MsOS_SHM_GetId(MS_U8* pu8ClientName, MS_U32 u32BufSize, MS_U32* pu32ShmId, MS_VIRT* pu32Addr, MS_U32* pu32BufSize, MS_U32 u32Flag); 1780 1781 //------------------------------------------------------------------------------------------------- 1782 // /// MsOS_SHM_FreeId (Detail need to be done.) 1783 // /// @ingroup MsOS_Task 1784 // /// @return TRUE : succeed 1785 // /// @return FALSE : fail due to invalide parameter 1786 // //------------------------------------------------------------------------------------------------- 1787 // // MS_BOOL MsOS_SHM_FreeId(MS_U8* pu8ClientName, MS_U32 u32ShmId); 1788 #if defined (MSOS_TYPE_NOS) 1789 //------------------------------------------------------------------------------------------------- 1790 /// MsOS_MEM_GetId (Detail need to be done.) 1791 /// @ingroup MsOS_Task 1792 /// @return TRUE : succeed 1793 /// @return FALSE : fail due to invalide parameter 1794 //------------------------------------------------------------------------------------------------- 1795 MS_BOOL MsOS_MEM_GetId(MS_U8* pu8ClientName, MS_U32 u32BufSize, MS_U32* pu32ShmId, MS_VIRT* pu32Addr, MS_U32* pu32BufSize, MS_U32 u32Flag); 1796 #endif 1797 1798 // 1799 // OS Dependent Macro 1800 // 1801 1802 // Worldwide thread safe macro 1803 // Usage: 1804 // MS_S32 os_X_MutexID; 1805 // os_X_MutexID = OS_CREATE_MUTEX(_M_); 1806 // if (os_X_MutexID < 0) { return FALSE; } 1807 // if (OS_OBTAIN_MUTEX(os_X_MutexID, 1000) == FALSE) { return FALSE; } 1808 // ... 1809 // OS_RELEASE_MUTEX(os_X_MutexID); 1810 // return X; 1811 // 1812 1813 #define OS_CREATE_MUTEX(_M_) MsOS_CreateMutex(E_MSOS_FIFO, "OS_"#_M_"_Mutex", MSOS_PROCESS_SHARED) 1814 #define OS_OBTAIN_MUTEX(_mx, _tm) MsOS_ObtainMutex(_mx, _tm) 1815 #define OS_RELEASE_MUTEX(_mx) MsOS_ReleaseMutex(_mx) 1816 #define OS_DELETE_MUTEX(_mx) MsOS_DeleteMutex(_mx) 1817 #define OS_DELAY_TASK(_msec) MsOS_DelayTask(_msec) 1818 #define OS_SYSTEM_TIME() MsOS_GetSystemTime() 1819 #define OS_ENTER_CRITICAL() MsOS_DisableAllInterrupts(); 1820 #define OS_EXIT_CRITICAL() MsOS_EnableAllInterrupts(); 1821 1822 //------------------------------------------------------------------------------------------------- 1823 // Virutal/Physial address operation 1824 //------------------------------------------------------------------------------------------------- 1825 //------------------------------------------------------------------------------------------------- 1826 /// MsOS_VA2PA (Detail need to be done.) 1827 /// @ingroup MsOS_MPool 1828 /// @return TRUE : succeed 1829 /// @return FALSE : fail due to invalide parameter 1830 //------------------------------------------------------------------------------------------------- 1831 MS_PHY MsOS_VA2PA(MS_VIRT addr); 1832 1833 //------------------------------------------------------------------------------------------------- 1834 /// MsOS_PA2KSEG0 (Detail need to be done.) 1835 /// @ingroup MsOS_MPool 1836 /// @return TRUE : succeed 1837 /// @return FALSE : fail due to invalide parameter 1838 //------------------------------------------------------------------------------------------------- 1839 MS_VIRT MsOS_PA2KSEG0(MS_PHY addr); 1840 1841 //------------------------------------------------------------------------------------------------- 1842 /// MsOS_PA2KSEG1 (Detail need to be done.) 1843 /// @ingroup MsOS_MPool 1844 /// @return TRUE : succeed 1845 /// @return FALSE : fail due to invalide parameter 1846 //------------------------------------------------------------------------------------------------- 1847 MS_VIRT MsOS_PA2KSEG1(MS_PHY addr); 1848 1849 //------------------------------------------------------------------------------------------------- 1850 /// MsOS_PA2BA (Detail need to be done.) 1851 /// @ingroup MsOS_MPool 1852 /// @return TRUE : succeed 1853 /// @return FALSE : fail due to invalide parameter 1854 //------------------------------------------------------------------------------------------------- 1855 MS_PHY MsOS_PA2BA(MS_PHY PhyAddr); 1856 1857 //------------------------------------------------------------------------------------------------- 1858 /// MsOS_BA2PA (Detail need to be done.) 1859 /// @ingroup MsOS_MPool 1860 /// @return TRUE : succeed 1861 /// @return FALSE : fail due to invalide parameter 1862 //------------------------------------------------------------------------------------------------- 1863 MS_PHY MsOS_BA2PA(MS_PHY BusAddr); 1864 1865 //------------------------------------------------------------------------------------------------- 1866 /// MsOS_FlushMemory (Detail need to be done.) 1867 /// @ingroup MsOS_MPool 1868 /// @return TRUE : succeed 1869 /// @return FALSE : fail due to invalide parameter 1870 //------------------------------------------------------------------------------------------------- 1871 void MsOS_FlushMemory(void); 1872 1873 //------------------------------------------------------------------------------------------------- 1874 /// MsOS_ReadMemory (Detail need to be done.) 1875 /// @ingroup MsOS_MPool 1876 /// @return TRUE : succeed 1877 /// @return FALSE : fail due to invalide parameter 1878 //------------------------------------------------------------------------------------------------- 1879 void MsOS_ReadMemory(void); 1880 1881 //------------------------------------------------------------------------------------------------- 1882 // /// MsOS_GetKattribute (Detail need to be done.) 1883 // /// @ingroup MsOS_BASIC 1884 // /// @return TRUE : succeed 1885 // /// @return FALSE : fail due to invalide parameter 1886 // //------------------------------------------------------------------------------------------------- 1887 // // MS_U32 MsOS_GetKattribute(char *pAttr); 1888 1889 #define MS_VA2PA(_addr_) (MS_PHY)MsOS_VA2PA((_addr_)) 1890 #define MS_PA2KSEG0(_addr_) (MS_VIRT)MsOS_PA2KSEG0((_addr_)) 1891 #define MS_PA2KSEG1(_addr_) (MS_VIRT)MsOS_PA2KSEG1((_addr_)) 1892 1893 //------------------------------------------------------------------------------------------------- 1894 // Debug message 1895 //------------------------------------------------------------------------------------------------- 1896 #define MS_CRITICAL_MSG(x) x // for dump critical message 1897 #define MS_FATAL_MSG(fmt,...) printf( "[MS_FATAL]: %s: %d \n" fmt, __FUNCTION__, __LINE__, ## __VA_ARGS__) 1898 1899 1900 #if defined (MSOS_TYPE_LINUX_KERNEL) 1901 #define printf printk // utopia being a kernel driver should use printk 1902 #endif 1903 1904 #if defined (MS_DEBUG) 1905 #define MS_DEBUG_MSG(x) x 1906 #elif defined (MS_OPTIMIZE) 1907 #define MS_DEBUG_MSG(x) // retail version remove debug message 1908 #endif 1909 1910 //------------------------------------------------------------------------------------------------- 1911 // debug 1912 //------------------------------------------------------------------------------------------------- 1913 // extern void MsOS_RegMyDbg(void); ///< MsOS debug register itself debug 1914 1915 typedef MS_BOOL (*UartDbg_IP_CallBack) (int argc, char *argv[]); ///< MsOS debug call back function prototype 1916 1917 ///< define your own name, help, callback mapping here 1918 typedef struct 1919 { 1920 const char *Func_Name; 1921 const char *Func_Help; 1922 UartDbg_IP_CallBack pCallBack; 1923 } MS_DBG_LINK; 1924 1925 ///< for application to pass debug command into MsOS debug module 1926 // extern MS_BOOL MsOS_Dbg_ParseCmd(char *Cmd, MS_U32 u32CmdLen); 1927 1928 ///< register your main menu here 1929 // extern MS_BOOL MsOS_Dbg_Regist(const char *Func_Name, const char *Func_Help, MS_DBG_LINK *pAryDbgLink); 1930 1931 ///< for user to handle their own sub menu 1932 // extern MS_BOOL MsOS_Dbg_ExecuteSubCB(const char *Func_Name, int argc, char *argv[], MS_DBG_LINK *pAryDbgLink); 1933 1934 #ifdef __cplusplus 1935 } 1936 #endif 1937 1938 #endif // _MS_OS_H_ 1939