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 timer.c
ericebert 0:57690853989a 4 * @version V1.1.3
ericebert 0:57690853989a 5 * @date 2010.04.26
ericebert 0:57690853989a 6 * @brief timer management implementation code of CooCox CoOS kernel.
ericebert 0:57690853989a 7 *******************************************************************************
ericebert 0:57690853989a 8 * @copy
ericebert 0:57690853989a 9 *
ericebert 0:57690853989a 10 * INTERNAL FILE,DON'T PUBLIC.
ericebert 0:57690853989a 11 *
ericebert 0:57690853989a 12 * <h2><center>&copy; COPYRIGHT 2009 CooCox </center></h2>
ericebert 0:57690853989a 13 *******************************************************************************
ericebert 0:57690853989a 14 */
ericebert 0:57690853989a 15
ericebert 0:57690853989a 16
ericebert 0:57690853989a 17
ericebert 0:57690853989a 18 /*---------------------------- Include ---------------------------------------*/
ericebert 0:57690853989a 19 #include <coocox.h>
ericebert 0:57690853989a 20
ericebert 0:57690853989a 21 /*---------------------------- Variable Define -------------------------------*/
ericebert 0:57690853989a 22 #if CFG_TMR_EN > 0
ericebert 0:57690853989a 23
ericebert 0:57690853989a 24 TmrCtrl TmrTbl[CFG_MAX_TMR]= {{0}};/*!< Table which save timer control block.*/
ericebert 0:57690853989a 25 P_TmrCtrl TmrList = 0; /*!< The header of the TmrCtrl list. */
ericebert 0:57690853989a 26 U32 TmrIDVessel = 0; /*!< Timer ID container. */
ericebert 0:57690853989a 27
ericebert 0:57690853989a 28
ericebert 0:57690853989a 29 /**
ericebert 0:57690853989a 30 *******************************************************************************
ericebert 0:57690853989a 31 * @brief Insert a timer into the timer list
ericebert 0:57690853989a 32 * @param[in] tmrID Specify timer ID which insertted.
ericebert 0:57690853989a 33 * @param[out] None
ericebert 0:57690853989a 34 * @retval E_INVALID_ID Timer ID passed was invalid,insert fail.
ericebert 0:57690853989a 35 * @retval E_OK Insert successful.
ericebert 0:57690853989a 36 *
ericebert 0:57690853989a 37 * @par Description
ericebert 0:57690853989a 38 * @details This function is called to insert a timer into the timer list.
ericebert 0:57690853989a 39 *******************************************************************************
ericebert 0:57690853989a 40 */
ericebert 0:57690853989a 41 static void InsertTmrList(OS_TCID tmrID)
ericebert 0:57690853989a 42 {
ericebert 0:57690853989a 43 P_TmrCtrl pTmr;
ericebert 0:57690853989a 44 S32 deltaTicks;
ericebert 0:57690853989a 45 U32 tmrCnt;
ericebert 0:57690853989a 46 tmrCnt = TmrTbl[tmrID].tmrCnt; /* Get timer time */
ericebert 0:57690853989a 47
ericebert 0:57690853989a 48 if(tmrCnt == 0) /* Is timer time==0? */
ericebert 0:57690853989a 49 {
ericebert 0:57690853989a 50 return; /* Do nothing,return */
ericebert 0:57690853989a 51 }
ericebert 0:57690853989a 52
ericebert 0:57690853989a 53 OsSchedLock(); /* Lock schedule */
ericebert 0:57690853989a 54 if(TmrList == 0) /* Is no item in timer list? */
ericebert 0:57690853989a 55 {
ericebert 0:57690853989a 56 TmrList = &TmrTbl[tmrID]; /* Yes,set this as first item */
ericebert 0:57690853989a 57 }
ericebert 0:57690853989a 58 else /* No,find correct place ,and insert inserted timer */
ericebert 0:57690853989a 59 {
ericebert 0:57690853989a 60 pTmr = TmrList;
ericebert 0:57690853989a 61 deltaTicks = tmrCnt; /* Get timer tick */
ericebert 0:57690853989a 62
ericebert 0:57690853989a 63 /* find correct place */
ericebert 0:57690853989a 64 while(pTmr != 0)
ericebert 0:57690853989a 65 {
ericebert 0:57690853989a 66 deltaTicks -= pTmr->tmrCnt; /* Get ticks with previous item */
ericebert 0:57690853989a 67 if(deltaTicks < 0) /* Is delta ticks<0? */
ericebert 0:57690853989a 68 {
ericebert 0:57690853989a 69 /* Yes,get correct place */
ericebert 0:57690853989a 70 if(pTmr->tmrPrev!= 0)/* Is head item of timer list? */
ericebert 0:57690853989a 71 {
ericebert 0:57690853989a 72 /* No,insert into */
ericebert 0:57690853989a 73 pTmr->tmrPrev->tmrNext = &TmrTbl[tmrID];
ericebert 0:57690853989a 74 TmrTbl[tmrID].tmrPrev = pTmr->tmrPrev;
ericebert 0:57690853989a 75 TmrTbl[tmrID].tmrNext = pTmr;
ericebert 0:57690853989a 76 pTmr->tmrPrev = &TmrTbl[tmrID];
ericebert 0:57690853989a 77 }
ericebert 0:57690853989a 78 else /* Yes,set task as first item */
ericebert 0:57690853989a 79 {
ericebert 0:57690853989a 80 TmrTbl[tmrID].tmrNext = TmrList;
ericebert 0:57690853989a 81 TmrList->tmrPrev = &TmrTbl[tmrID];
ericebert 0:57690853989a 82 TmrList = &TmrTbl[tmrID];
ericebert 0:57690853989a 83 }
ericebert 0:57690853989a 84 TmrTbl[tmrID].tmrCnt = TmrTbl[tmrID].tmrNext->tmrCnt+deltaTicks;
ericebert 0:57690853989a 85 TmrTbl[tmrID].tmrNext->tmrCnt -= TmrTbl[tmrID].tmrCnt;
ericebert 0:57690853989a 86 break;
ericebert 0:57690853989a 87 }
ericebert 0:57690853989a 88 /* Is last item in list? */
ericebert 0:57690853989a 89 else if((deltaTicks >= 0) && (pTmr->tmrNext == 0))
ericebert 0:57690853989a 90 {
ericebert 0:57690853989a 91 /* Yes,insert into */
ericebert 0:57690853989a 92 TmrTbl[tmrID].tmrPrev = pTmr;
ericebert 0:57690853989a 93 pTmr->tmrNext = &TmrTbl[tmrID];
ericebert 0:57690853989a 94 TmrTbl[tmrID].tmrCnt = deltaTicks;
ericebert 0:57690853989a 95 break;
ericebert 0:57690853989a 96 }
ericebert 0:57690853989a 97 pTmr = pTmr->tmrNext; /* Get the next item in timer list */
ericebert 0:57690853989a 98 }
ericebert 0:57690853989a 99 }
ericebert 0:57690853989a 100 OsSchedUnlock(); /* Unlock schedule */
ericebert 0:57690853989a 101 }
ericebert 0:57690853989a 102
ericebert 0:57690853989a 103
ericebert 0:57690853989a 104 /**
ericebert 0:57690853989a 105 *******************************************************************************
ericebert 0:57690853989a 106 * @brief Remove a timer from the timer list
ericebert 0:57690853989a 107 * @param[in] tmrID Specify ID for a timer which removed form timer list.
ericebert 0:57690853989a 108 * @param[out] None
ericebert 0:57690853989a 109 * @retval None
ericebert 0:57690853989a 110 *
ericebert 0:57690853989a 111 * @par Description
ericebert 0:57690853989a 112 * @details This function is called to remove a timer from the timer list.
ericebert 0:57690853989a 113 *******************************************************************************
ericebert 0:57690853989a 114 */
ericebert 0:57690853989a 115 static void RemoveTmrList(OS_TCID tmrID)
ericebert 0:57690853989a 116 {
ericebert 0:57690853989a 117 P_TmrCtrl pTmr;
ericebert 0:57690853989a 118
ericebert 0:57690853989a 119 pTmr = &TmrTbl[tmrID];
ericebert 0:57690853989a 120
ericebert 0:57690853989a 121 OsSchedLock(); /* Lock schedule */
ericebert 0:57690853989a 122
ericebert 0:57690853989a 123 /* Is there only one item in timer list? */
ericebert 0:57690853989a 124 if((pTmr->tmrPrev == 0) && (pTmr->tmrNext == 0))
ericebert 0:57690853989a 125 {
ericebert 0:57690853989a 126 TmrList = 0; /* Yes,set timer list as 0 */
ericebert 0:57690853989a 127 }
ericebert 0:57690853989a 128 else if(pTmr->tmrPrev == 0) /* Is the first item in timer list? */
ericebert 0:57690853989a 129 { /* Yes,remove timer from list,and reset timer list */
ericebert 0:57690853989a 130 TmrList = pTmr->tmrNext;
ericebert 0:57690853989a 131 TmrList->tmrPrev = 0;
ericebert 0:57690853989a 132 pTmr->tmrNext->tmrCnt += pTmr->tmrCnt;
ericebert 0:57690853989a 133 pTmr->tmrNext = 0;
ericebert 0:57690853989a 134 }
ericebert 0:57690853989a 135 else if(pTmr->tmrNext == 0) /* Is the last item in timer list? */
ericebert 0:57690853989a 136 {
ericebert 0:57690853989a 137 /* Yes,remove timer form list */
ericebert 0:57690853989a 138 pTmr->tmrPrev->tmrNext = 0;
ericebert 0:57690853989a 139 pTmr->tmrPrev = 0;
ericebert 0:57690853989a 140 }
ericebert 0:57690853989a 141 else /* No, remove timer from list */
ericebert 0:57690853989a 142 {
ericebert 0:57690853989a 143 pTmr->tmrPrev->tmrNext = pTmr->tmrNext;
ericebert 0:57690853989a 144 pTmr->tmrNext->tmrPrev = pTmr->tmrPrev;
ericebert 0:57690853989a 145 pTmr->tmrNext->tmrCnt += pTmr->tmrCnt;
ericebert 0:57690853989a 146 pTmr->tmrNext = 0;
ericebert 0:57690853989a 147 pTmr->tmrPrev = 0;
ericebert 0:57690853989a 148 }
ericebert 0:57690853989a 149 OsSchedUnlock(); /* Unlock schedule */
ericebert 0:57690853989a 150 }
ericebert 0:57690853989a 151
ericebert 0:57690853989a 152
ericebert 0:57690853989a 153 /**
ericebert 0:57690853989a 154 *******************************************************************************
ericebert 0:57690853989a 155 * @brief Create a timer
ericebert 0:57690853989a 156 * @param[in] tmrType Specify timer's type.
ericebert 0:57690853989a 157 * @param[in] tmrCnt Specify timer initial counter value.
ericebert 0:57690853989a 158 * @param[in] tmrReload Specify timer reload value.
ericebert 0:57690853989a 159 * @param[in] func Specify timer callback function entry.
ericebert 0:57690853989a 160 * @param[out] None
ericebert 0:57690853989a 161 * @retval E_CREATE_FAIL Create timer fail.
ericebert 0:57690853989a 162 * @retval others Create timer successful.
ericebert 0:57690853989a 163 *
ericebert 0:57690853989a 164 * @par Description
ericebert 0:57690853989a 165 * @details This function is called to create a timer.
ericebert 0:57690853989a 166 *******************************************************************************
ericebert 0:57690853989a 167 */
ericebert 0:57690853989a 168 OS_TCID CoCreateTmr(U8 tmrType, U32 tmrCnt, U32 tmrReload, vFUNCPtr func)
ericebert 0:57690853989a 169 {
ericebert 0:57690853989a 170 U8 i;
ericebert 0:57690853989a 171 #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
ericebert 0:57690853989a 172 if((tmrType != TMR_TYPE_ONE_SHOT) && (tmrType != TMR_TYPE_PERIODIC))
ericebert 0:57690853989a 173 {
ericebert 0:57690853989a 174 return E_CREATE_FAIL;
ericebert 0:57690853989a 175 }
ericebert 0:57690853989a 176 if(func == 0)
ericebert 0:57690853989a 177 {
ericebert 0:57690853989a 178 return E_CREATE_FAIL;
ericebert 0:57690853989a 179 }
ericebert 0:57690853989a 180 #endif
ericebert 0:57690853989a 181 OsSchedLock(); /* Lock schedule */
ericebert 0:57690853989a 182 for(i = 0; i < CFG_MAX_TMR; i++)
ericebert 0:57690853989a 183 {
ericebert 0:57690853989a 184 if((TmrIDVessel & (1 << i)) == 0) /* Is free timer ID? */
ericebert 0:57690853989a 185 {
ericebert 0:57690853989a 186 TmrIDVessel |= (1<<i); /* Yes,assign ID to this timer */
ericebert 0:57690853989a 187 OsSchedUnlock(); /* Unlock schedule */
ericebert 0:57690853989a 188 TmrTbl[i].tmrID = i; /* Initialize timer as user set */
ericebert 0:57690853989a 189 TmrTbl[i].tmrType = tmrType;
ericebert 0:57690853989a 190 TmrTbl[i].tmrState = TMR_STATE_STOPPED;
ericebert 0:57690853989a 191 TmrTbl[i].tmrCnt = tmrCnt;
ericebert 0:57690853989a 192 TmrTbl[i].tmrReload = tmrReload;
ericebert 0:57690853989a 193 TmrTbl[i].tmrCallBack = func;
ericebert 0:57690853989a 194 TmrTbl[i].tmrPrev = 0;
ericebert 0:57690853989a 195 TmrTbl[i].tmrNext = 0;
ericebert 0:57690853989a 196 return i; /* Return timer ID */
ericebert 0:57690853989a 197 }
ericebert 0:57690853989a 198 }
ericebert 0:57690853989a 199 OsSchedUnlock(); /* Unlock schedule */
ericebert 0:57690853989a 200 return E_CREATE_FAIL; /* Error return */
ericebert 0:57690853989a 201 }
ericebert 0:57690853989a 202
ericebert 0:57690853989a 203
ericebert 0:57690853989a 204 /**
ericebert 0:57690853989a 205 *******************************************************************************
ericebert 0:57690853989a 206 * @brief Start counter
ericebert 0:57690853989a 207 * @param[in] tmrID Specify a timer which startted.
ericebert 0:57690853989a 208 * @param[out] None
ericebert 0:57690853989a 209 * @retval E_INVALID_ID The timer id passed was invalid,can't start timer
ericebert 0:57690853989a 210 * @retval E_OK Insert a timer to timer list and start it successful.
ericebert 0:57690853989a 211 *
ericebert 0:57690853989a 212 * @par Description
ericebert 0:57690853989a 213 * @details This function is called to make a timer start countering.
ericebert 0:57690853989a 214 *******************************************************************************
ericebert 0:57690853989a 215 */
ericebert 0:57690853989a 216 StatusType CoStartTmr(OS_TCID tmrID)
ericebert 0:57690853989a 217 {
ericebert 0:57690853989a 218 #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
ericebert 0:57690853989a 219 if(tmrID >= CFG_MAX_TMR)
ericebert 0:57690853989a 220 {
ericebert 0:57690853989a 221 return E_INVALID_ID;
ericebert 0:57690853989a 222 }
ericebert 0:57690853989a 223 if( (TmrIDVessel & (1<<tmrID)) == 0)
ericebert 0:57690853989a 224 {
ericebert 0:57690853989a 225 return E_INVALID_ID;
ericebert 0:57690853989a 226 }
ericebert 0:57690853989a 227 #endif
ericebert 0:57690853989a 228
ericebert 0:57690853989a 229 if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING) /* Is timer running? */
ericebert 0:57690853989a 230 {
ericebert 0:57690853989a 231 return E_OK; /* Yes,do nothing,return OK */
ericebert 0:57690853989a 232 }
ericebert 0:57690853989a 233
ericebert 0:57690853989a 234 /* No,set timer status as TMR_STATE_RUNNING */
ericebert 0:57690853989a 235 TmrTbl[tmrID].tmrState = TMR_STATE_RUNNING;
ericebert 0:57690853989a 236 InsertTmrList(tmrID); /* Insert this timer into timer list */
ericebert 0:57690853989a 237 return E_OK; /* Return OK */
ericebert 0:57690853989a 238 }
ericebert 0:57690853989a 239
ericebert 0:57690853989a 240
ericebert 0:57690853989a 241
ericebert 0:57690853989a 242 /**
ericebert 0:57690853989a 243 *******************************************************************************
ericebert 0:57690853989a 244 * @brief Stop countering for a spcify timer
ericebert 0:57690853989a 245 * @param[in] tmrID Specify a timer which stopped.
ericebert 0:57690853989a 246 * @param[out] None
ericebert 0:57690853989a 247 * @retval E_INVALID_ID The timer id passed was invalid, stop failure.
ericebert 0:57690853989a 248 * @retval E_OK Stop a timer countering successful.
ericebert 0:57690853989a 249 *
ericebert 0:57690853989a 250 * @par Description
ericebert 0:57690853989a 251 * @details This function is called to stop a timer from counting.
ericebert 0:57690853989a 252 *******************************************************************************
ericebert 0:57690853989a 253 */
ericebert 0:57690853989a 254 StatusType CoStopTmr(OS_TCID tmrID)
ericebert 0:57690853989a 255 {
ericebert 0:57690853989a 256 #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
ericebert 0:57690853989a 257 if(tmrID >= CFG_MAX_TMR)
ericebert 0:57690853989a 258 {
ericebert 0:57690853989a 259 return E_INVALID_ID;
ericebert 0:57690853989a 260 }
ericebert 0:57690853989a 261 if((TmrIDVessel & (1<<tmrID)) == 0)
ericebert 0:57690853989a 262 {
ericebert 0:57690853989a 263 return E_INVALID_ID;
ericebert 0:57690853989a 264 }
ericebert 0:57690853989a 265 #endif
ericebert 0:57690853989a 266
ericebert 0:57690853989a 267
ericebert 0:57690853989a 268 if(TmrTbl[tmrID].tmrState == TMR_STATE_STOPPED)/* Does timer stop running?*/
ericebert 0:57690853989a 269 {
ericebert 0:57690853989a 270 return E_OK; /* Yes,do nothing,return OK */
ericebert 0:57690853989a 271 }
ericebert 0:57690853989a 272 RemoveTmrList(tmrID); /* No,remove this timer from timer list */
ericebert 0:57690853989a 273
ericebert 0:57690853989a 274 /* Set timer status as TMR_STATE_STOPPED */
ericebert 0:57690853989a 275 TmrTbl[tmrID].tmrState = TMR_STATE_STOPPED;
ericebert 0:57690853989a 276 return E_OK; /* Return OK */
ericebert 0:57690853989a 277 }
ericebert 0:57690853989a 278
ericebert 0:57690853989a 279
ericebert 0:57690853989a 280 /**
ericebert 0:57690853989a 281 *******************************************************************************
ericebert 0:57690853989a 282 * @brief Delete a timer
ericebert 0:57690853989a 283 * @param[in] tmrID Specify a timer which deleted.
ericebert 0:57690853989a 284 * @param[out] None
ericebert 0:57690853989a 285 * @retval E_INVALID_ID The timer id passed was invalid,deleted failure.
ericebert 0:57690853989a 286 * @retval E_OK Delete a timer successful.
ericebert 0:57690853989a 287 *
ericebert 0:57690853989a 288 * @par Description
ericebert 0:57690853989a 289 * @details This function is called to delete a timer which created before.
ericebert 0:57690853989a 290 *******************************************************************************
ericebert 0:57690853989a 291 */
ericebert 0:57690853989a 292 StatusType CoDelTmr(OS_TCID tmrID)
ericebert 0:57690853989a 293 {
ericebert 0:57690853989a 294 #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
ericebert 0:57690853989a 295 if(tmrID >= CFG_MAX_TMR)
ericebert 0:57690853989a 296 {
ericebert 0:57690853989a 297 return E_INVALID_ID;
ericebert 0:57690853989a 298 }
ericebert 0:57690853989a 299 if( (TmrIDVessel & (1<<tmrID)) == 0)
ericebert 0:57690853989a 300 {
ericebert 0:57690853989a 301 return E_INVALID_ID;
ericebert 0:57690853989a 302 }
ericebert 0:57690853989a 303 #endif
ericebert 0:57690853989a 304
ericebert 0:57690853989a 305 if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING) /* Is timer running? */
ericebert 0:57690853989a 306 {
ericebert 0:57690853989a 307 RemoveTmrList(tmrID); /* Yes,remove this timer from timer list*/
ericebert 0:57690853989a 308 }
ericebert 0:57690853989a 309 TmrIDVessel &=~(1<<tmrID); /* Release resource that this timer hold*/
ericebert 0:57690853989a 310 return E_OK; /* Return OK */
ericebert 0:57690853989a 311 }
ericebert 0:57690853989a 312
ericebert 0:57690853989a 313
ericebert 0:57690853989a 314 /**
ericebert 0:57690853989a 315 *******************************************************************************
ericebert 0:57690853989a 316 * @brief Get current counter of specify timer
ericebert 0:57690853989a 317 * @param[in] tmrID Specify timer by ID.
ericebert 0:57690853989a 318 * @param[out] E_INVALID_ID Invalid ID was passed and get counter failure.
ericebert 0:57690853989a 319 * @param[out] E_OK Get current counter successful.
ericebert 0:57690853989a 320 * @retval Current counter of a timer which specify by id.
ericebert 0:57690853989a 321 *
ericebert 0:57690853989a 322 * @par Description
ericebert 0:57690853989a 323 * @details This function is called to obtain current counter of specify timer.
ericebert 0:57690853989a 324 *******************************************************************************
ericebert 0:57690853989a 325 */
ericebert 0:57690853989a 326 U32 CoGetCurTmrCnt(OS_TCID tmrID,StatusType* perr)
ericebert 0:57690853989a 327 {
ericebert 0:57690853989a 328 #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
ericebert 0:57690853989a 329 if(tmrID >= CFG_MAX_TMR)
ericebert 0:57690853989a 330 {
ericebert 0:57690853989a 331 *perr = E_INVALID_ID;
ericebert 0:57690853989a 332 return 0;
ericebert 0:57690853989a 333 }
ericebert 0:57690853989a 334 if((TmrIDVessel & (1<<tmrID)) == 0)
ericebert 0:57690853989a 335 {
ericebert 0:57690853989a 336 *perr = E_INVALID_ID;
ericebert 0:57690853989a 337 return 0;
ericebert 0:57690853989a 338 }
ericebert 0:57690853989a 339 #endif
ericebert 0:57690853989a 340 *perr = E_OK;
ericebert 0:57690853989a 341 return TmrTbl[tmrID].tmrCnt; /* Return timer counter */
ericebert 0:57690853989a 342 }
ericebert 0:57690853989a 343
ericebert 0:57690853989a 344
ericebert 0:57690853989a 345 /**
ericebert 0:57690853989a 346 *******************************************************************************
ericebert 0:57690853989a 347 * @brief Setting for a specify timer
ericebert 0:57690853989a 348 * @param[in] tmrID Specify timer by ID.
ericebert 0:57690853989a 349 * @param[in] tmrCnt Specify timer counter which need to be set.
ericebert 0:57690853989a 350 * @param[in] tmrReload Specify timer reload value which need to be set.
ericebert 0:57690853989a 351 * @param[out] None
ericebert 0:57690853989a 352 * @retval E_INVALID_ID The ID passed was invalid,set fail.
ericebert 0:57690853989a 353 * @retval E_OK Set timer counter successful.
ericebert 0:57690853989a 354 *
ericebert 0:57690853989a 355 * @par Description
ericebert 0:57690853989a 356 * @details This function is called to set timer counter and reload value.
ericebert 0:57690853989a 357 *******************************************************************************
ericebert 0:57690853989a 358 */
ericebert 0:57690853989a 359 StatusType CoSetTmrCnt(OS_TCID tmrID,U32 tmrCnt,U32 tmrReload)
ericebert 0:57690853989a 360 {
ericebert 0:57690853989a 361 #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */
ericebert 0:57690853989a 362 if(tmrID >= CFG_MAX_TMR)
ericebert 0:57690853989a 363 {
ericebert 0:57690853989a 364 return E_INVALID_ID;
ericebert 0:57690853989a 365 }
ericebert 0:57690853989a 366 if( (TmrIDVessel & (1<<tmrID)) == 0)
ericebert 0:57690853989a 367 {
ericebert 0:57690853989a 368 return E_INVALID_ID;
ericebert 0:57690853989a 369 }
ericebert 0:57690853989a 370 #endif
ericebert 0:57690853989a 371 TmrTbl[tmrID].tmrCnt = tmrCnt; /* Reset timer counter and reload value */
ericebert 0:57690853989a 372 TmrTbl[tmrID].tmrReload = tmrReload;
ericebert 0:57690853989a 373
ericebert 0:57690853989a 374 if(TmrTbl[tmrID].tmrState == TMR_STATE_RUNNING) /* Is timer running? */
ericebert 0:57690853989a 375 {
ericebert 0:57690853989a 376 RemoveTmrList(tmrID); /* Yes,reorder timer in timer list */
ericebert 0:57690853989a 377 InsertTmrList(tmrID);
ericebert 0:57690853989a 378 }
ericebert 0:57690853989a 379 return E_OK; /* Return OK */
ericebert 0:57690853989a 380 }
ericebert 0:57690853989a 381
ericebert 0:57690853989a 382
ericebert 0:57690853989a 383 /**
ericebert 0:57690853989a 384 *******************************************************************************
ericebert 0:57690853989a 385 * @brief Timer counter dispose
ericebert 0:57690853989a 386 * @param[in] None
ericebert 0:57690853989a 387 * @param[out] None
ericebert 0:57690853989a 388 * @retval None
ericebert 0:57690853989a 389 *
ericebert 0:57690853989a 390 * @par Description
ericebert 0:57690853989a 391 * @details This function is called to dispose timer counter.
ericebert 0:57690853989a 392 *******************************************************************************
ericebert 0:57690853989a 393 */
ericebert 0:57690853989a 394 void TmrDispose(void)
ericebert 0:57690853989a 395 {
ericebert 0:57690853989a 396 P_TmrCtrl pTmr;
ericebert 0:57690853989a 397
ericebert 0:57690853989a 398 pTmr = TmrList; /* Get first item of timer list */
ericebert 0:57690853989a 399 while((pTmr != 0) && (pTmr->tmrCnt == 0) )
ericebert 0:57690853989a 400 {
ericebert 0:57690853989a 401 if(pTmr->tmrType == TMR_TYPE_ONE_SHOT) /* Is a One-shot timer? */
ericebert 0:57690853989a 402 {
ericebert 0:57690853989a 403 /* Yes,remove this timer from timer list */
ericebert 0:57690853989a 404 RemoveTmrList(pTmr->tmrID);
ericebert 0:57690853989a 405
ericebert 0:57690853989a 406 /* Set timer status as TMR_STATE_STOPPED */
ericebert 0:57690853989a 407 pTmr->tmrState = TMR_STATE_STOPPED;
ericebert 0:57690853989a 408 (pTmr->tmrCallBack)(); /* Call timer callback function */
ericebert 0:57690853989a 409 }
ericebert 0:57690853989a 410 else if(pTmr->tmrType == TMR_TYPE_PERIODIC) /* Is a periodic timer? */
ericebert 0:57690853989a 411 {
ericebert 0:57690853989a 412 /* Yes,remove this timer from timer list */
ericebert 0:57690853989a 413 RemoveTmrList(pTmr->tmrID);
ericebert 0:57690853989a 414 pTmr->tmrCnt = pTmr->tmrReload; /* Reset timer tick */
ericebert 0:57690853989a 415 InsertTmrList(pTmr->tmrID); /* Insert timer into timer list */
ericebert 0:57690853989a 416 (pTmr->tmrCallBack)(); /* Call timer callback function */
ericebert 0:57690853989a 417 }
ericebert 0:57690853989a 418 pTmr = TmrList; /* Get first item of timer list */
ericebert 0:57690853989a 419 }
ericebert 0:57690853989a 420 }
ericebert 0:57690853989a 421
ericebert 0:57690853989a 422
ericebert 0:57690853989a 423 /**
ericebert 0:57690853989a 424 *******************************************************************************
ericebert 0:57690853989a 425 * @brief Timer counter dispose in ISR
ericebert 0:57690853989a 426 * @param[in] None
ericebert 0:57690853989a 427 * @param[out] None
ericebert 0:57690853989a 428 * @retval None
ericebert 0:57690853989a 429 *
ericebert 0:57690853989a 430 * @par Description
ericebert 0:57690853989a 431 * @details This function is called to dispose timer counter.
ericebert 0:57690853989a 432 *******************************************************************************
ericebert 0:57690853989a 433 */
ericebert 0:57690853989a 434 void isr_TmrDispose(void)
ericebert 0:57690853989a 435 {
ericebert 0:57690853989a 436 if(OSSchedLock > 1) /* Is schedule lock? */
ericebert 0:57690853989a 437 {
ericebert 0:57690853989a 438 IsrReq = TRUE;
ericebert 0:57690853989a 439 TimerReq = TRUE; /* Yes,set timer request true */
ericebert 0:57690853989a 440 }
ericebert 0:57690853989a 441 else
ericebert 0:57690853989a 442 {
ericebert 0:57690853989a 443 TmrDispose(); /* No,call handler */
ericebert 0:57690853989a 444 }
ericebert 0:57690853989a 445 }
ericebert 0:57690853989a 446
ericebert 0:57690853989a 447 #endif