astroboy astroboy
/
CoOS_LWIP
Quick and dirty CoOS + LWIP ( Webserver )
CoOS/kernel/CoOS.h@0:94897d537b31, 2011-09-10 (annotated)
- Committer:
- astroboy
- Date:
- Sat Sep 10 22:41:10 2011 +0000
- Revision:
- 0:94897d537b31
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
astroboy | 0:94897d537b31 | 1 | /** |
astroboy | 0:94897d537b31 | 2 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 3 | * @file CoOS.h |
astroboy | 0:94897d537b31 | 4 | * @version V1.1.4 |
astroboy | 0:94897d537b31 | 5 | * @date 2011.04.20 |
astroboy | 0:94897d537b31 | 6 | * @brief API header file of CooCox CoOS. |
astroboy | 0:94897d537b31 | 7 | * @details This file including all API functions's declare of CooCox CoOS. |
astroboy | 0:94897d537b31 | 8 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 9 | * @copy |
astroboy | 0:94897d537b31 | 10 | * |
astroboy | 0:94897d537b31 | 11 | * INTERNAL FILE,DON'T PUBLIC. |
astroboy | 0:94897d537b31 | 12 | * |
astroboy | 0:94897d537b31 | 13 | * <h2><center>© COPYRIGHT 2009 CooCox </center></h2> |
astroboy | 0:94897d537b31 | 14 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 15 | */ |
astroboy | 0:94897d537b31 | 16 | |
astroboy | 0:94897d537b31 | 17 | #ifndef _CCRTOS_H |
astroboy | 0:94897d537b31 | 18 | #define _CCRTOS_H |
astroboy | 0:94897d537b31 | 19 | #include "OsConfig.h" |
astroboy | 0:94897d537b31 | 20 | /*---------------------------- Type Define ----------------------------------*/ |
astroboy | 0:94897d537b31 | 21 | typedef signed char S8; |
astroboy | 0:94897d537b31 | 22 | typedef unsigned char U8; |
astroboy | 0:94897d537b31 | 23 | typedef short S16; |
astroboy | 0:94897d537b31 | 24 | typedef unsigned short U16; |
astroboy | 0:94897d537b31 | 25 | typedef int S32; |
astroboy | 0:94897d537b31 | 26 | typedef unsigned int U32; |
astroboy | 0:94897d537b31 | 27 | typedef long long S64; |
astroboy | 0:94897d537b31 | 28 | typedef unsigned long long U64; |
astroboy | 0:94897d537b31 | 29 | typedef unsigned char BIT; |
astroboy | 0:94897d537b31 | 30 | typedef unsigned char BOOL; |
astroboy | 0:94897d537b31 | 31 | typedef unsigned int OS_STK; |
astroboy | 0:94897d537b31 | 32 | typedef U8 OS_TID; |
astroboy | 0:94897d537b31 | 33 | typedef U8 OS_TCID; |
astroboy | 0:94897d537b31 | 34 | typedef U8 OS_MutexID; |
astroboy | 0:94897d537b31 | 35 | typedef U8 OS_EventID; |
astroboy | 0:94897d537b31 | 36 | typedef U8 OS_FlagID; |
astroboy | 0:94897d537b31 | 37 | typedef U8 OS_MMID; |
astroboy | 0:94897d537b31 | 38 | typedef U8 StatusType; |
astroboy | 0:94897d537b31 | 39 | typedef U16 OS_VER; |
astroboy | 0:94897d537b31 | 40 | typedef void (*FUNCPtr)(void*); |
astroboy | 0:94897d537b31 | 41 | typedef void (*vFUNCPtr)(void); |
astroboy | 0:94897d537b31 | 42 | |
astroboy | 0:94897d537b31 | 43 | |
astroboy | 0:94897d537b31 | 44 | /*---------------------------- Constant Define -------------------------------*/ |
astroboy | 0:94897d537b31 | 45 | #ifndef Co_NULL |
astroboy | 0:94897d537b31 | 46 | #define Co_NULL ((void *)0) |
astroboy | 0:94897d537b31 | 47 | #endif |
astroboy | 0:94897d537b31 | 48 | |
astroboy | 0:94897d537b31 | 49 | #ifndef Co_FALSE |
astroboy | 0:94897d537b31 | 50 | #define Co_FALSE (0) |
astroboy | 0:94897d537b31 | 51 | #endif |
astroboy | 0:94897d537b31 | 52 | |
astroboy | 0:94897d537b31 | 53 | #ifndef Co_TRUE |
astroboy | 0:94897d537b31 | 54 | #define Co_TRUE (1) |
astroboy | 0:94897d537b31 | 55 | #endif |
astroboy | 0:94897d537b31 | 56 | |
astroboy | 0:94897d537b31 | 57 | |
astroboy | 0:94897d537b31 | 58 | /*---------------------------- Error Codes ---------------------------------*/ |
astroboy | 0:94897d537b31 | 59 | #define E_CREATE_FAIL (StatusType)-1 |
astroboy | 0:94897d537b31 | 60 | #define E_OK (StatusType)0 |
astroboy | 0:94897d537b31 | 61 | #define E_INVALID_ID (StatusType)1 |
astroboy | 0:94897d537b31 | 62 | #define E_INVALID_PARAMETER (StatusType)2 |
astroboy | 0:94897d537b31 | 63 | #define E_CALL (StatusType)3 |
astroboy | 0:94897d537b31 | 64 | #define E_TASK_WAITING (StatusType)4 |
astroboy | 0:94897d537b31 | 65 | #define E_TIMEOUT (StatusType)5 |
astroboy | 0:94897d537b31 | 66 | #define E_SEM_FULL (StatusType)6 |
astroboy | 0:94897d537b31 | 67 | #define E_MBOX_FULL (StatusType)7 |
astroboy | 0:94897d537b31 | 68 | #define E_QUEUE_FULL (StatusType)8 |
astroboy | 0:94897d537b31 | 69 | #define E_SEM_EMPTY (StatusType)9 |
astroboy | 0:94897d537b31 | 70 | #define E_MBOX_EMPTY (StatusType)10 |
astroboy | 0:94897d537b31 | 71 | #define E_QUEUE_EMPTY (StatusType)11 |
astroboy | 0:94897d537b31 | 72 | #define E_FLAG_NOT_READY (StatusType)12 |
astroboy | 0:94897d537b31 | 73 | #define E_ALREADY_IN_WAITING (StatusType)13 |
astroboy | 0:94897d537b31 | 74 | #define E_TASK_NOT_WAITING (StatusType)14 |
astroboy | 0:94897d537b31 | 75 | #define E_TASK_WAIT_OTHER (StatusType)15 |
astroboy | 0:94897d537b31 | 76 | #define E_EXCEED_MAX_NUM (StatusType)16 |
astroboy | 0:94897d537b31 | 77 | #define E_NOT_IN_DELAY_LIST (StatusType)17 |
astroboy | 0:94897d537b31 | 78 | #define E_SEV_REQ_FULL (StatusType)18 |
astroboy | 0:94897d537b31 | 79 | #define E_NOT_FREE_ALL (StatusType)19 |
astroboy | 0:94897d537b31 | 80 | #define E_PROTECTED_TASK (StatusType)20 |
astroboy | 0:94897d537b31 | 81 | #define E_OS_IN_LOCK (StatusType)21 |
astroboy | 0:94897d537b31 | 82 | |
astroboy | 0:94897d537b31 | 83 | |
astroboy | 0:94897d537b31 | 84 | /*---------------------------- Wait Opreation type --------------------------*/ |
astroboy | 0:94897d537b31 | 85 | #define OPT_WAIT_ALL 0 /*!< Wait for all flags. */ |
astroboy | 0:94897d537b31 | 86 | #define OPT_WAIT_ANY 1 /*!< Wait for any one of flags. */ |
astroboy | 0:94897d537b31 | 87 | #define OPT_WAIT_ONE 2 /*!< Waot for one flag. */ |
astroboy | 0:94897d537b31 | 88 | |
astroboy | 0:94897d537b31 | 89 | |
astroboy | 0:94897d537b31 | 90 | /*---------------------------- Delete Opreation type ------------------------*/ |
astroboy | 0:94897d537b31 | 91 | #define OPT_DEL_NO_PEND 0 /*!< Delete when no task waitting for */ |
astroboy | 0:94897d537b31 | 92 | #define OPT_DEL_ANYWAY 1 /*!< Delete always. */ |
astroboy | 0:94897d537b31 | 93 | |
astroboy | 0:94897d537b31 | 94 | |
astroboy | 0:94897d537b31 | 95 | /*---------------------------- Timer Types ----------------------------------*/ |
astroboy | 0:94897d537b31 | 96 | #if CFG_TMR_EN >0 |
astroboy | 0:94897d537b31 | 97 | #define TMR_TYPE_ONE_SHOT 0 /*!< Timer counter type: One-shot */ |
astroboy | 0:94897d537b31 | 98 | #define TMR_TYPE_PERIODIC 1 /*!< Timer counter type: Periodic */ |
astroboy | 0:94897d537b31 | 99 | #endif |
astroboy | 0:94897d537b31 | 100 | |
astroboy | 0:94897d537b31 | 101 | |
astroboy | 0:94897d537b31 | 102 | /*---------------------------- Event Control ---------------------------------*/ |
astroboy | 0:94897d537b31 | 103 | #if CFG_EVENT_EN >0 |
astroboy | 0:94897d537b31 | 104 | #define EVENT_SORT_TYPE_FIFO (U8)0x01 /*!< Insert a event by FIFO */ |
astroboy | 0:94897d537b31 | 105 | #define EVENT_SORT_TYPE_PRIO (U8)0x02 /*!< Insert a event by prio */ |
astroboy | 0:94897d537b31 | 106 | #endif |
astroboy | 0:94897d537b31 | 107 | |
astroboy | 0:94897d537b31 | 108 | |
astroboy | 0:94897d537b31 | 109 | /*---------------------------- Function declare-------------------------------*/ |
astroboy | 0:94897d537b31 | 110 | |
astroboy | 0:94897d537b31 | 111 | /* Implement in file "core.c" */ |
astroboy | 0:94897d537b31 | 112 | extern void CoInitOS(void); /*!< Initialize OS */ |
astroboy | 0:94897d537b31 | 113 | extern void CoStartOS(void); /*!< Start multitask */ |
astroboy | 0:94897d537b31 | 114 | extern void CoEnterISR(void); /*!< Enter a ISR */ |
astroboy | 0:94897d537b31 | 115 | extern void CoExitISR(void); /*!< Exit a ISR */ |
astroboy | 0:94897d537b31 | 116 | extern void CoSchedLock(void); |
astroboy | 0:94897d537b31 | 117 | extern void CoSchedUnlock(void); |
astroboy | 0:94897d537b31 | 118 | extern OS_VER CoGetOSVersion(void); /*!< Get OS version value */ |
astroboy | 0:94897d537b31 | 119 | |
astroboy | 0:94897d537b31 | 120 | |
astroboy | 0:94897d537b31 | 121 | /* Implement in file "task.c" */ |
astroboy | 0:94897d537b31 | 122 | #define CoCreateTask(task,argv,prio,stk,stkSz) \ |
astroboy | 0:94897d537b31 | 123 | CreateTask(task,argv,(prio)|(((stkSz)<<8) &0x000FFF00 ),stk) |
astroboy | 0:94897d537b31 | 124 | |
astroboy | 0:94897d537b31 | 125 | |
astroboy | 0:94897d537b31 | 126 | #define CoCreateTaskEx(task,argv,prio,stk,stkSz,timeSlice,isWaitting) \ |
astroboy | 0:94897d537b31 | 127 | CreateTask(task,argv,(prio)|(((stkSz)<<8)&0x000FFF00)|(((timeSlice)<<20)&0x7FF00000)|((isWaitting<<31)&0x80000000),stk) |
astroboy | 0:94897d537b31 | 128 | |
astroboy | 0:94897d537b31 | 129 | extern void CoExitTask(void); |
astroboy | 0:94897d537b31 | 130 | extern OS_TID CoGetCurTaskID(void); |
astroboy | 0:94897d537b31 | 131 | extern StatusType CoDelTask(OS_TID taskID); |
astroboy | 0:94897d537b31 | 132 | extern StatusType CoActivateTask(OS_TID taskID,void *argv); |
astroboy | 0:94897d537b31 | 133 | extern StatusType CoAwakeTask(OS_TID taskID); |
astroboy | 0:94897d537b31 | 134 | extern StatusType CoSuspendTask(OS_TID taskID); |
astroboy | 0:94897d537b31 | 135 | extern StatusType CoSetPriority(OS_TID taskID,U8 priority); |
astroboy | 0:94897d537b31 | 136 | extern OS_TID CreateTask(FUNCPtr task,void *argv,U32 parameter,OS_STK *stk); |
astroboy | 0:94897d537b31 | 137 | |
astroboy | 0:94897d537b31 | 138 | /* Implement in file "time.c" */ |
astroboy | 0:94897d537b31 | 139 | extern U64 CoGetOSTime(void); |
astroboy | 0:94897d537b31 | 140 | extern StatusType CoTickDelay(U32 ticks); |
astroboy | 0:94897d537b31 | 141 | extern StatusType CoResetTaskDelayTick(OS_TID taskID,U32 ticks); |
astroboy | 0:94897d537b31 | 142 | extern StatusType CoTimeDelay(U8 hour,U8 minute,U8 sec,U16 millsec); |
astroboy | 0:94897d537b31 | 143 | |
astroboy | 0:94897d537b31 | 144 | |
astroboy | 0:94897d537b31 | 145 | /* Implement in file "timer.c" */ |
astroboy | 0:94897d537b31 | 146 | extern StatusType CoDelTmr(OS_TCID tmrID); |
astroboy | 0:94897d537b31 | 147 | extern StatusType CoStopTmr(OS_TCID tmrID); |
astroboy | 0:94897d537b31 | 148 | extern StatusType CoStartTmr(OS_TCID tmrID); |
astroboy | 0:94897d537b31 | 149 | extern U32 CoGetCurTmrCnt(OS_TCID tmrID,StatusType* perr); |
astroboy | 0:94897d537b31 | 150 | extern StatusType CoSetTmrCnt(OS_TCID tmrID,U32 tmrCnt,U32 tmrReload); |
astroboy | 0:94897d537b31 | 151 | extern OS_TCID CoCreateTmr(U8 tmrType, U32 tmrCnt, U32 tmrReload, vFUNCPtr func); |
astroboy | 0:94897d537b31 | 152 | |
astroboy | 0:94897d537b31 | 153 | |
astroboy | 0:94897d537b31 | 154 | /* Implement in file "kernelHeap.c"*/ |
astroboy | 0:94897d537b31 | 155 | extern void* CoKmalloc(U32 size); |
astroboy | 0:94897d537b31 | 156 | extern void CoKfree(void* memBuf); |
astroboy | 0:94897d537b31 | 157 | |
astroboy | 0:94897d537b31 | 158 | |
astroboy | 0:94897d537b31 | 159 | /* Implement in file "mm.c" */ |
astroboy | 0:94897d537b31 | 160 | extern void* CoGetMemoryBuffer(OS_MMID mmID); |
astroboy | 0:94897d537b31 | 161 | extern StatusType CoDelMemoryPartition(OS_MMID mmID); |
astroboy | 0:94897d537b31 | 162 | extern StatusType CoFreeMemoryBuffer(OS_MMID mmID,void* buf); |
astroboy | 0:94897d537b31 | 163 | extern U32 CoGetFreeBlockNum(OS_MMID mmID,StatusType* perr); |
astroboy | 0:94897d537b31 | 164 | extern OS_MMID CoCreateMemPartition(U8* memBuf,U32 blockSize,U32 blockNum); |
astroboy | 0:94897d537b31 | 165 | |
astroboy | 0:94897d537b31 | 166 | /* Implement in file "mutex.c" */ |
astroboy | 0:94897d537b31 | 167 | extern OS_MutexID CoCreateMutex(void); |
astroboy | 0:94897d537b31 | 168 | extern StatusType CoEnterMutexSection(OS_MutexID mutexID); |
astroboy | 0:94897d537b31 | 169 | extern StatusType CoLeaveMutexSection(OS_MutexID mutexID); |
astroboy | 0:94897d537b31 | 170 | |
astroboy | 0:94897d537b31 | 171 | |
astroboy | 0:94897d537b31 | 172 | /* Implement in file "sem.c" */ |
astroboy | 0:94897d537b31 | 173 | extern StatusType CoPostSem(OS_EventID id); |
astroboy | 0:94897d537b31 | 174 | extern StatusType CoAcceptSem(OS_EventID id); |
astroboy | 0:94897d537b31 | 175 | extern StatusType isr_PostSem(OS_EventID id); |
astroboy | 0:94897d537b31 | 176 | extern StatusType CoDelSem(OS_EventID id,U8 opt); |
astroboy | 0:94897d537b31 | 177 | extern StatusType CoPendSem(OS_EventID id,U32 timeout); |
astroboy | 0:94897d537b31 | 178 | extern OS_EventID CoCreateSem(U16 initCnt,U16 maxCnt,U8 sortType); |
astroboy | 0:94897d537b31 | 179 | |
astroboy | 0:94897d537b31 | 180 | |
astroboy | 0:94897d537b31 | 181 | /* Implement in file "mbox.c" */ |
astroboy | 0:94897d537b31 | 182 | extern OS_EventID CoCreateMbox(U8 sortType); |
astroboy | 0:94897d537b31 | 183 | extern StatusType CoDelMbox(OS_EventID id,U8 opt); |
astroboy | 0:94897d537b31 | 184 | extern StatusType CoPostMail(OS_EventID id,void* pmail); |
astroboy | 0:94897d537b31 | 185 | extern StatusType isr_PostMail(OS_EventID id,void* pmail); |
astroboy | 0:94897d537b31 | 186 | extern void* CoAcceptMail(OS_EventID id,StatusType* perr); |
astroboy | 0:94897d537b31 | 187 | extern void* CoPendMail(OS_EventID id,U32 timeout,StatusType* perr); |
astroboy | 0:94897d537b31 | 188 | |
astroboy | 0:94897d537b31 | 189 | |
astroboy | 0:94897d537b31 | 190 | /* Implement in file "queue.c" */ |
astroboy | 0:94897d537b31 | 191 | extern StatusType CoDelQueue(OS_EventID id,U8 opt); |
astroboy | 0:94897d537b31 | 192 | extern StatusType CoPostQueueMail(OS_EventID id,void* pmail); |
astroboy | 0:94897d537b31 | 193 | extern StatusType isr_PostQueueMail(OS_EventID id,void* pmail); |
astroboy | 0:94897d537b31 | 194 | extern void* CoAcceptQueueMail(OS_EventID id,StatusType* perr); |
astroboy | 0:94897d537b31 | 195 | extern OS_EventID CoCreateQueue(void **qStart, U16 size ,U8 sortType); |
astroboy | 0:94897d537b31 | 196 | extern void* CoPendQueueMail(OS_EventID id,U32 timeout,StatusType* perr); |
astroboy | 0:94897d537b31 | 197 | |
astroboy | 0:94897d537b31 | 198 | |
astroboy | 0:94897d537b31 | 199 | |
astroboy | 0:94897d537b31 | 200 | /* Implement in file "flag.c" */ |
astroboy | 0:94897d537b31 | 201 | extern StatusType CoSetFlag (OS_FlagID id); |
astroboy | 0:94897d537b31 | 202 | extern StatusType CoClearFlag (OS_FlagID id); |
astroboy | 0:94897d537b31 | 203 | extern StatusType isr_SetFlag (OS_FlagID id); |
astroboy | 0:94897d537b31 | 204 | extern StatusType CoDelFlag (OS_FlagID id,U8 opt); |
astroboy | 0:94897d537b31 | 205 | extern StatusType CoAcceptSingleFlag (OS_FlagID id); |
astroboy | 0:94897d537b31 | 206 | extern StatusType CoWaitForSingleFlag (OS_FlagID id,U32 timeout); |
astroboy | 0:94897d537b31 | 207 | extern OS_FlagID CoCreateFlag (BOOL bAutoReset,BOOL bInitialState); |
astroboy | 0:94897d537b31 | 208 | extern U32 CoAcceptMultipleFlags (U32 flags,U8 waitType,StatusType *perr); |
astroboy | 0:94897d537b31 | 209 | extern U32 CoWaitForMultipleFlags (U32 flags,U8 waitType,U32 timeout,StatusType *perr); |
astroboy | 0:94897d537b31 | 210 | |
astroboy | 0:94897d537b31 | 211 | |
astroboy | 0:94897d537b31 | 212 | /* Implement in file "utility.c" */ |
astroboy | 0:94897d537b31 | 213 | extern StatusType CoTimeToTick(U8 hour,U8 minute,U8 sec,U16 millsec,U32* ticks); |
astroboy | 0:94897d537b31 | 214 | extern void CoTickToTime(U32 ticks,U8* hour,U8* minute,U8* sec,U16* millsec); |
astroboy | 0:94897d537b31 | 215 | |
astroboy | 0:94897d537b31 | 216 | |
astroboy | 0:94897d537b31 | 217 | /* Implement in file "hook.c" */ |
astroboy | 0:94897d537b31 | 218 | extern void CoIdleTask(void* pdata); |
astroboy | 0:94897d537b31 | 219 | extern void CoStkOverflowHook(OS_TID taskID); |
astroboy | 0:94897d537b31 | 220 | |
astroboy | 0:94897d537b31 | 221 | |
astroboy | 0:94897d537b31 | 222 | #endif |