astroboy astroboy
/
CoOS_LWIP
Quick and dirty CoOS + LWIP ( Webserver )
CoOS/kernel/time.c@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 time.c |
astroboy | 0:94897d537b31 | 4 | * @version V1.1.4 |
astroboy | 0:94897d537b31 | 5 | * @date 2011.04.20 |
astroboy | 0:94897d537b31 | 6 | * @brief time management 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>© COPYRIGHT 2009 CooCox </center></h2> |
astroboy | 0:94897d537b31 | 13 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 14 | */ |
astroboy | 0:94897d537b31 | 15 | |
astroboy | 0:94897d537b31 | 16 | |
astroboy | 0:94897d537b31 | 17 | |
astroboy | 0:94897d537b31 | 18 | /*---------------------------- Include ---------------------------------------*/ |
astroboy | 0:94897d537b31 | 19 | #include <coocox.h> |
astroboy | 0:94897d537b31 | 20 | |
astroboy | 0:94897d537b31 | 21 | #if CFG_TASK_WAITTING_EN > 0 |
astroboy | 0:94897d537b31 | 22 | |
astroboy | 0:94897d537b31 | 23 | /*---------------------------- Variable Define -------------------------------*/ |
astroboy | 0:94897d537b31 | 24 | P_OSTCB DlyList = 0; /*!< Header pointer to the DELAY list.*/ |
astroboy | 0:94897d537b31 | 25 | |
astroboy | 0:94897d537b31 | 26 | |
astroboy | 0:94897d537b31 | 27 | /** |
astroboy | 0:94897d537b31 | 28 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 29 | * @brief Insert into DELAY list |
astroboy | 0:94897d537b31 | 30 | * |
astroboy | 0:94897d537b31 | 31 | * @param[in] ptcb Task that want to insert into DELAY list. |
astroboy | 0:94897d537b31 | 32 | * @param[in] ticks Delay system ticks. |
astroboy | 0:94897d537b31 | 33 | * @param[out] None |
astroboy | 0:94897d537b31 | 34 | * @retval None. |
astroboy | 0:94897d537b31 | 35 | * |
astroboy | 0:94897d537b31 | 36 | * @par Description |
astroboy | 0:94897d537b31 | 37 | * @details This function is called to insert task into DELAY list. |
astroboy | 0:94897d537b31 | 38 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 39 | */ |
astroboy | 0:94897d537b31 | 40 | void InsertDelayList(P_OSTCB ptcb,U32 ticks) |
astroboy | 0:94897d537b31 | 41 | { |
astroboy | 0:94897d537b31 | 42 | S32 deltaTicks; |
astroboy | 0:94897d537b31 | 43 | P_OSTCB dlyNext; |
astroboy | 0:94897d537b31 | 44 | |
astroboy | 0:94897d537b31 | 45 | if(ticks == 0) /* Is delay tick == 0? */ |
astroboy | 0:94897d537b31 | 46 | return; /* Yes,do nothing,return */ |
astroboy | 0:94897d537b31 | 47 | if(DlyList == 0) /* Is no item in DELAY list? */ |
astroboy | 0:94897d537b31 | 48 | { |
astroboy | 0:94897d537b31 | 49 | ptcb->delayTick = ticks; /* Yes,set this as first item */ |
astroboy | 0:94897d537b31 | 50 | DlyList = ptcb; |
astroboy | 0:94897d537b31 | 51 | } |
astroboy | 0:94897d537b31 | 52 | else |
astroboy | 0:94897d537b31 | 53 | { |
astroboy | 0:94897d537b31 | 54 | /* No,find correct place ,and insert the task */ |
astroboy | 0:94897d537b31 | 55 | dlyNext = DlyList; |
astroboy | 0:94897d537b31 | 56 | deltaTicks = ticks; /* Get task delay ticks */ |
astroboy | 0:94897d537b31 | 57 | |
astroboy | 0:94897d537b31 | 58 | /* Find correct place */ |
astroboy | 0:94897d537b31 | 59 | while(dlyNext != 0) |
astroboy | 0:94897d537b31 | 60 | { |
astroboy | 0:94897d537b31 | 61 | /* Get delta ticks with previous item */ |
astroboy | 0:94897d537b31 | 62 | deltaTicks -= dlyNext->delayTick; |
astroboy | 0:94897d537b31 | 63 | if(deltaTicks < 0) /* Is delta ticks<0? */ |
astroboy | 0:94897d537b31 | 64 | { |
astroboy | 0:94897d537b31 | 65 | /* Yes,get correct place */ |
astroboy | 0:94897d537b31 | 66 | if(dlyNext->TCBprev != 0) /* Is head item of DELAY list? */ |
astroboy | 0:94897d537b31 | 67 | { |
astroboy | 0:94897d537b31 | 68 | dlyNext->TCBprev->TCBnext = ptcb; /* No,insert into */ |
astroboy | 0:94897d537b31 | 69 | ptcb->TCBprev = dlyNext->TCBprev; |
astroboy | 0:94897d537b31 | 70 | ptcb->TCBnext = dlyNext; |
astroboy | 0:94897d537b31 | 71 | dlyNext->TCBprev = ptcb; |
astroboy | 0:94897d537b31 | 72 | } |
astroboy | 0:94897d537b31 | 73 | else /* Yes,set task as first item */ |
astroboy | 0:94897d537b31 | 74 | { |
astroboy | 0:94897d537b31 | 75 | ptcb->TCBnext = DlyList; |
astroboy | 0:94897d537b31 | 76 | DlyList->TCBprev = ptcb; |
astroboy | 0:94897d537b31 | 77 | DlyList = ptcb; |
astroboy | 0:94897d537b31 | 78 | } |
astroboy | 0:94897d537b31 | 79 | ptcb->delayTick = ptcb->TCBnext->delayTick+deltaTicks; |
astroboy | 0:94897d537b31 | 80 | ptcb->TCBnext->delayTick -= ptcb->delayTick; |
astroboy | 0:94897d537b31 | 81 | break; |
astroboy | 0:94897d537b31 | 82 | } |
astroboy | 0:94897d537b31 | 83 | /* Is last item in DELAY list? */ |
astroboy | 0:94897d537b31 | 84 | else if((deltaTicks >= 0) && (dlyNext->TCBnext == 0) ) |
astroboy | 0:94897d537b31 | 85 | { |
astroboy | 0:94897d537b31 | 86 | ptcb->TCBprev = dlyNext; /* Yes,insert into */ |
astroboy | 0:94897d537b31 | 87 | dlyNext->TCBnext = ptcb; |
astroboy | 0:94897d537b31 | 88 | ptcb->delayTick = deltaTicks; |
astroboy | 0:94897d537b31 | 89 | break; |
astroboy | 0:94897d537b31 | 90 | } |
astroboy | 0:94897d537b31 | 91 | dlyNext = dlyNext->TCBnext; /* Get the next item in DELAY list */ |
astroboy | 0:94897d537b31 | 92 | } |
astroboy | 0:94897d537b31 | 93 | } |
astroboy | 0:94897d537b31 | 94 | |
astroboy | 0:94897d537b31 | 95 | ptcb->state = TASK_WAITING; /* Set task status as TASK_WAITING */ |
astroboy | 0:94897d537b31 | 96 | TaskSchedReq = Co_TRUE; |
astroboy | 0:94897d537b31 | 97 | } |
astroboy | 0:94897d537b31 | 98 | |
astroboy | 0:94897d537b31 | 99 | |
astroboy | 0:94897d537b31 | 100 | /** |
astroboy | 0:94897d537b31 | 101 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 102 | * @brief Remove from the DELAY list |
astroboy | 0:94897d537b31 | 103 | * @param[in] ptcb Task that want to remove from the DELAY list. |
astroboy | 0:94897d537b31 | 104 | * @param[out] None |
astroboy | 0:94897d537b31 | 105 | * @retval None |
astroboy | 0:94897d537b31 | 106 | * |
astroboy | 0:94897d537b31 | 107 | * @par Description |
astroboy | 0:94897d537b31 | 108 | * @details This function is called to remove task from the DELAY list. |
astroboy | 0:94897d537b31 | 109 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 110 | */ |
astroboy | 0:94897d537b31 | 111 | void RemoveDelayList(P_OSTCB ptcb) |
astroboy | 0:94897d537b31 | 112 | { |
astroboy | 0:94897d537b31 | 113 | |
astroboy | 0:94897d537b31 | 114 | /* Is there only one item in the DELAY list? */ |
astroboy | 0:94897d537b31 | 115 | if((ptcb->TCBprev == 0) && ( ptcb->TCBnext == 0)) |
astroboy | 0:94897d537b31 | 116 | { |
astroboy | 0:94897d537b31 | 117 | DlyList = 0; /* Yes,set DELAY list as Co_NULL */ |
astroboy | 0:94897d537b31 | 118 | } |
astroboy | 0:94897d537b31 | 119 | else if(ptcb->TCBprev == 0) /* Is the first item in DELAY list? */ |
astroboy | 0:94897d537b31 | 120 | { |
astroboy | 0:94897d537b31 | 121 | /* Yes,remove task from the DELAY list,and reset the list */ |
astroboy | 0:94897d537b31 | 122 | DlyList = ptcb->TCBnext; |
astroboy | 0:94897d537b31 | 123 | ptcb->TCBnext->delayTick += ptcb->delayTick; |
astroboy | 0:94897d537b31 | 124 | ptcb->TCBnext->TCBprev = 0; |
astroboy | 0:94897d537b31 | 125 | ptcb->TCBnext = 0; |
astroboy | 0:94897d537b31 | 126 | |
astroboy | 0:94897d537b31 | 127 | } |
astroboy | 0:94897d537b31 | 128 | else if(ptcb->TCBnext == 0) /* Is the last item in DELAY list? */ |
astroboy | 0:94897d537b31 | 129 | { |
astroboy | 0:94897d537b31 | 130 | ptcb->TCBprev->TCBnext = 0; /* Yes,remove task form DELAY list */ |
astroboy | 0:94897d537b31 | 131 | ptcb->TCBprev = 0; |
astroboy | 0:94897d537b31 | 132 | } |
astroboy | 0:94897d537b31 | 133 | else /* No, remove task from DELAY list */ |
astroboy | 0:94897d537b31 | 134 | { |
astroboy | 0:94897d537b31 | 135 | ptcb->TCBprev->TCBnext = ptcb->TCBnext; |
astroboy | 0:94897d537b31 | 136 | ptcb->TCBnext->TCBprev = ptcb->TCBprev; |
astroboy | 0:94897d537b31 | 137 | ptcb->TCBnext->delayTick += ptcb->delayTick; |
astroboy | 0:94897d537b31 | 138 | ptcb->TCBnext = 0; |
astroboy | 0:94897d537b31 | 139 | ptcb->TCBprev = 0; |
astroboy | 0:94897d537b31 | 140 | } |
astroboy | 0:94897d537b31 | 141 | ptcb->delayTick = INVALID_VALUE; /* Set task delay tick value as invalid */ |
astroboy | 0:94897d537b31 | 142 | } |
astroboy | 0:94897d537b31 | 143 | |
astroboy | 0:94897d537b31 | 144 | /** |
astroboy | 0:94897d537b31 | 145 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 146 | * @brief Get current ticks |
astroboy | 0:94897d537b31 | 147 | * @param[in] None |
astroboy | 0:94897d537b31 | 148 | * @param[out] None |
astroboy | 0:94897d537b31 | 149 | * @retval Return current system tick counter. |
astroboy | 0:94897d537b31 | 150 | * |
astroboy | 0:94897d537b31 | 151 | * @par Description |
astroboy | 0:94897d537b31 | 152 | * @details This function is called to obtain current system tick counter. |
astroboy | 0:94897d537b31 | 153 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 154 | */ |
astroboy | 0:94897d537b31 | 155 | U64 CoGetOSTime(void) |
astroboy | 0:94897d537b31 | 156 | { |
astroboy | 0:94897d537b31 | 157 | return OSTickCnt; /* Get system time(tick) */ |
astroboy | 0:94897d537b31 | 158 | } |
astroboy | 0:94897d537b31 | 159 | |
astroboy | 0:94897d537b31 | 160 | |
astroboy | 0:94897d537b31 | 161 | /** |
astroboy | 0:94897d537b31 | 162 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 163 | * @brief Delay current task for specify ticks number |
astroboy | 0:94897d537b31 | 164 | * @param[in] ticks Specify system tick number which will delay. |
astroboy | 0:94897d537b31 | 165 | * @param[out] None |
astroboy | 0:94897d537b31 | 166 | * @retval E_CALL Error call in ISR. |
astroboy | 0:94897d537b31 | 167 | * @retval E_OK The current task was insert to DELAY list successful,it |
astroboy | 0:94897d537b31 | 168 | * will delay specify time. |
astroboy | 0:94897d537b31 | 169 | * @par Description |
astroboy | 0:94897d537b31 | 170 | * @details This function delay specify ticks for current task. |
astroboy | 0:94897d537b31 | 171 | * |
astroboy | 0:94897d537b31 | 172 | * @note This function be called in ISR,do nothing and return immediately. |
astroboy | 0:94897d537b31 | 173 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 174 | */ |
astroboy | 0:94897d537b31 | 175 | StatusType CoTickDelay(U32 ticks) |
astroboy | 0:94897d537b31 | 176 | { |
astroboy | 0:94897d537b31 | 177 | if(OSIntNesting >0) /* Is call in ISR? */ |
astroboy | 0:94897d537b31 | 178 | { |
astroboy | 0:94897d537b31 | 179 | return E_CALL; /* Yes,error return */ |
astroboy | 0:94897d537b31 | 180 | } |
astroboy | 0:94897d537b31 | 181 | |
astroboy | 0:94897d537b31 | 182 | if(ticks == INVALID_VALUE) /* Is tick==INVALID_VALUE? */ |
astroboy | 0:94897d537b31 | 183 | { |
astroboy | 0:94897d537b31 | 184 | return E_INVALID_PARAMETER; /* Yes,error return */ |
astroboy | 0:94897d537b31 | 185 | } |
astroboy | 0:94897d537b31 | 186 | if(ticks == 0) /* Is tick==0? */ |
astroboy | 0:94897d537b31 | 187 | { |
astroboy | 0:94897d537b31 | 188 | return E_OK; /* Yes,do nothing ,return OK */ |
astroboy | 0:94897d537b31 | 189 | } |
astroboy | 0:94897d537b31 | 190 | if(OSSchedLock != 0) /* Is OS lock? */ |
astroboy | 0:94897d537b31 | 191 | { |
astroboy | 0:94897d537b31 | 192 | return E_OS_IN_LOCK; /* Yes,error return */ |
astroboy | 0:94897d537b31 | 193 | } |
astroboy | 0:94897d537b31 | 194 | OsSchedLock(); /* Lock schedule */ |
astroboy | 0:94897d537b31 | 195 | InsertDelayList(TCBRunning,ticks); /* Insert task in DELAY list */ |
astroboy | 0:94897d537b31 | 196 | OsSchedUnlock(); /* Unlock schedule,and call task schedule */ |
astroboy | 0:94897d537b31 | 197 | return E_OK; /* Return OK */ |
astroboy | 0:94897d537b31 | 198 | } |
astroboy | 0:94897d537b31 | 199 | |
astroboy | 0:94897d537b31 | 200 | |
astroboy | 0:94897d537b31 | 201 | /** |
astroboy | 0:94897d537b31 | 202 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 203 | * @brief Reset task delay ticks |
astroboy | 0:94897d537b31 | 204 | * @param[in] ptcb Task that want to insert into DELAY list. |
astroboy | 0:94897d537b31 | 205 | * @param[in] ticks Specify system tick number which will delay . |
astroboy | 0:94897d537b31 | 206 | * @param[out] None |
astroboy | 0:94897d537b31 | 207 | * @retval E_CALL Error call in ISR. |
astroboy | 0:94897d537b31 | 208 | * @retval E_INVALID_ID Invalid task id. |
astroboy | 0:94897d537b31 | 209 | * @retval E_NOT_IN_DELAY_LIST Task not in delay list. |
astroboy | 0:94897d537b31 | 210 | * @retval E_OK The current task was inserted to DELAY list |
astroboy | 0:94897d537b31 | 211 | * successful,it will delay for specify time. |
astroboy | 0:94897d537b31 | 212 | * @par Description |
astroboy | 0:94897d537b31 | 213 | * @details This function delay specify ticks for current task. |
astroboy | 0:94897d537b31 | 214 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 215 | */ |
astroboy | 0:94897d537b31 | 216 | StatusType CoResetTaskDelayTick(OS_TID taskID,U32 ticks) |
astroboy | 0:94897d537b31 | 217 | { |
astroboy | 0:94897d537b31 | 218 | P_OSTCB ptcb; |
astroboy | 0:94897d537b31 | 219 | |
astroboy | 0:94897d537b31 | 220 | |
astroboy | 0:94897d537b31 | 221 | #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ |
astroboy | 0:94897d537b31 | 222 | if(taskID >= CFG_MAX_USER_TASKS + SYS_TASK_NUM) |
astroboy | 0:94897d537b31 | 223 | { |
astroboy | 0:94897d537b31 | 224 | return E_INVALID_ID; |
astroboy | 0:94897d537b31 | 225 | } |
astroboy | 0:94897d537b31 | 226 | #endif |
astroboy | 0:94897d537b31 | 227 | |
astroboy | 0:94897d537b31 | 228 | ptcb = &TCBTbl[taskID]; |
astroboy | 0:94897d537b31 | 229 | #if CFG_PAR_CHECKOUT_EN >0 |
astroboy | 0:94897d537b31 | 230 | if(ptcb->stkPtr == Co_NULL) |
astroboy | 0:94897d537b31 | 231 | { |
astroboy | 0:94897d537b31 | 232 | return E_INVALID_ID; |
astroboy | 0:94897d537b31 | 233 | } |
astroboy | 0:94897d537b31 | 234 | #endif |
astroboy | 0:94897d537b31 | 235 | |
astroboy | 0:94897d537b31 | 236 | if(ptcb->delayTick == INVALID_VALUE) /* Is tick==INVALID_VALUE? */ |
astroboy | 0:94897d537b31 | 237 | { |
astroboy | 0:94897d537b31 | 238 | return E_NOT_IN_DELAY_LIST; /* Yes,error return */ |
astroboy | 0:94897d537b31 | 239 | } |
astroboy | 0:94897d537b31 | 240 | OsSchedLock(); /* Lock schedule */ |
astroboy | 0:94897d537b31 | 241 | RemoveDelayList(ptcb); /* Remove task from the DELAY list */ |
astroboy | 0:94897d537b31 | 242 | |
astroboy | 0:94897d537b31 | 243 | if(ticks == 0) /* Is delay tick==0? */ |
astroboy | 0:94897d537b31 | 244 | { |
astroboy | 0:94897d537b31 | 245 | InsertToTCBRdyList(ptcb); /* Insert task into the DELAY list */ |
astroboy | 0:94897d537b31 | 246 | } |
astroboy | 0:94897d537b31 | 247 | else |
astroboy | 0:94897d537b31 | 248 | { |
astroboy | 0:94897d537b31 | 249 | InsertDelayList(ptcb,ticks); /* No,insert task into DELAY list */ |
astroboy | 0:94897d537b31 | 250 | } |
astroboy | 0:94897d537b31 | 251 | OsSchedUnlock(); /* Unlock schedule,and call task schedule */ |
astroboy | 0:94897d537b31 | 252 | return E_OK; /* Return OK */ |
astroboy | 0:94897d537b31 | 253 | } |
astroboy | 0:94897d537b31 | 254 | |
astroboy | 0:94897d537b31 | 255 | |
astroboy | 0:94897d537b31 | 256 | /** |
astroboy | 0:94897d537b31 | 257 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 258 | * @brief Delay current task for detail time |
astroboy | 0:94897d537b31 | 259 | * @param[in] hour Specify the number of hours. |
astroboy | 0:94897d537b31 | 260 | * @param[in] minute Specify the number of minutes. |
astroboy | 0:94897d537b31 | 261 | * @param[in] sec Specify the number of seconds. |
astroboy | 0:94897d537b31 | 262 | * @param[in] millsec Specify the number of millseconds. |
astroboy | 0:94897d537b31 | 263 | * @param[out] None |
astroboy | 0:94897d537b31 | 264 | * @retval E_CALL Error call in ISR. |
astroboy | 0:94897d537b31 | 265 | * @retval E_INVALID_PARAMETER Parameter passed was invalid,delay fail. |
astroboy | 0:94897d537b31 | 266 | * @retval E_OK The current task was inserted to DELAY list |
astroboy | 0:94897d537b31 | 267 | * successful,it will delay for specify time. |
astroboy | 0:94897d537b31 | 268 | * @par Description |
astroboy | 0:94897d537b31 | 269 | * @details This function delay specify time for current task. |
astroboy | 0:94897d537b31 | 270 | * |
astroboy | 0:94897d537b31 | 271 | * @note If this function called in ISR,do nothing and return immediately. |
astroboy | 0:94897d537b31 | 272 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 273 | */ |
astroboy | 0:94897d537b31 | 274 | #if CFG_TIME_DELAY_EN >0 |
astroboy | 0:94897d537b31 | 275 | StatusType CoTimeDelay(U8 hour,U8 minute,U8 sec,U16 millsec) |
astroboy | 0:94897d537b31 | 276 | { |
astroboy | 0:94897d537b31 | 277 | U32 ticks; |
astroboy | 0:94897d537b31 | 278 | #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ |
astroboy | 0:94897d537b31 | 279 | if(OSIntNesting > 0) |
astroboy | 0:94897d537b31 | 280 | { |
astroboy | 0:94897d537b31 | 281 | return E_CALL; |
astroboy | 0:94897d537b31 | 282 | } |
astroboy | 0:94897d537b31 | 283 | if((minute > 59)||(sec > 59)||(millsec > 999)) |
astroboy | 0:94897d537b31 | 284 | return E_INVALID_PARAMETER; |
astroboy | 0:94897d537b31 | 285 | #endif |
astroboy | 0:94897d537b31 | 286 | if(OSSchedLock != 0) /* Is OS lock? */ |
astroboy | 0:94897d537b31 | 287 | { |
astroboy | 0:94897d537b31 | 288 | return E_OS_IN_LOCK; /* Yes,error return */ |
astroboy | 0:94897d537b31 | 289 | } |
astroboy | 0:94897d537b31 | 290 | |
astroboy | 0:94897d537b31 | 291 | /* Get tick counter from time */ |
astroboy | 0:94897d537b31 | 292 | ticks = ((hour*3600) + (minute*60) + (sec)) * (CFG_SYSTICK_FREQ)\ |
astroboy | 0:94897d537b31 | 293 | + (millsec*CFG_SYSTICK_FREQ + 500)/1000; |
astroboy | 0:94897d537b31 | 294 | |
astroboy | 0:94897d537b31 | 295 | CoTickDelay(ticks); /* Call tick delay */ |
astroboy | 0:94897d537b31 | 296 | return E_OK; /* Return OK */ |
astroboy | 0:94897d537b31 | 297 | } |
astroboy | 0:94897d537b31 | 298 | #endif |
astroboy | 0:94897d537b31 | 299 | |
astroboy | 0:94897d537b31 | 300 | |
astroboy | 0:94897d537b31 | 301 | |
astroboy | 0:94897d537b31 | 302 | |
astroboy | 0:94897d537b31 | 303 | /** |
astroboy | 0:94897d537b31 | 304 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 305 | * @brief Dispose time delay |
astroboy | 0:94897d537b31 | 306 | * @param[in] None |
astroboy | 0:94897d537b31 | 307 | * @param[out] None |
astroboy | 0:94897d537b31 | 308 | * @retval None |
astroboy | 0:94897d537b31 | 309 | * |
astroboy | 0:94897d537b31 | 310 | * @par Description |
astroboy | 0:94897d537b31 | 311 | * @details This function is called to dispose time delay of all task. |
astroboy | 0:94897d537b31 | 312 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 313 | */ |
astroboy | 0:94897d537b31 | 314 | void TimeDispose(void) |
astroboy | 0:94897d537b31 | 315 | { |
astroboy | 0:94897d537b31 | 316 | P_OSTCB dlyList; |
astroboy | 0:94897d537b31 | 317 | |
astroboy | 0:94897d537b31 | 318 | dlyList = DlyList; /* Get first item of DELAY list */ |
astroboy | 0:94897d537b31 | 319 | while((dlyList != 0) && (dlyList->delayTick == 0) ) |
astroboy | 0:94897d537b31 | 320 | { |
astroboy | 0:94897d537b31 | 321 | |
astroboy | 0:94897d537b31 | 322 | #if CFG_EVENT_EN > 0 |
astroboy | 0:94897d537b31 | 323 | if(dlyList->eventID != INVALID_ID) /* Is task in event waiting list? */ |
astroboy | 0:94897d537b31 | 324 | { |
astroboy | 0:94897d537b31 | 325 | RemoveEventWaittingList(dlyList); /* Yes,remove task from list */ |
astroboy | 0:94897d537b31 | 326 | } |
astroboy | 0:94897d537b31 | 327 | #endif |
astroboy | 0:94897d537b31 | 328 | |
astroboy | 0:94897d537b31 | 329 | #if CFG_FLAG_EN > 0 |
astroboy | 0:94897d537b31 | 330 | if(dlyList->pnode != 0) /* Is task in flag waiting list? */ |
astroboy | 0:94897d537b31 | 331 | { |
astroboy | 0:94897d537b31 | 332 | RemoveLinkNode((P_FLAG_NODE)dlyList->pnode); /* Yes,remove task from list */ |
astroboy | 0:94897d537b31 | 333 | } |
astroboy | 0:94897d537b31 | 334 | #endif |
astroboy | 0:94897d537b31 | 335 | dlyList->delayTick = INVALID_VALUE; /* Set delay tick value as invalid*/ |
astroboy | 0:94897d537b31 | 336 | DlyList = dlyList->TCBnext; /* Get next item as the head of DELAY list*/ |
astroboy | 0:94897d537b31 | 337 | dlyList->TCBnext = 0; |
astroboy | 0:94897d537b31 | 338 | |
astroboy | 0:94897d537b31 | 339 | InsertToTCBRdyList(dlyList); /* Insert task into READY list */ |
astroboy | 0:94897d537b31 | 340 | |
astroboy | 0:94897d537b31 | 341 | dlyList = DlyList; /* Get the first item of DELAY list */ |
astroboy | 0:94897d537b31 | 342 | if(dlyList != 0) /* Is DELAY list as Co_NULL? */ |
astroboy | 0:94897d537b31 | 343 | { |
astroboy | 0:94897d537b31 | 344 | dlyList->TCBprev = 0; /* No,initialize the first item */ |
astroboy | 0:94897d537b31 | 345 | } |
astroboy | 0:94897d537b31 | 346 | } |
astroboy | 0:94897d537b31 | 347 | } |
astroboy | 0:94897d537b31 | 348 | |
astroboy | 0:94897d537b31 | 349 | |
astroboy | 0:94897d537b31 | 350 | /** |
astroboy | 0:94897d537b31 | 351 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 352 | * @brief Dispose time delay in ISR |
astroboy | 0:94897d537b31 | 353 | * @param[in] None |
astroboy | 0:94897d537b31 | 354 | * @param[out] None |
astroboy | 0:94897d537b31 | 355 | * @retval None |
astroboy | 0:94897d537b31 | 356 | * |
astroboy | 0:94897d537b31 | 357 | * @par Description |
astroboy | 0:94897d537b31 | 358 | * @details This function is called in systick interrupt to dispose time delay |
astroboy | 0:94897d537b31 | 359 | * of all task. |
astroboy | 0:94897d537b31 | 360 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 361 | */ |
astroboy | 0:94897d537b31 | 362 | void isr_TimeDispose(void) |
astroboy | 0:94897d537b31 | 363 | { |
astroboy | 0:94897d537b31 | 364 | if(OSSchedLock > 1) /* Is schedule lock? */ |
astroboy | 0:94897d537b31 | 365 | { |
astroboy | 0:94897d537b31 | 366 | IsrReq = Co_TRUE; |
astroboy | 0:94897d537b31 | 367 | TimeReq = Co_TRUE; /* Yes,set time request Co_TRUE */ |
astroboy | 0:94897d537b31 | 368 | } |
astroboy | 0:94897d537b31 | 369 | else |
astroboy | 0:94897d537b31 | 370 | { |
astroboy | 0:94897d537b31 | 371 | TimeDispose(); /* No,call handler */ |
astroboy | 0:94897d537b31 | 372 | } |
astroboy | 0:94897d537b31 | 373 | } |
astroboy | 0:94897d537b31 | 374 | |
astroboy | 0:94897d537b31 | 375 | |
astroboy | 0:94897d537b31 | 376 | #endif |