Quick and dirty CoOS + LWIP ( Webserver )

Dependencies:   mbed lwip

Committer:
astroboy
Date:
Sat Sep 10 22:41:10 2011 +0000
Revision:
0:94897d537b31

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
astroboy 0:94897d537b31 1 /**
astroboy 0:94897d537b31 2 *******************************************************************************
astroboy 0:94897d537b31 3 * @file core.c
astroboy 0:94897d537b31 4 * @version V1.1.4
astroboy 0:94897d537b31 5 * @date 2011.04.20
astroboy 0:94897d537b31 6 * @brief Core implementation code of CooCox CoOS kernel.
astroboy 0:94897d537b31 7 *******************************************************************************
astroboy 0:94897d537b31 8 * @copy
astroboy 0:94897d537b31 9 *
astroboy 0:94897d537b31 10 * INTERNAL FILE,DON'T PUBLIC.
astroboy 0:94897d537b31 11 *
astroboy 0:94897d537b31 12 * <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2>
astroboy 0:94897d537b31 13 *******************************************************************************
astroboy 0:94897d537b31 14 */
astroboy 0:94897d537b31 15
astroboy 0:94897d537b31 16 /*---------------------------- Include ---------------------------------------*/
astroboy 0:94897d537b31 17 #include <coocox.h>
astroboy 0:94897d537b31 18
astroboy 0:94897d537b31 19 /*---------------------------- Variable Define -------------------------------*/
astroboy 0:94897d537b31 20 volatile U8 OSIntNesting = 0; /*!< Use to indicate interrupt nesting level*/
astroboy 0:94897d537b31 21 volatile U8 OSSchedLock = 0; /*!< Task Switch lock. */
astroboy 0:94897d537b31 22 volatile BOOL TaskSchedReq = Co_FALSE;
astroboy 0:94897d537b31 23
astroboy 0:94897d537b31 24
astroboy 0:94897d537b31 25 /**
astroboy 0:94897d537b31 26 *******************************************************************************
astroboy 0:94897d537b31 27 * @brief Enter a ISR.
astroboy 0:94897d537b31 28 * @param[in] None
astroboy 0:94897d537b31 29 * @param[out] None
astroboy 0:94897d537b31 30 * @retval None
astroboy 0:94897d537b31 31 *
astroboy 0:94897d537b31 32 * @par Description
astroboy 0:94897d537b31 33 * @details This function is called to notify OS when enter to an ISR.
astroboy 0:94897d537b31 34 *
astroboy 0:94897d537b31 35 * @note When you call API in ISR,you must call CoEnterISR() before your
astroboy 0:94897d537b31 36 * interrupt handler code,and call CoExitISR() after your handler
astroboy 0:94897d537b31 37 * code and before exiting from ISR.
astroboy 0:94897d537b31 38 *******************************************************************************
astroboy 0:94897d537b31 39 */
astroboy 0:94897d537b31 40 void CoEnterISR(void)
astroboy 0:94897d537b31 41 {
astroboy 0:94897d537b31 42 Inc8(&OSIntNesting); /* OSIntNesting increment */
astroboy 0:94897d537b31 43 }
astroboy 0:94897d537b31 44
astroboy 0:94897d537b31 45
astroboy 0:94897d537b31 46 /**
astroboy 0:94897d537b31 47 *******************************************************************************
astroboy 0:94897d537b31 48 * @brief Exit a ISR.
astroboy 0:94897d537b31 49 * @param[in] None
astroboy 0:94897d537b31 50 * @param[out] None
astroboy 0:94897d537b31 51 * @retval None
astroboy 0:94897d537b31 52 *
astroboy 0:94897d537b31 53 * @par Description
astroboy 0:94897d537b31 54 * @details This function is called when exit from a ISR.
astroboy 0:94897d537b31 55 *
astroboy 0:94897d537b31 56 * @note
astroboy 0:94897d537b31 57 *******************************************************************************
astroboy 0:94897d537b31 58 */
astroboy 0:94897d537b31 59 void CoExitISR(void)
astroboy 0:94897d537b31 60 {
astroboy 0:94897d537b31 61 Dec8(&OSIntNesting); /* OSIntNesting decrease */
astroboy 0:94897d537b31 62 if( OSIntNesting == 0) /* Is OSIntNesting == 0? */
astroboy 0:94897d537b31 63 {
astroboy 0:94897d537b31 64 if(TaskSchedReq == Co_TRUE)
astroboy 0:94897d537b31 65 {
astroboy 0:94897d537b31 66 OSSchedLock++;
astroboy 0:94897d537b31 67 Schedule(); /* Call task schedule */
astroboy 0:94897d537b31 68 OSSchedLock--;
astroboy 0:94897d537b31 69 }
astroboy 0:94897d537b31 70 }
astroboy 0:94897d537b31 71 }
astroboy 0:94897d537b31 72
astroboy 0:94897d537b31 73
astroboy 0:94897d537b31 74
astroboy 0:94897d537b31 75 /**
astroboy 0:94897d537b31 76 *******************************************************************************
astroboy 0:94897d537b31 77 * @brief Unlock schedule
astroboy 0:94897d537b31 78 * @param[in] None
astroboy 0:94897d537b31 79 * @param[out] None
astroboy 0:94897d537b31 80 * @retval None
astroboy 0:94897d537b31 81 *
astroboy 0:94897d537b31 82 * @par Description
astroboy 0:94897d537b31 83 * @details This function is called to unlock schedule(i.e.enable schedule again)
astroboy 0:94897d537b31 84 *
astroboy 0:94897d537b31 85 * @note
astroboy 0:94897d537b31 86 *******************************************************************************
astroboy 0:94897d537b31 87 */
astroboy 0:94897d537b31 88 void OsSchedUnlock(void)
astroboy 0:94897d537b31 89 {
astroboy 0:94897d537b31 90 if(OSSchedLock == 1) /* Is OSSchedLock == 0? */
astroboy 0:94897d537b31 91 {
astroboy 0:94897d537b31 92 #if CFG_TASK_WAITTING_EN > 0
astroboy 0:94897d537b31 93 if(IsrReq == Co_TRUE)
astroboy 0:94897d537b31 94 {
astroboy 0:94897d537b31 95 RespondSRQ(); /* Respond service request */
astroboy 0:94897d537b31 96 }
astroboy 0:94897d537b31 97 #endif
astroboy 0:94897d537b31 98 /* Judge task state change or higher PRI task coming in */
astroboy 0:94897d537b31 99 if(TaskSchedReq == Co_TRUE)
astroboy 0:94897d537b31 100 {
astroboy 0:94897d537b31 101 Schedule(); /* Call task schedule */
astroboy 0:94897d537b31 102 }
astroboy 0:94897d537b31 103 OSSchedLock = 0;
astroboy 0:94897d537b31 104 }
astroboy 0:94897d537b31 105 else
astroboy 0:94897d537b31 106 {
astroboy 0:94897d537b31 107 OSSchedLock--;
astroboy 0:94897d537b31 108 }
astroboy 0:94897d537b31 109 }
astroboy 0:94897d537b31 110
astroboy 0:94897d537b31 111
astroboy 0:94897d537b31 112 /**
astroboy 0:94897d537b31 113 *******************************************************************************
astroboy 0:94897d537b31 114 * @brief Lock schedule
astroboy 0:94897d537b31 115 * @param[in] None
astroboy 0:94897d537b31 116 * @param[out] None
astroboy 0:94897d537b31 117 * @retval None
astroboy 0:94897d537b31 118 *
astroboy 0:94897d537b31 119 * @par Description
astroboy 0:94897d537b31 120 * @details This function is called in application code to lock schedule.
astroboy 0:94897d537b31 121 *
astroboy 0:94897d537b31 122 * @note
astroboy 0:94897d537b31 123 *******************************************************************************
astroboy 0:94897d537b31 124 */
astroboy 0:94897d537b31 125 void CoSchedLock(void)
astroboy 0:94897d537b31 126 {
astroboy 0:94897d537b31 127 OsSchedLock(); /* Lock schedule */
astroboy 0:94897d537b31 128 }
astroboy 0:94897d537b31 129
astroboy 0:94897d537b31 130
astroboy 0:94897d537b31 131 /**
astroboy 0:94897d537b31 132 *******************************************************************************
astroboy 0:94897d537b31 133 * @brief Unlock schedule
astroboy 0:94897d537b31 134 * @param[in] None
astroboy 0:94897d537b31 135 * @param[out] None
astroboy 0:94897d537b31 136 * @retval None
astroboy 0:94897d537b31 137 *
astroboy 0:94897d537b31 138 * @par Description
astroboy 0:94897d537b31 139 * @details This function is called in APP to unlock schedule.
astroboy 0:94897d537b31 140 *
astroboy 0:94897d537b31 141 * @note
astroboy 0:94897d537b31 142 *******************************************************************************
astroboy 0:94897d537b31 143 */
astroboy 0:94897d537b31 144 void CoSchedUnlock(void)
astroboy 0:94897d537b31 145 {
astroboy 0:94897d537b31 146 OsSchedUnlock(); /* Unlock schedule */
astroboy 0:94897d537b31 147 }
astroboy 0:94897d537b31 148
astroboy 0:94897d537b31 149
astroboy 0:94897d537b31 150 /**
astroboy 0:94897d537b31 151 *******************************************************************************
astroboy 0:94897d537b31 152 * @brief Initialize OS
astroboy 0:94897d537b31 153 * @param[in] None
astroboy 0:94897d537b31 154 * @param[out] None
astroboy 0:94897d537b31 155 * @retval None
astroboy 0:94897d537b31 156 *
astroboy 0:94897d537b31 157 * @par Description
astroboy 0:94897d537b31 158 * @details This function is called to initialize OS.
astroboy 0:94897d537b31 159 *
astroboy 0:94897d537b31 160 * @note You must call this function first,before any other OS API function
astroboy 0:94897d537b31 161 *
astroboy 0:94897d537b31 162 * @code There is a example for useage of this function,as follows:
astroboy 0:94897d537b31 163 * e.g.
astroboy 0:94897d537b31 164 * ... // Your target initial code.
astroboy 0:94897d537b31 165 *
astroboy 0:94897d537b31 166 * OsInit(); // Initial OS.
astroboy 0:94897d537b31 167 * CreateTask(...); // Create tasks.
astroboy 0:94897d537b31 168 * ...
astroboy 0:94897d537b31 169 * OsStart(); // Start multitask.
astroboy 0:94897d537b31 170 * @endcode
astroboy 0:94897d537b31 171 *******************************************************************************
astroboy 0:94897d537b31 172 */
astroboy 0:94897d537b31 173 void CoInitOS(void)
astroboy 0:94897d537b31 174 {
astroboy 0:94897d537b31 175 InitSysTick(); /* Initialize system tick. */
astroboy 0:94897d537b31 176 InitInt(); /* Initialize PendSV,SVC,SysTick interrupt */
astroboy 0:94897d537b31 177 CreateTCBList(); /* Create TCB list. */
astroboy 0:94897d537b31 178 #if CFG_EVENT_EN > 0
astroboy 0:94897d537b31 179 CreateEventList(); /* Create event control list. */
astroboy 0:94897d537b31 180 #endif
astroboy 0:94897d537b31 181 #if CFG_KHEAP_EN > 0
astroboy 0:94897d537b31 182 CoCreateKheap(); /* Create kernel heap within user define */
astroboy 0:94897d537b31 183 #endif
astroboy 0:94897d537b31 184 OsSchedLock(); /* Lock Schedule */
astroboy 0:94897d537b31 185 /* Create first task -- IDLE task. */
astroboy 0:94897d537b31 186 CoCreateTask( CoIdleTask,
astroboy 0:94897d537b31 187 Co_NULL,
astroboy 0:94897d537b31 188 CFG_LOWEST_PRIO,
astroboy 0:94897d537b31 189 &idle_stk[CFG_IDLE_STACK_SIZE-1],
astroboy 0:94897d537b31 190 CFG_IDLE_STACK_SIZE
astroboy 0:94897d537b31 191 );
astroboy 0:94897d537b31 192 /* Set PSP for CoIdleTask coming in */
astroboy 0:94897d537b31 193 SetEnvironment(&idle_stk[CFG_IDLE_STACK_SIZE-1]);
astroboy 0:94897d537b31 194 }
astroboy 0:94897d537b31 195
astroboy 0:94897d537b31 196
astroboy 0:94897d537b31 197 /**
astroboy 0:94897d537b31 198 *******************************************************************************
astroboy 0:94897d537b31 199 * @brief Start multitask
astroboy 0:94897d537b31 200 * @param[in] None
astroboy 0:94897d537b31 201 * @param[out] None
astroboy 0:94897d537b31 202 * @retval None
astroboy 0:94897d537b31 203 *
astroboy 0:94897d537b31 204 * @par Description
astroboy 0:94897d537b31 205 * @details This function is called to start multitask.After it is called,
astroboy 0:94897d537b31 206 * OS start schedule task by priority or/and time slice.
astroboy 0:94897d537b31 207 * @note This function must be called to start OS when you use CoOS,and must
astroboy 0:94897d537b31 208 * call after CoOsInit().
astroboy 0:94897d537b31 209 *******************************************************************************
astroboy 0:94897d537b31 210 */
astroboy 0:94897d537b31 211 void CoStartOS(void)
astroboy 0:94897d537b31 212 {
astroboy 0:94897d537b31 213 TCBRunning = &TCBTbl[0]; /* Get running task */
astroboy 0:94897d537b31 214 TCBNext = TCBRunning; /* Set next scheduled task as running task */
astroboy 0:94897d537b31 215 TCBRunning->state = TASK_RUNNING; /* Set running task status to RUNNING */
astroboy 0:94897d537b31 216 RemoveFromTCBRdyList(TCBRunning); /* Remove running task from READY list */
astroboy 0:94897d537b31 217 OsSchedUnlock(); /* Enable Schedule,call task schedule */
astroboy 0:94897d537b31 218 }
astroboy 0:94897d537b31 219
astroboy 0:94897d537b31 220
astroboy 0:94897d537b31 221 /**
astroboy 0:94897d537b31 222 *******************************************************************************
astroboy 0:94897d537b31 223 * @brief Get OS version
astroboy 0:94897d537b31 224 * @param[in] None
astroboy 0:94897d537b31 225 * @param[out] None
astroboy 0:94897d537b31 226 * @retval The value is version of OS mutipled by 100.
astroboy 0:94897d537b31 227 *
astroboy 0:94897d537b31 228 * @par Description
astroboy 0:94897d537b31 229 * @details This function is used to return the version number of CooCox OS.
astroboy 0:94897d537b31 230 * the return value corresponds to CooCox's version number multiplied
astroboy 0:94897d537b31 231 * by 100. In other words, version 1.02 would be returned as 102.
astroboy 0:94897d537b31 232 *******************************************************************************
astroboy 0:94897d537b31 233 */
astroboy 0:94897d537b31 234 OS_VER CoGetOSVersion(void)
astroboy 0:94897d537b31 235 {
astroboy 0:94897d537b31 236 return OS_VERSION; /* Get CooCox CoOS version */
astroboy 0:94897d537b31 237 }
astroboy 0:94897d537b31 238