![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CoOS Demonstrator adapted to mbed Hardware.
event.c@0:57690853989a, 2010-12-03 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
ericebert | 0:57690853989a | 1 | /** |
ericebert | 0:57690853989a | 2 | ******************************************************************************* |
ericebert | 0:57690853989a | 3 | * @file event.c |
ericebert | 0:57690853989a | 4 | * @version V1.1.3 |
ericebert | 0:57690853989a | 5 | * @date 2010.04.26 |
ericebert | 0:57690853989a | 6 | * @brief event 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>© 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 | /*---------------------------- Include ---------------------------------------*/ |
ericebert | 0:57690853989a | 18 | #include <coocox.h> |
ericebert | 0:57690853989a | 19 | |
ericebert | 0:57690853989a | 20 | |
ericebert | 0:57690853989a | 21 | /*---------------------------- Variable Define -------------------------------*/ |
ericebert | 0:57690853989a | 22 | #if CFG_EVENT_EN > 0 |
ericebert | 0:57690853989a | 23 | |
ericebert | 0:57690853989a | 24 | ECB EventTbl[CFG_MAX_EVENT]= {{0}};/*!< Table which save event control block.*/ |
ericebert | 0:57690853989a | 25 | P_ECB FreeEventList = 0; /*!< Pointer to free event control block. */ |
ericebert | 0:57690853989a | 26 | |
ericebert | 0:57690853989a | 27 | |
ericebert | 0:57690853989a | 28 | /** |
ericebert | 0:57690853989a | 29 | ******************************************************************************* |
ericebert | 0:57690853989a | 30 | * @brief Create a empty list of event control block |
ericebert | 0:57690853989a | 31 | * @param[in] None |
ericebert | 0:57690853989a | 32 | * @param[out] None |
ericebert | 0:57690853989a | 33 | * @retval None |
ericebert | 0:57690853989a | 34 | * |
ericebert | 0:57690853989a | 35 | * @par Description |
ericebert | 0:57690853989a | 36 | * @details This function is called by OSInit() API to create a ECB list,supply |
ericebert | 0:57690853989a | 37 | * a pointer to next event control block that not used. |
ericebert | 0:57690853989a | 38 | ******************************************************************************* |
ericebert | 0:57690853989a | 39 | */ |
ericebert | 0:57690853989a | 40 | void CreateEventList(void) |
ericebert | 0:57690853989a | 41 | { |
ericebert | 0:57690853989a | 42 | U8 i; |
ericebert | 0:57690853989a | 43 | P_ECB pecb1; |
ericebert | 0:57690853989a | 44 | #if CFG_MAX_EVENT > 1 |
ericebert | 0:57690853989a | 45 | P_ECB pecb2; |
ericebert | 0:57690853989a | 46 | #endif |
ericebert | 0:57690853989a | 47 | i=0; |
ericebert | 0:57690853989a | 48 | pecb1 = &EventTbl[0]; /* Get first item */ |
ericebert | 0:57690853989a | 49 | #if CFG_MAX_EVENT == 1 /* Build event list for only one item */ |
ericebert | 0:57690853989a | 50 | pecb1->eventPtr = 0; |
ericebert | 0:57690853989a | 51 | pecb1->id = i; /* Assign ID. */ |
ericebert | 0:57690853989a | 52 | pecb1->eventType = EVENT_TYPE_INVALID; /* Sign that not to use. */ |
ericebert | 0:57690853989a | 53 | #endif |
ericebert | 0:57690853989a | 54 | |
ericebert | 0:57690853989a | 55 | #if CFG_MAX_EVENT > 1 /* Build event list for more than one item */ |
ericebert | 0:57690853989a | 56 | pecb2 = &EventTbl[1]; |
ericebert | 0:57690853989a | 57 | for(;i< (CFG_MAX_EVENT-1);i++ ) |
ericebert | 0:57690853989a | 58 | { |
ericebert | 0:57690853989a | 59 | pecb1->eventPtr = (void*)pecb2; /* Set link for list */ |
ericebert | 0:57690853989a | 60 | pecb1->id = i; /* Assign ID. */ |
ericebert | 0:57690853989a | 61 | pecb1->eventType = EVENT_TYPE_INVALID;/* Sign that not to use. */ |
ericebert | 0:57690853989a | 62 | pecb1++; /* Get next item */ |
ericebert | 0:57690853989a | 63 | pecb2++; |
ericebert | 0:57690853989a | 64 | } |
ericebert | 0:57690853989a | 65 | pecb1->eventType = EVENT_TYPE_INVALID; /* Sign that not to use. */ |
ericebert | 0:57690853989a | 66 | pecb1->eventPtr = 0; /* Set link for last item */ |
ericebert | 0:57690853989a | 67 | pecb1->id = i; |
ericebert | 0:57690853989a | 68 | #endif |
ericebert | 0:57690853989a | 69 | |
ericebert | 0:57690853989a | 70 | FreeEventList = &EventTbl[0]; /* Set free event item */ |
ericebert | 0:57690853989a | 71 | } |
ericebert | 0:57690853989a | 72 | |
ericebert | 0:57690853989a | 73 | |
ericebert | 0:57690853989a | 74 | |
ericebert | 0:57690853989a | 75 | /** |
ericebert | 0:57690853989a | 76 | ******************************************************************************* |
ericebert | 0:57690853989a | 77 | * @brief Release a ECB |
ericebert | 0:57690853989a | 78 | * @param[in] pecb A pointer to event control block which be released. |
ericebert | 0:57690853989a | 79 | * @param[out] None |
ericebert | 0:57690853989a | 80 | * @retval None |
ericebert | 0:57690853989a | 81 | * |
ericebert | 0:57690853989a | 82 | * @par Description |
ericebert | 0:57690853989a | 83 | * @details This function is called to release a event control block when a |
ericebert | 0:57690853989a | 84 | * event be deleted. |
ericebert | 0:57690853989a | 85 | ******************************************************************************* |
ericebert | 0:57690853989a | 86 | */ |
ericebert | 0:57690853989a | 87 | static void ReleaseECB(P_ECB pecb) |
ericebert | 0:57690853989a | 88 | { |
ericebert | 0:57690853989a | 89 | pecb->eventType = EVENT_TYPE_INVALID; /* Sign that not to use. */ |
ericebert | 0:57690853989a | 90 | OsSchedLock(); /* Lock schedule */ |
ericebert | 0:57690853989a | 91 | pecb->eventPtr = FreeEventList; /* Release ECB that event hold */ |
ericebert | 0:57690853989a | 92 | FreeEventList = pecb; /* Reset free event item */ |
ericebert | 0:57690853989a | 93 | OsSchedUnlock(); /* Unlock schedule */ |
ericebert | 0:57690853989a | 94 | } |
ericebert | 0:57690853989a | 95 | |
ericebert | 0:57690853989a | 96 | |
ericebert | 0:57690853989a | 97 | |
ericebert | 0:57690853989a | 98 | /** |
ericebert | 0:57690853989a | 99 | ******************************************************************************* |
ericebert | 0:57690853989a | 100 | * @brief Create a event |
ericebert | 0:57690853989a | 101 | * @param[in] eventType The type of event which being created. |
ericebert | 0:57690853989a | 102 | * @param[in] eventSortType Event sort type. |
ericebert | 0:57690853989a | 103 | * @param[in] eventCounter Event counter,ONLY for EVENT_TYPE_SEM. |
ericebert | 0:57690853989a | 104 | * @param[in] eventPtr Event struct pointer,ONLY for Queue.0 for other |
ericebert | 0:57690853989a | 105 | * event type. |
ericebert | 0:57690853989a | 106 | * @param[out] None |
ericebert | 0:57690853989a | 107 | * @retval 0 Invalid pointer,create event fail. |
ericebert | 0:57690853989a | 108 | * @retval others Pointer to event control block which had assigned right now. |
ericebert | 0:57690853989a | 109 | * |
ericebert | 0:57690853989a | 110 | * @par Description |
ericebert | 0:57690853989a | 111 | * @details This function is called by CreateSem(),... |
ericebert | 0:57690853989a | 112 | * to get a event control block and initial the event content. |
ericebert | 0:57690853989a | 113 | * |
ericebert | 0:57690853989a | 114 | * @note This is a internal function of CooCox CoOS,User can't call. |
ericebert | 0:57690853989a | 115 | ******************************************************************************* |
ericebert | 0:57690853989a | 116 | */ |
ericebert | 0:57690853989a | 117 | P_ECB CreatEvent(U8 eventType,U8 eventSortType,void* eventPtr) |
ericebert | 0:57690853989a | 118 | { |
ericebert | 0:57690853989a | 119 | P_ECB pecb; |
ericebert | 0:57690853989a | 120 | |
ericebert | 0:57690853989a | 121 | OsSchedLock(); /* Lock schedule */ |
ericebert | 0:57690853989a | 122 | if(FreeEventList == 0) /* Is there no free evnet item */ |
ericebert | 0:57690853989a | 123 | { |
ericebert | 0:57690853989a | 124 | OsSchedUnlock(); /* Yes,unlock schedule */ |
ericebert | 0:57690853989a | 125 | return 0; /* Return error */ |
ericebert | 0:57690853989a | 126 | } |
ericebert | 0:57690853989a | 127 | pecb = FreeEventList;/* Assign the free event item to this event */ |
ericebert | 0:57690853989a | 128 | FreeEventList = (P_ECB)FreeEventList->eventPtr; /* Reset free event item */ |
ericebert | 0:57690853989a | 129 | OsSchedUnlock(); /* Unlock schedul */ |
ericebert | 0:57690853989a | 130 | |
ericebert | 0:57690853989a | 131 | pecb->eventType = eventType; /* Initialize event item as user set */ |
ericebert | 0:57690853989a | 132 | pecb->eventSortType = eventSortType; |
ericebert | 0:57690853989a | 133 | pecb->eventPtr = eventPtr; |
ericebert | 0:57690853989a | 134 | pecb->eventTCBList = 0; |
ericebert | 0:57690853989a | 135 | return pecb; /* Return event item pointer */ |
ericebert | 0:57690853989a | 136 | } |
ericebert | 0:57690853989a | 137 | |
ericebert | 0:57690853989a | 138 | |
ericebert | 0:57690853989a | 139 | /** |
ericebert | 0:57690853989a | 140 | ******************************************************************************* |
ericebert | 0:57690853989a | 141 | * @brief Delete a event |
ericebert | 0:57690853989a | 142 | * @param[in] pecb Pointer to event control block which will be deleted. |
ericebert | 0:57690853989a | 143 | * @param[in] opt Delete option. |
ericebert | 0:57690853989a | 144 | * @arg == OPT_DEL_ANYWAY Delete event always |
ericebert | 0:57690853989a | 145 | * @arg == OPT_DEL_NO_PEND Delete event only when no task pending on. |
ericebert | 0:57690853989a | 146 | * @param[out] None |
ericebert | 0:57690853989a | 147 | * @retval E_INVALID_PARAMETER Parameter passed is invalid,deleted fail. |
ericebert | 0:57690853989a | 148 | * @retval E_TASK_WAITTING These are one more tasks waitting event. |
ericebert | 0:57690853989a | 149 | * @retval E_OK Delete event control block successful. |
ericebert | 0:57690853989a | 150 | * |
ericebert | 0:57690853989a | 151 | * @par Description |
ericebert | 0:57690853989a | 152 | * @details This function is called to delete a event from the event wait list |
ericebert | 0:57690853989a | 153 | * use specify option. |
ericebert | 0:57690853989a | 154 | * |
ericebert | 0:57690853989a | 155 | * @note This is a internal function of Coocox CoOS,user can't call. |
ericebert | 0:57690853989a | 156 | ******************************************************************************* |
ericebert | 0:57690853989a | 157 | */ |
ericebert | 0:57690853989a | 158 | StatusType DeleteEvent(P_ECB pecb,U8 opt) |
ericebert | 0:57690853989a | 159 | { |
ericebert | 0:57690853989a | 160 | P_OSTCB ptcb; |
ericebert | 0:57690853989a | 161 | if(opt == OPT_DEL_NO_PEND) /* Do delete event when no task pend? */ |
ericebert | 0:57690853989a | 162 | { |
ericebert | 0:57690853989a | 163 | if(pecb->eventTCBList != 0) /* Yes,is there task pend this event? */ |
ericebert | 0:57690853989a | 164 | { |
ericebert | 0:57690853989a | 165 | return E_TASK_WAITING; /* Yes,error return */ |
ericebert | 0:57690853989a | 166 | } |
ericebert | 0:57690853989a | 167 | else |
ericebert | 0:57690853989a | 168 | { |
ericebert | 0:57690853989a | 169 | ReleaseECB(pecb); /* No,release resource that event hold*/ |
ericebert | 0:57690853989a | 170 | } |
ericebert | 0:57690853989a | 171 | } |
ericebert | 0:57690853989a | 172 | else if(opt == OPT_DEL_ANYWAY) /* Do delete event anyway? */ |
ericebert | 0:57690853989a | 173 | { |
ericebert | 0:57690853989a | 174 | OsSchedLock(); /* Lock schedule */ |
ericebert | 0:57690853989a | 175 | while(pecb->eventTCBList != 0) /* Is there task pend this event? */ |
ericebert | 0:57690853989a | 176 | { /* Yes,remove it */ |
ericebert | 0:57690853989a | 177 | ptcb = pecb->eventTCBList;/* Get first task in event waiting list */ |
ericebert | 0:57690853989a | 178 | if(ptcb->delayTick != INVALID_VALUE) /* Is task in delay list? */ |
ericebert | 0:57690853989a | 179 | { |
ericebert | 0:57690853989a | 180 | RemoveDelayList(ptcb); /* Yes,remove task from delay list */ |
ericebert | 0:57690853989a | 181 | } |
ericebert | 0:57690853989a | 182 | |
ericebert | 0:57690853989a | 183 | /* Set next item as event waiting list head */ |
ericebert | 0:57690853989a | 184 | pecb->eventTCBList = ptcb->waitNext; |
ericebert | 0:57690853989a | 185 | ptcb->waitNext = 0; /* Clear link for event waiting list */ |
ericebert | 0:57690853989a | 186 | ptcb->eventID = INVALID_ID; /* Sign that not to use. */ |
ericebert | 0:57690853989a | 187 | |
ericebert | 0:57690853989a | 188 | InsertToTCBRdyList(ptcb); /* Insert task into ready list */ |
ericebert | 0:57690853989a | 189 | } |
ericebert | 0:57690853989a | 190 | OsSchedUnlock(); /* Unlock schedule */ |
ericebert | 0:57690853989a | 191 | ReleaseECB(pecb); /* Release resource that event hold */ |
ericebert | 0:57690853989a | 192 | } |
ericebert | 0:57690853989a | 193 | return E_OK; /* Return OK */ |
ericebert | 0:57690853989a | 194 | } |
ericebert | 0:57690853989a | 195 | |
ericebert | 0:57690853989a | 196 | |
ericebert | 0:57690853989a | 197 | /** |
ericebert | 0:57690853989a | 198 | ******************************************************************************* |
ericebert | 0:57690853989a | 199 | * @brief Insert a task to event wait list |
ericebert | 0:57690853989a | 200 | * @param[in] pecb Pointer to event control block corresponding to the event. |
ericebert | 0:57690853989a | 201 | * @param[in] ptcb Pointer to task that will be insert to event wait list. |
ericebert | 0:57690853989a | 202 | * @param[out] None |
ericebert | 0:57690853989a | 203 | * @retval None |
ericebert | 0:57690853989a | 204 | * |
ericebert | 0:57690853989a | 205 | * @par Description |
ericebert | 0:57690853989a | 206 | * @details This function is called to insert a task by fllowing manner: |
ericebert | 0:57690853989a | 207 | * opt == EVENT_SORT_TYPE_FIFO By FIFO. |
ericebert | 0:57690853989a | 208 | * opt == EVENT_SORT_TYPE_PRIO By priority order,hghest priority |
ericebert | 0:57690853989a | 209 | * as head,lowest priority as end. |
ericebert | 0:57690853989a | 210 | * (Highest-->...-->Lowest-->0) |
ericebert | 0:57690853989a | 211 | ******************************************************************************* |
ericebert | 0:57690853989a | 212 | */ |
ericebert | 0:57690853989a | 213 | void EventTaskToWait(P_ECB pecb,P_OSTCB ptcb) |
ericebert | 0:57690853989a | 214 | { |
ericebert | 0:57690853989a | 215 | P_OSTCB ptcb1; |
ericebert | 0:57690853989a | 216 | #if (CFG_EVENT_SORT == 2) || (CFG_EVENT_SORT == 3) |
ericebert | 0:57690853989a | 217 | P_OSTCB ptcb2; |
ericebert | 0:57690853989a | 218 | #endif |
ericebert | 0:57690853989a | 219 | |
ericebert | 0:57690853989a | 220 | OsSchedLock(); /* Lock schedule */ |
ericebert | 0:57690853989a | 221 | ptcb1 = pecb->eventTCBList; /* Get first task in event waiting list */ |
ericebert | 0:57690853989a | 222 | ptcb->eventID = pecb->id; /* Set event ID for task */ |
ericebert | 0:57690853989a | 223 | |
ericebert | 0:57690853989a | 224 | #if CFG_EVENT_SORT == 3 /* Does event waiting list sort as FIFO? */ |
ericebert | 0:57690853989a | 225 | |
ericebert | 0:57690853989a | 226 | if(pecb->eventSortType == EVENT_SORT_TYPE_FIFO) |
ericebert | 0:57690853989a | 227 | #endif |
ericebert | 0:57690853989a | 228 | |
ericebert | 0:57690853989a | 229 | #if (CFG_EVENT_SORT == 1) || (CFG_EVENT_SORT == 3) |
ericebert | 0:57690853989a | 230 | { |
ericebert | 0:57690853989a | 231 | if(ptcb1 == 0) /* Is no item in event waiting list?*/ |
ericebert | 0:57690853989a | 232 | { |
ericebert | 0:57690853989a | 233 | pecb->eventTCBList = ptcb; /* Yes,set task as first item */ |
ericebert | 0:57690853989a | 234 | } |
ericebert | 0:57690853989a | 235 | else |
ericebert | 0:57690853989a | 236 | { |
ericebert | 0:57690853989a | 237 | while(ptcb1->waitNext != 0)/* No,insert task in last */ |
ericebert | 0:57690853989a | 238 | { |
ericebert | 0:57690853989a | 239 | ptcb1 = ptcb1->waitNext; |
ericebert | 0:57690853989a | 240 | } |
ericebert | 0:57690853989a | 241 | ptcb1->waitNext = ptcb; /* Set link for list */ |
ericebert | 0:57690853989a | 242 | ptcb->waitPrev = ptcb1; |
ericebert | 0:57690853989a | 243 | } |
ericebert | 0:57690853989a | 244 | } |
ericebert | 0:57690853989a | 245 | #endif |
ericebert | 0:57690853989a | 246 | |
ericebert | 0:57690853989a | 247 | #if CFG_EVENT_SORT ==3 /* Does event waiting list sort as preemptive priority?*/ |
ericebert | 0:57690853989a | 248 | else if(pecb->eventSortType == EVENT_SORT_TYPE_PRIO) |
ericebert | 0:57690853989a | 249 | #endif |
ericebert | 0:57690853989a | 250 | #if (CFG_EVENT_SORT == 2) || (CFG_EVENT_SORT == 3) |
ericebert | 0:57690853989a | 251 | { |
ericebert | 0:57690853989a | 252 | if(ptcb1 == 0) /* Is no item in event waiting list? */ |
ericebert | 0:57690853989a | 253 | { |
ericebert | 0:57690853989a | 254 | pecb->eventTCBList = ptcb; /* Yes,set task as first item */ |
ericebert | 0:57690853989a | 255 | } |
ericebert | 0:57690853989a | 256 | /* Is PRI of task higher than list first item? */ |
ericebert | 0:57690853989a | 257 | else if(ptcb1->prio > ptcb->prio) |
ericebert | 0:57690853989a | 258 | { |
ericebert | 0:57690853989a | 259 | pecb->eventTCBList = ptcb; /* Reset task as first item */ |
ericebert | 0:57690853989a | 260 | ptcb->waitNext = ptcb1; /* Set link for list */ |
ericebert | 0:57690853989a | 261 | ptcb1->waitPrev = ptcb; |
ericebert | 0:57690853989a | 262 | } |
ericebert | 0:57690853989a | 263 | else /* No,find correct place to insert */ |
ericebert | 0:57690853989a | 264 | { |
ericebert | 0:57690853989a | 265 | ptcb2 = ptcb1->waitNext; |
ericebert | 0:57690853989a | 266 | while(ptcb2 != 0) /* Is last item? */ |
ericebert | 0:57690853989a | 267 | { |
ericebert | 0:57690853989a | 268 | if(ptcb2->prio > ptcb->prio) /* No,is correct place? */ |
ericebert | 0:57690853989a | 269 | { |
ericebert | 0:57690853989a | 270 | break; /* Yes,break Circulation */ |
ericebert | 0:57690853989a | 271 | } |
ericebert | 0:57690853989a | 272 | ptcb1 = ptcb2; /* Save current item */ |
ericebert | 0:57690853989a | 273 | ptcb2 = ptcb2->waitNext; /* Get next item */ |
ericebert | 0:57690853989a | 274 | } |
ericebert | 0:57690853989a | 275 | ptcb1->waitNext = ptcb; /* Set link for list */ |
ericebert | 0:57690853989a | 276 | ptcb->waitPrev = ptcb1; |
ericebert | 0:57690853989a | 277 | ptcb->waitNext = ptcb2; |
ericebert | 0:57690853989a | 278 | if(ptcb2 != 0) |
ericebert | 0:57690853989a | 279 | { |
ericebert | 0:57690853989a | 280 | ptcb2->waitPrev = ptcb; |
ericebert | 0:57690853989a | 281 | } |
ericebert | 0:57690853989a | 282 | } |
ericebert | 0:57690853989a | 283 | } |
ericebert | 0:57690853989a | 284 | #endif |
ericebert | 0:57690853989a | 285 | ptcb->state = TASK_WAITING; /* Set task status to TASK_WAITING state */ |
ericebert | 0:57690853989a | 286 | TaskSchedReq = TRUE; |
ericebert | 0:57690853989a | 287 | OsSchedUnlock(); /* Unlock schedule,and call task schedule */ |
ericebert | 0:57690853989a | 288 | } |
ericebert | 0:57690853989a | 289 | |
ericebert | 0:57690853989a | 290 | |
ericebert | 0:57690853989a | 291 | /** |
ericebert | 0:57690853989a | 292 | ******************************************************************************* |
ericebert | 0:57690853989a | 293 | * @brief Move a task from event WAITING list to the DELAY list |
ericebert | 0:57690853989a | 294 | * @param[in] pecb Pointer to event control block corresponding to the event. |
ericebert | 0:57690853989a | 295 | * @param[out] None |
ericebert | 0:57690853989a | 296 | * @retval None |
ericebert | 0:57690853989a | 297 | * |
ericebert | 0:57690853989a | 298 | * @par Description |
ericebert | 0:57690853989a | 299 | * @details This function is called to remove a task from event wait list,and |
ericebert | 0:57690853989a | 300 | * then insert it into the READY list. |
ericebert | 0:57690853989a | 301 | ******************************************************************************* |
ericebert | 0:57690853989a | 302 | */ |
ericebert | 0:57690853989a | 303 | void EventTaskToRdy(P_ECB pecb) |
ericebert | 0:57690853989a | 304 | { |
ericebert | 0:57690853989a | 305 | P_OSTCB ptcb; |
ericebert | 0:57690853989a | 306 | #if CFG_QUEUE_EN >0 |
ericebert | 0:57690853989a | 307 | P_QCB pqcb; |
ericebert | 0:57690853989a | 308 | #endif |
ericebert | 0:57690853989a | 309 | ptcb = pecb->eventTCBList; |
ericebert | 0:57690853989a | 310 | if(ptcb == 0) |
ericebert | 0:57690853989a | 311 | return; |
ericebert | 0:57690853989a | 312 | |
ericebert | 0:57690853989a | 313 | pecb->eventTCBList = ptcb->waitNext;/* Get first task in event waiting list*/ |
ericebert | 0:57690853989a | 314 | if(pecb->eventTCBList != 0) /* Is no item in event waiting list? */ |
ericebert | 0:57690853989a | 315 | { |
ericebert | 0:57690853989a | 316 | pecb->eventTCBList->waitPrev = 0; /* No,clear link for first item */ |
ericebert | 0:57690853989a | 317 | } |
ericebert | 0:57690853989a | 318 | |
ericebert | 0:57690853989a | 319 | ptcb->waitNext = 0; /* Clear event waiting link for task*/ |
ericebert | 0:57690853989a | 320 | ptcb->eventID = INVALID_ID; /* Sign that not to use. */ |
ericebert | 0:57690853989a | 321 | |
ericebert | 0:57690853989a | 322 | if(ptcb->delayTick != INVALID_VALUE) /* Is task in delay list? */ |
ericebert | 0:57690853989a | 323 | { |
ericebert | 0:57690853989a | 324 | RemoveDelayList(ptcb); /* Yes,remove task from DELAY list */ |
ericebert | 0:57690853989a | 325 | } |
ericebert | 0:57690853989a | 326 | if(pecb->eventType == EVENT_TYPE_MBOX)/* Is it a mailbox event? */ |
ericebert | 0:57690853989a | 327 | { |
ericebert | 0:57690853989a | 328 | ptcb->pmail = pecb->eventPtr; /* Yes,send mail to task */ |
ericebert | 0:57690853989a | 329 | pecb->eventPtr = 0; /* Clear event sign */ |
ericebert | 0:57690853989a | 330 | pecb->eventCounter--; |
ericebert | 0:57690853989a | 331 | } |
ericebert | 0:57690853989a | 332 | #if CFG_QUEUE_EN >0 |
ericebert | 0:57690853989a | 333 | else if(pecb->eventType == EVENT_TYPE_QUEUE) /* Is it a queue event? */ |
ericebert | 0:57690853989a | 334 | { |
ericebert | 0:57690853989a | 335 | pqcb = (P_QCB)pecb->eventPtr; /* Yes,get queue pointer */ |
ericebert | 0:57690853989a | 336 | ptcb->pmail = *(pqcb->qStart + pqcb->head); /* Send mail to task */ |
ericebert | 0:57690853989a | 337 | pqcb->head++; /* Clear event sign */ |
ericebert | 0:57690853989a | 338 | pqcb->qSize--; |
ericebert | 0:57690853989a | 339 | if(pqcb->head == pqcb->qMaxSize) |
ericebert | 0:57690853989a | 340 | { |
ericebert | 0:57690853989a | 341 | pqcb->head = 0; |
ericebert | 0:57690853989a | 342 | } |
ericebert | 0:57690853989a | 343 | } |
ericebert | 0:57690853989a | 344 | #endif |
ericebert | 0:57690853989a | 345 | |
ericebert | 0:57690853989a | 346 | #if CFG_MAILBOX_EN >0 |
ericebert | 0:57690853989a | 347 | else if(pecb->eventType == EVENT_TYPE_SEM)/* Is it a semaphore event? */ |
ericebert | 0:57690853989a | 348 | { |
ericebert | 0:57690853989a | 349 | pecb->eventCounter--; /* Yes,clear event sign */ |
ericebert | 0:57690853989a | 350 | ptcb->pmail = (void*)0xffffffff; /* Indicate task woke by event */ |
ericebert | 0:57690853989a | 351 | } |
ericebert | 0:57690853989a | 352 | #endif |
ericebert | 0:57690853989a | 353 | if(ptcb == TCBRunning) |
ericebert | 0:57690853989a | 354 | { |
ericebert | 0:57690853989a | 355 | ptcb->state = TASK_RUNNING; |
ericebert | 0:57690853989a | 356 | } |
ericebert | 0:57690853989a | 357 | else |
ericebert | 0:57690853989a | 358 | { |
ericebert | 0:57690853989a | 359 | InsertToTCBRdyList(ptcb); /* Insert task into ready list */ |
ericebert | 0:57690853989a | 360 | } |
ericebert | 0:57690853989a | 361 | } |
ericebert | 0:57690853989a | 362 | |
ericebert | 0:57690853989a | 363 | |
ericebert | 0:57690853989a | 364 | |
ericebert | 0:57690853989a | 365 | /** |
ericebert | 0:57690853989a | 366 | ******************************************************************************* |
ericebert | 0:57690853989a | 367 | * @brief Move a task from event wait list to the ready list |
ericebert | 0:57690853989a | 368 | * @param[in] pecb Pointer to event control block corresponding to the event. |
ericebert | 0:57690853989a | 369 | * @param[out] None |
ericebert | 0:57690853989a | 370 | * @retval None |
ericebert | 0:57690853989a | 371 | * |
ericebert | 0:57690853989a | 372 | * @par Description |
ericebert | 0:57690853989a | 373 | * @details This function is called to remove a task from event wait list,and |
ericebert | 0:57690853989a | 374 | * then insert it to the ready list. |
ericebert | 0:57690853989a | 375 | ******************************************************************************* |
ericebert | 0:57690853989a | 376 | */ |
ericebert | 0:57690853989a | 377 | void RemoveEventWaittingList(P_OSTCB ptcb) |
ericebert | 0:57690853989a | 378 | { |
ericebert | 0:57690853989a | 379 | P_ECB pecb; |
ericebert | 0:57690853989a | 380 | pecb = &EventTbl[ptcb->eventID]; /* Get event control block */ |
ericebert | 0:57690853989a | 381 | |
ericebert | 0:57690853989a | 382 | /* Is there only one item in event waiting list? */ |
ericebert | 0:57690853989a | 383 | if((ptcb->waitNext == 0) && (ptcb->waitPrev == 0)) |
ericebert | 0:57690853989a | 384 | { |
ericebert | 0:57690853989a | 385 | pecb->eventTCBList = 0; /* Yes,set event waiting list as 0 */ |
ericebert | 0:57690853989a | 386 | } |
ericebert | 0:57690853989a | 387 | else if(ptcb->waitPrev == 0)/* Is the first item in event waiting list?*/ |
ericebert | 0:57690853989a | 388 | { |
ericebert | 0:57690853989a | 389 | /* Yes,remove task from list,and reset event waiting list */ |
ericebert | 0:57690853989a | 390 | ptcb->waitNext->waitPrev = 0; |
ericebert | 0:57690853989a | 391 | pecb->eventTCBList = ptcb->waitNext; |
ericebert | 0:57690853989a | 392 | ptcb->waitNext = 0; |
ericebert | 0:57690853989a | 393 | } |
ericebert | 0:57690853989a | 394 | else if(ptcb->waitNext == 0)/* Is the last item in event waiting list? */ |
ericebert | 0:57690853989a | 395 | { |
ericebert | 0:57690853989a | 396 | ptcb->waitPrev->waitNext = 0; /* Yes,remove task form list */ |
ericebert | 0:57690853989a | 397 | ptcb->waitPrev = 0; |
ericebert | 0:57690853989a | 398 | } |
ericebert | 0:57690853989a | 399 | else /* No, remove task from list */ |
ericebert | 0:57690853989a | 400 | { |
ericebert | 0:57690853989a | 401 | ptcb->waitPrev->waitNext = ptcb->waitNext; |
ericebert | 0:57690853989a | 402 | ptcb->waitNext->waitPrev = ptcb->waitPrev; |
ericebert | 0:57690853989a | 403 | ptcb->waitPrev = 0; |
ericebert | 0:57690853989a | 404 | ptcb->waitNext = 0; |
ericebert | 0:57690853989a | 405 | } |
ericebert | 0:57690853989a | 406 | ptcb->eventID = INVALID_ID; /* Sign that not to use. */ |
ericebert | 0:57690853989a | 407 | } |
ericebert | 0:57690853989a | 408 | |
ericebert | 0:57690853989a | 409 | #endif //CFG_EVENT_EN |
ericebert | 0:57690853989a | 410 |