📄 os_task.lst
字号:
return (OS_TASK_DEL_IDLE);
}
if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
return (OS_PRIO_INVALID);
}
#endif
OS_ENTER_CRITICAL();
if (prio == OS_PRIO_SELF) { /* See if requesting to delete self */
prio = OSTCBCur->OSTCBPrio; /* Set priority to delete to current */
}
if ((ptcb = OSTCBPrioTbl[prio]) != (OS_TCB *)0) { /* Task to delete must exist */
if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) { /* Make task not ready */
OSRdyGrp &= ~ptcb->OSTCBBitY;
}
#if OS_EVENT_EN > 0
pevent = ptcb->OSTCBEventPtr;
if (pevent != (OS_EVENT *)0) { /* If task is waiting on event */
if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) { /* ... remove task from */
pevent->OSEventGrp &= ~ptcb->OSTCBBitY; /* ... event ctrl block */
}
}
#endif
#if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
pnode = ptcb->OSTCBFlagNode;
if (pnode != (OS_FLAG_NODE *)0) { /* If task is waiting on event flag */
OS_FlagUnlink(pnode); /* Remove from wait list */
}
#endif
ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from updating */
ptcb->OSTCBStat = OS_STAT_RDY; /* Prevent task from being resumed */
if (OSLockNesting < 255) {
OSLockNesting++;
}
OS_EXIT_CRITICAL(); /* Enabling INT. ignores next instruc. */
OS_Dummy(); /* ... Dummy ensures that INTs will be */
OS_ENTER_CRITICAL(); /* ... disabled HERE! */
if (OSLockNesting > 0) {
OSLockNesting--;
}
OSTaskDelHook(ptcb); /* Call user defined hook */
OSTaskCtr--; /* One less task being managed */
OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Clear old priority entry */
if (ptcb->OSTCBPrev == (OS_TCB *)0) { /* Remove from TCB chain */
ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
OSTCBList = ptcb->OSTCBNext;
} else {
ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
}
ptcb->OSTCBNext = OSTCBFreeList; /* Return TCB to free TCB list */
C51 COMPILER V7.02b OS_TASK 11/29/2006 14:48:15 PAGE 8
OSTCBFreeList = ptcb;
OS_EXIT_CRITICAL();
OS_Sched(); /* Find new highest priority task */
return (OS_NO_ERR);
}
OS_EXIT_CRITICAL();
return (OS_TASK_DEL_ERR);
}
#endif
435 /*$PAGE*/
436 /*
437 *********************************************************************************************************
438 * REQUEST THAT A TASK DELETE ITSELF
439 *
440 * Description: This function is used to:
441 * a) notify a task to delete itself.
442 * b) to see if a task requested that the current task delete itself.
443 * This function is a little tricky to understand. Basically, you have a task that needs
444 * to be deleted however, this task has resources that it has allocated (memory buffers,
445 * semaphores, mailboxes, queues etc.). The task cannot be deleted otherwise these
446 * resources would not be freed. The requesting task calls OSTaskDelReq() to indicate that
447 * the task needs to be deleted. Deleting of the task is however, deferred to the task to
448 * be deleted. For example, suppose that task #10 needs to be deleted. The requesting task
449 * example, task #5, would call OSTaskDelReq(10). When task #10 gets to execute, it calls
450 * this function by specifying OS_PRIO_SELF and monitors the returned value. If the return
451 * value is OS_TASK_DEL_REQ, another task requested a task delete. Task #10 would look like
452 * this:
453 *
454 * void Task(void *data)
455 * {
456 * .
457 * .
458 * while (1) {
459 * OSTimeDly(1);
460 * if (OSTaskDelReq(OS_PRIO_SELF) == OS_TASK_DEL_REQ) {
461 * Release any owned resources;
462 * De-allocate any dynamic memory;
463 * OSTaskDel(OS_PRIO_SELF);
464 * }
465 * }
466 * }
467 *
468 * Arguments : prio is the priority of the task to request the delete from
469 *
470 * Returns : OS_NO_ERR if the task exist and the request has been registered
471 * OS_TASK_NOT_EXIST if the task has been deleted. This allows the caller to know whether
472 * the request has been executed.
473 * OS_TASK_DEL_IDLE if you requested to delete uC/OS-II's idle task
474 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
475 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
476 * OS_TASK_DEL_REQ if a task (possibly another task) requested that the running task be
477 * deleted.
478 *********************************************************************************************************
479 */
480 /*$PAGE*/
481 #if OS_TASK_DEL_EN > 0
INT8U OSTaskDelReq (INT8U prio) reentrant
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
BOOLEAN stat;
C51 COMPILER V7.02b OS_TASK 11/29/2006 14:48:15 PAGE 9
INT8U err;
OS_TCB *ptcb;
#if OS_ARG_CHK_EN > 0
if (prio == OS_IDLE_PRIO) { /* Not allowed to delete idle task */
return (OS_TASK_DEL_IDLE);
}
if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
return (OS_PRIO_INVALID);
}
#endif
if (prio == OS_PRIO_SELF) { /* See if a task is requesting to ... */
OS_ENTER_CRITICAL(); /* ... this task to delete itself */
stat = OSTCBCur->OSTCBDelReq; /* Return request status to caller */
OS_EXIT_CRITICAL();
return (stat);
}
OS_ENTER_CRITICAL();
if ((ptcb = OSTCBPrioTbl[prio]) != (OS_TCB *)0) { /* Task to delete must exist */
ptcb->OSTCBDelReq = OS_TASK_DEL_REQ; /* Set flag indicating task to be DEL. */
err = OS_NO_ERR;
} else {
err = OS_TASK_NOT_EXIST; /* Task must be deleted */
}
OS_EXIT_CRITICAL();
return (err);
}
#endif
517 /*$PAGE*/
518 /*
519 *********************************************************************************************************
520 * RESUME A SUSPENDED TASK
521 *
522 * Description: This function is called to resume a previously suspended task. This is the only call that
523 * will remove an explicit task suspension.
524 *
525 * Arguments : prio is the priority of the task to resume.
526 *
527 * Returns : OS_NO_ERR if the requested task is resumed
528 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
529 * (i.e. >= OS_LOWEST_PRIO)
530 * OS_TASK_RESUME_PRIO if the task to resume does not exist
531 * OS_TASK_NOT_SUSPENDED if the task to resume has not been suspended
532 *********************************************************************************************************
533 */
534
535 #if OS_TASK_SUSPEND_EN > 0
INT8U OSTaskResume (INT8U prio) reentrant
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OS_TCB *ptcb;
#if OS_ARG_CHK_EN > 0
if (prio >= OS_LOWEST_PRIO) { /* Make sure task priority is valid */
return (OS_PRIO_INVALID);
}
#endif
OS_ENTER_CRITICAL();
C51 COMPILER V7.02b OS_TASK 11/29/2006 14:48:15 PAGE 10
if ((ptcb = OSTCBPrioTbl[prio]) == (OS_TCB *)0) { /* Task to suspend must exist */
OS_EXIT_CRITICAL();
return (OS_TASK_RESUME_PRIO);
}
if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != 0x00) { /* Task must be suspended */
if (((ptcb->OSTCBStat &= ~OS_STAT_SUSPEND) == OS_STAT_RDY) && /* Remove suspension */
(ptcb->OSTCBDly == 0)) { /* Must not be delayed */
OSRdyGrp |= ptcb->OSTCBBitY; /* Make task ready to run */
OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
OS_EXIT_CRITICAL();
OS_Sched();
} else {
OS_EXIT_CRITICAL();
}
return (OS_NO_ERR);
}
OS_EXIT_CRITICAL();
return (OS_TASK_NOT_SUSPENDED);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -