CoOS Demonstrator adapted to mbed Hardware.

Dependencies:   mbed

Committer:
ericebert
Date:
Fri Dec 03 19:45:30 2010 +0000
Revision:
0:57690853989a
Some basic LED-Flashing works in the CoOS-RTOS using Tasks

Who changed what in which revision?

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