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