| 1 | /**************************************************************************** |
|---|
| 2 | * Copyright (c) 2006 DST Technologies Inc. All Rights Reserved. |
|---|
| 3 | * |
|---|
| 4 | * Module: OS |
|---|
| 5 | * |
|---|
| 6 | * Description: Unified APIs for interfacing with different operating systems |
|---|
| 7 | * |
|---|
| 8 | * Notes: This module containes defines to interface with the following |
|---|
| 9 | * operating system's objects: |
|---|
| 10 | * - Tasks |
|---|
| 11 | * - Mutexes |
|---|
| 12 | * - Events |
|---|
| 13 | * - Timers |
|---|
| 14 | * - Qeueus |
|---|
| 15 | * - Semaphores |
|---|
| 16 | * - Memory |
|---|
| 17 | * - Persistent Storage (NVM) |
|---|
| 18 | * - Processes |
|---|
| 19 | * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | #ifndef OS_H_ |
|---|
| 22 | #define OS_H_ |
|---|
| 23 | |
|---|
| 24 | #ifdef __cplusplus |
|---|
| 25 | extern "C" |
|---|
| 26 | { |
|---|
| 27 | #endif |
|---|
| 28 | |
|---|
| 29 | #include "oem_opt.h" |
|---|
| 30 | |
|---|
| 31 | /*========================== |
|---|
| 32 | * Global defines |
|---|
| 33 | *=========================*/ |
|---|
| 34 | enum |
|---|
| 35 | { |
|---|
| 36 | OS_VRTX, |
|---|
| 37 | OS_LINUX, |
|---|
| 38 | OS_WINCE, |
|---|
| 39 | OS_VXWORKS, |
|---|
| 40 | OS_WIN9X, |
|---|
| 41 | OS_WINNT, |
|---|
| 42 | OS_PSOS, |
|---|
| 43 | OS_QNX, |
|---|
| 44 | OS_MSDOS, |
|---|
| 45 | OS_PMON, |
|---|
| 46 | OS_POWERTV |
|---|
| 47 | }; |
|---|
| 48 | |
|---|
| 49 | #define OS_OK 0 |
|---|
| 50 | #define OS_TIMEOUT 1 |
|---|
| 51 | #define OS_FAIL 2 |
|---|
| 52 | #define OS_NOT_SUPPORTED 3 |
|---|
| 53 | #ifndef OS_WAIT_FOREVER |
|---|
| 54 | #define OS_WAIT_FOREVER 0xFFFFFFFF |
|---|
| 55 | #endif |
|---|
| 56 | |
|---|
| 57 | #define CORE_TASK_ID DS_U32 |
|---|
| 58 | #define CORE_LOCK_ID DS_U32 |
|---|
| 59 | #define CORE_SEM_ID DS_U32 |
|---|
| 60 | #define CORE_MUTEX_ID DS_U32 |
|---|
| 61 | #define CORE_EVENT_ID DS_U32 |
|---|
| 62 | #define CORE_QUEUE_ID DS_U32 |
|---|
| 63 | #define CORE_TIMER_ID DS_U32 |
|---|
| 64 | #define CORE_NOTIFYQ_ID DS_U32 |
|---|
| 65 | #define CORE_UIRT_ID DS_U32 |
|---|
| 66 | |
|---|
| 67 | #define CORE_INVALID_ID 0x0 |
|---|
| 68 | |
|---|
| 69 | #define TASK_PRIOR_CALLER 0x01000000 |
|---|
| 70 | #define TASK_PRIOR_LOWEST 0x00ff0000 |
|---|
| 71 | #define TASK_PRIOR_LOW 0x00800000 |
|---|
| 72 | #define TASK_PRIOR_NORMAL 0x00400000 |
|---|
| 73 | #define TASK_PRIOR_HIGH 0x00100000 |
|---|
| 74 | #define TASK_PRIOR_HIGHEST 0x00010000 |
|---|
| 75 | #define TASK_PRIOR_IST 0x02000000 |
|---|
| 76 | |
|---|
| 77 | typedef enum |
|---|
| 78 | { |
|---|
| 79 | CORE_OK = 0, |
|---|
| 80 | CORE_ERROR, |
|---|
| 81 | CORE_TIMEOUT, |
|---|
| 82 | CORE_INVALID_PARAM, |
|---|
| 83 | CORE_INVALID_HANDLE, |
|---|
| 84 | CORE_OPEN_FAILED |
|---|
| 85 | } CORE_RESULT; |
|---|
| 86 | |
|---|
| 87 | //yzyeo |
|---|
| 88 | #define MSGQ_SIZE |
|---|
| 89 | |
|---|
| 90 | typedef void (INTER_PROC_FUNC)(DS_S32, void *); |
|---|
| 91 | typedef INTER_PROC_FUNC *INTER_PROC_CALL; |
|---|
| 92 | |
|---|
| 93 | typedef struct |
|---|
| 94 | { |
|---|
| 95 | DS_U32 PhysAddr; |
|---|
| 96 | DS_U32 VirtAddr; |
|---|
| 97 | DS_U32 Length; |
|---|
| 98 | } PHYS_BLOCK; |
|---|
| 99 | |
|---|
| 100 | /*========================== |
|---|
| 101 | * Global prototypes |
|---|
| 102 | *=========================*/ |
|---|
| 103 | |
|---|
| 104 | /*---------------------- |
|---|
| 105 | * Tasks |
|---|
| 106 | *---------------------*/ |
|---|
| 107 | CORE_TASK_ID DstCore_TaskCreate (void (*TaskFuncPtr) (void *), |
|---|
| 108 | void *Parameter, DS_U32 Priority); |
|---|
| 109 | DS_U32 DstCore_TaskSuspend (CORE_TASK_ID TaskId); |
|---|
| 110 | DS_U32 DstCore_TaskResume (CORE_TASK_ID TaskId); |
|---|
| 111 | DS_U32 DstCore_TaskGetInfo (CORE_TASK_ID *TaskId); |
|---|
| 112 | DS_U32 DstCore_TaskSetPriority (CORE_TASK_ID TaskId, DS_U32 Priority); |
|---|
| 113 | DS_U32 DstCore_TaskDelete (CORE_TASK_ID TaskId); |
|---|
| 114 | |
|---|
| 115 | /*---------------------- |
|---|
| 116 | * Task locks |
|---|
| 117 | *---------------------*/ |
|---|
| 118 | CORE_LOCK_ID DstCore_TaskLockCreate (void); |
|---|
| 119 | DS_U32 DstCore_TaskLockSet (CORE_LOCK_ID LockId); |
|---|
| 120 | DS_U32 DstCore_TaskLockReset (CORE_LOCK_ID LockId); |
|---|
| 121 | DS_U32 DstCore_TaskLockDelete (CORE_LOCK_ID LockId); |
|---|
| 122 | |
|---|
| 123 | /*---------------------- |
|---|
| 124 | * Mutexes |
|---|
| 125 | *---------------------*/ |
|---|
| 126 | CORE_MUTEX_ID DstCore_MutexCreate (DS_U32 MutexName); |
|---|
| 127 | DS_U32 DstCore_MutexLock (CORE_MUTEX_ID MutexId, DS_U32 Timeout); |
|---|
| 128 | DS_U32 DstCore_MutexUnlock (CORE_MUTEX_ID MutexId); |
|---|
| 129 | DS_U32 DstCore_MutexDelete (CORE_MUTEX_ID MutexId); |
|---|
| 130 | |
|---|
| 131 | /*---------------------- |
|---|
| 132 | * Semaphores |
|---|
| 133 | *---------------------*/ |
|---|
| 134 | CORE_SEM_ID DstCore_SemCreate (DS_U32 SemName, DS_U32 InitCount); |
|---|
| 135 | DS_U32 DstCore_SemLock (CORE_SEM_ID SemId, DS_U32 Timeout); |
|---|
| 136 | DS_U32 DstCore_SemUnlock (CORE_SEM_ID SemId); |
|---|
| 137 | DS_U32 DstCore_SemDelete (CORE_SEM_ID SemId); |
|---|
| 138 | |
|---|
| 139 | /*---------------------- |
|---|
| 140 | * Events |
|---|
| 141 | *---------------------*/ |
|---|
| 142 | CORE_EVENT_ID DstCore_EventCreate (DS_U32 EventName, DS_BOOL Signaled); |
|---|
| 143 | DS_U32 DstCore_EventSet (CORE_EVENT_ID EventId); |
|---|
| 144 | DS_U32 DstCore_EventReset (CORE_EVENT_ID EventId); |
|---|
| 145 | DS_U32 DstCore_EventWait (CORE_EVENT_ID EventId, DS_BOOL AutoReset, |
|---|
| 146 | DS_U32 Timeout); |
|---|
| 147 | DS_U32 DstCore_EventDelete (CORE_EVENT_ID EventId); |
|---|
| 148 | |
|---|
| 149 | /*---------------------- |
|---|
| 150 | * Multiple events |
|---|
| 151 | *---------------------*/ |
|---|
| 152 | CORE_EVENT_ID DstCore_EvGroupCreate (DS_BOOL Signaled, DS_U32 SubEvents); |
|---|
| 153 | DS_U32 DstCore_EvGroupSet (CORE_EVENT_ID EventId, DS_U32 Mask); |
|---|
| 154 | DS_U32 DstCore_EvGroupReset (CORE_EVENT_ID EventId, DS_U32 Mask); |
|---|
| 155 | DS_U32 DstCore_EvGroupWait (CORE_EVENT_ID EventId, DS_U32 *EventsPtr, |
|---|
| 156 | DS_BOOL AutoReset, DS_U32 Timeout); |
|---|
| 157 | DS_U32 DstCore_EvGroupDelete (CORE_EVENT_ID EventId); |
|---|
| 158 | |
|---|
| 159 | /*---------------------- |
|---|
| 160 | * Queues |
|---|
| 161 | *---------------------*/ |
|---|
| 162 | CORE_QUEUE_ID DstCore_QueueCreate (DS_U32 QueueName, DS_U32 MaxMsgCount, |
|---|
| 163 | DS_U32 MsgLen); |
|---|
| 164 | DS_U32 DstCore_QueuePost (CORE_QUEUE_ID QueueId, DS_U32 *Message |
|---|
| 165 | //yzyeo |
|---|
| 166 | #ifdef MSGQ_SIZE |
|---|
| 167 | , DS_U32 msg_size |
|---|
| 168 | #endif |
|---|
| 169 | ); |
|---|
| 170 | DS_U32 DstCore_QueueWait (CORE_QUEUE_ID QueueId, DS_U32 *Msg, |
|---|
| 171 | DS_U32 Timeout |
|---|
| 172 | //yzyeo |
|---|
| 173 | #ifdef MSGQ_SIZE |
|---|
| 174 | , DS_U32 *msg_size |
|---|
| 175 | #endif |
|---|
| 176 | ); |
|---|
| 177 | DS_U32 DstCore_QueueReset (CORE_QUEUE_ID QueueId); |
|---|
| 178 | DS_U32 DstCore_QueueDelete (CORE_QUEUE_ID QueueId); |
|---|
| 179 | |
|---|
| 180 | /*---------------------- |
|---|
| 181 | * Timers and clocks |
|---|
| 182 | *---------------------*/ |
|---|
| 183 | CORE_TIMER_ID DstCore_TimerCreate (DS_U32 MsInterval, DS_U32 UserParam, |
|---|
| 184 | void (*UserFunc) (CORE_TIMER_ID TimerId, |
|---|
| 185 | DS_U32 TickCount, DS_U32 UsrParam)); |
|---|
| 186 | DS_U32 DstCore_TimerDelete (CORE_TIMER_ID TimerId); |
|---|
| 187 | |
|---|
| 188 | DS_U32 DstCore_SetTimeOfDay (DS_U32 UtcSeconds); |
|---|
| 189 | DS_U32 DstCore_GetTimeOfDay (DS_U32 *UtcSeconds); |
|---|
| 190 | DS_U32 DstCore_Get100HzClockTick (void); |
|---|
| 191 | DS_U32 DstCore_GetSysClockTick (void); |
|---|
| 192 | DS_U32 DstCore_GetSysClockFreq (void); |
|---|
| 193 | DS_U32 DstCore_Delay (DS_U32 Delay); |
|---|
| 194 | DS_U32 DstCore_UsDelay (DS_U32 Delay); |
|---|
| 195 | |
|---|
| 196 | /*---------------------- |
|---|
| 197 | * Memory management |
|---|
| 198 | *---------------------*/ |
|---|
| 199 | void *DstCore_MemAlloc (DS_U32 ByteSize); |
|---|
| 200 | DS_U32 DstCore_MemFree (void *VirtualAddr); |
|---|
| 201 | void *DstCore_MemSharedAlloc (DS_S8 *BufferName, DS_U32 ByteSize, |
|---|
| 202 | DS_BOOL *Exist); |
|---|
| 203 | DS_U32 DstCore_MemSharedFree (DS_S8 *BufferName, void *VirtualAddr); |
|---|
| 204 | |
|---|
| 205 | DS_U32 DstCore_RegWrite (DS_U32 Address, DS_U32 Value, int Size); |
|---|
| 206 | DS_U32 DstCore_RegRead (DS_U32 Address, int Size); |
|---|
| 207 | DS_U32 DstCore_GetLoaderVer(void); |
|---|
| 208 | |
|---|
| 209 | #ifdef __cplusplus |
|---|
| 210 | } |
|---|
| 211 | #endif |
|---|
| 212 | |
|---|
| 213 | #endif /* OS_H_ */ |
|---|