/*
*********************************************************************************************************
* RESUME A DELAYED TASK
*
* Description: This function is used resume a task that has been delayed through a call to either
* OSTimeDly() or OSTimeDlyHMSM(). Note that you can call this function to resume a
* task that is waiting for an event with timeout. This would make the task look
* like a timeout occurred.
*
* Also, you cannot resume a task that has called OSTimeDlyHMSM() with a combined time that
* exceeds 65535 clock ticks. In other words, if the clock tick runs at 100 Hz then, you will
* not be able to resume a delayed task that called OSTimeDlyHMSM(0, 10, 55, 350) or higher:
*
* (10 Minutes * 60 + 55 Seconds + 0.35) * 100 ticks/second.
*
* Arguments : prio specifies the priority of the task to resume
*
* Returns : OS_ERR_NONE Task has been resumed
* OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allowed
* (i.e. >= OS_LOWEST_PRIO)
* OS_ERR_TIME_NOT_DLY Task is not waiting for time to expire
* OS_ERR_TASK_NOT_EXIST The desired task has not been created or has been assigned to a Mutex.
*********************************************************************************************************
*/
#if OS_TIME_DLY_RESUME_EN > 0
INT8U OSTimeDlyResume (INT8U prio)
{
OS_TCB *ptcb;
#if OS_CRITICAL_METHOD == 3 /* Storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
if (prio >= OS_LOWEST_PRIO) {
return (OS_ERR_PRIO_INVALID);
}
OS_ENTER_CRITICAL();
ptcb = OSTCBPrioTbl[prio]; /* Make sure that task exist */
if (ptcb == (OS_TCB *)0) {
OS_EXIT_CRITICAL();
return (OS_ERR_TASK_NOT_EXIST); /* The task does not exist */
}
if (ptcb == OS_TCB_RESERVED) {
OS_EXIT_CRITICAL();
return (OS_ERR_TASK_NOT_EXIST); /* The task does not exist */
}
if (ptcb->OSTCBDly == 0) { /* See if task is delayed */
OS_EXIT_CRITICAL();
return (OS_ERR_TIME_NOT_DLY); /* Indicate that task was not delayed */
}
ptcb->OSTCBDly = 0; /* Clear the time delay */
if ((ptcb->OSTCBStat & OS_STAT_PEND_ANY) != OS_STAT_RDY) {
ptcb->OSTCBStat &= ~OS_STAT_PEND_ANY; /* Yes, Clear status flag */
ptcb->OSTCBStatPend = OS_STAT_PEND_TO; /* Indicate PEND timeout */
} else {
ptcb->OSTCBStatPend = OS_STAT_PEND_OK;
}
if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) { /* Is task suspended? */
OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make ready */
OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
OS_EXIT_CRITICAL();
OS_Sched(); /* See if this is new highest priority */
} else {
OS_EXIT_CRITICAL(); /* Task may be suspended */
}
return (OS_ERR_NONE);
}
#endif
上面的代码前面是有效性判断,后面对prio优先级别的任务TCB的OSTCBDly=0操作,最后如果此 OSTCBPrioTbl[prio]任务没有挂起,则进行一个任务级别的任务切换操作OS_Sched()。