/** ******************************************************************************* * @brief Remove a flag node from list * @param[in] pnode A node that will remove from flag waiting list. * @param[out] None * @retval pnode Next node of the node that have removed out. * * @par Description * @details This function is called to remove a flag node from the wait list. * @note ******************************************************************************* */ static P_FLAG_NODE RemoveFromLink(P_FLAG_NODE pnode) { P_OSTCB ptcb; RemoveLinkNode(pnode); /* Remove the flag node from wait list. */ ptcb = pnode->waitTask; /* The task in the delay list */ if(ptcb->delayTick != INVALID_VALUE)/* If the task is in tick delay list */ { RemoveDelayList(ptcb); /* Remove the task from tick delay list */ } ptcb->pnode = (void*)0xffffffff; if(ptcb == TCBRunning) { ptcb->state = TASK_RUNNING; } else { InsertToTCBRdyList(ptcb); /* Insert the task to ready list */ } return (pnode->nextNode); }
/** ******************************************************************************* * @brief Reset task delay ticks * @param[in] ptcb Task that want to insert into DELAY list. * @param[in] ticks Specify system tick number which will delay . * @param[out] None * @retval E_CALL Error call in ISR. * @retval E_INVALID_ID Invalid task id. * @retval E_NOT_IN_DELAY_LIST Task not in delay list. * @retval E_OK The current task was inserted to DELAY list * successful,it will delay for specify time. * @par Description * @details This function delay specify ticks for current task. ******************************************************************************* */ StatusType CoResetTaskDelayTick(OS_TID taskID,U32 ticks) { P_OSTCB ptcb; #if CFG_PAR_CHECKOUT_EN >0 /* Check validity of parameter */ if(taskID >= CFG_MAX_USER_TASKS + SYS_TASK_NUM) { return E_INVALID_ID; } #endif ptcb = &TCBTbl[taskID]; #if CFG_PAR_CHECKOUT_EN >0 if(ptcb->stkPtr == Co_NULL) { return E_INVALID_ID; } #endif if(ptcb->delayTick == INVALID_VALUE) { /* Is tick==INVALID_VALUE? */ return E_NOT_IN_DELAY_LIST; /* Yes,error return */ } OsSchedLock(); /* Lock schedule */ RemoveDelayList(ptcb); /* Remove task from the DELAY list */ if(ticks == 0) { /* Is delay tick==0? */ InsertToTCBRdyList(ptcb); /* Insert task into the DELAY list */ } else { InsertDelayList(ptcb,ticks); /* No,insert task into DELAY list */ } OsSchedUnlock(); /* Unlock schedule,and call task schedule */ return E_OK; /* Return OK */ }
/** ******************************************************************************* * @brief Move a task from event WAITING list to the DELAY list * @param[in] pecb Pointer to event control block corresponding to the event. * @param[out] None * @retval None * * @par Description * @details This function is called to remove a task from event wait list,and * then insert it into the READY list. ******************************************************************************* */ void EventTaskToRdy(P_ECB pecb) { P_OSTCB ptcb; #if CFG_QUEUE_EN >0 P_QCB pqcb; #endif ptcb = pecb->eventTCBList; if(ptcb == NULL) return; pecb->eventTCBList = ptcb->waitNext;/* Get first task in event waiting list*/ if(pecb->eventTCBList != NULL) /* Is no item in event waiting list? */ { pecb->eventTCBList->waitPrev = NULL; /* No,clear link for first item */ } ptcb->waitNext = NULL; /* Clear event waiting link for task*/ ptcb->eventID = INVALID_ID; /* Sign that not to use. */ if(ptcb->delayTick != INVALID_VALUE) /* Is task in delay list? */ { RemoveDelayList(ptcb); /* Yes,remove task from DELAY list */ } if(pecb->eventType == EVENT_TYPE_MBOX)/* Is it a mailbox event? */ { ptcb->pmail = pecb->eventPtr; /* Yes,send mail to task */ pecb->eventPtr = NULL; /* Clear event sign */ pecb->eventCounter--; } #if CFG_QUEUE_EN >0 else if(pecb->eventType == EVENT_TYPE_QUEUE) /* Is it a queue event? */ { pqcb = (P_QCB)pecb->eventPtr; /* Yes,get queue pointer */ ptcb->pmail = *(pqcb->qStart + pqcb->head); /* Send mail to task */ pqcb->head++; /* Clear event sign */ pqcb->qSize--; if(pqcb->head == pqcb->qMaxSize) { pqcb->head = 0; } } #endif #if CFG_MAILBOX_EN >0 else if(pecb->eventType == EVENT_TYPE_SEM)/* Is it a semaphore event? */ { pecb->eventCounter--; /* Yes,clear event sign */ ptcb->pmail = (void*)0xffffffff; /* Indicate task woke by event */ } #endif if(ptcb == TCBRunning) { ptcb->state = TASK_RUNNING; } else { InsertToTCBRdyList(ptcb); /* Insert task into ready list */ } }
/** ******************************************************************************* * @brief Delete a event * @param[in] pecb Pointer to event control block which will be deleted. * @param[in] opt Delete option. * @arg == OPT_DEL_ANYWAY Delete event always * @arg == OPT_DEL_NO_PEND Delete event only when no task pending on. * @param[out] None * @retval E_INVALID_PARAMETER Parameter passed is invalid,deleted fail. * @retval E_TASK_WAITTING These are one more tasks waitting event. * @retval E_OK Delete event control block successful. * * @par Description * @details This function is called to delete a event from the event wait list * use specify option. * * @note This is a internal function of Coocox CoOS,user can't call. ******************************************************************************* */ StatusType DeleteEvent(P_ECB pecb,U8 opt) { P_OSTCB ptcb; if(opt == OPT_DEL_NO_PEND) /* Do delete event when no task pend? */ { if(pecb->eventTCBList != NULL) /* Yes,is there task pend this event? */ { return E_TASK_WAITING; /* Yes,error return */ } else { ReleaseECB(pecb); /* No,release resource that event hold*/ } } else if(opt == OPT_DEL_ANYWAY) /* Do delete event anyway? */ { OsSchedLock(); /* Lock schedule */ while(pecb->eventTCBList != NULL) /* Is there task pend this event? */ { /* Yes,remove it */ ptcb = pecb->eventTCBList;/* Get first task in event waiting list */ if(ptcb->delayTick != INVALID_VALUE) /* Is task in delay list? */ { RemoveDelayList(ptcb); /* Yes,remove task from delay list */ } /* Set next item as event waiting list head */ pecb->eventTCBList = ptcb->waitNext; ptcb->waitNext = NULL; /* Clear link for event waiting list */ ptcb->eventID = INVALID_ID; /* Sign that not to use. */ InsertToTCBRdyList(ptcb); /* Insert task into ready list */ } OsSchedUnlock(); /* Unlock schedule */ ReleaseECB(pecb); /* Release resource that event hold */ } return E_OK; /* Return OK */ }