📄 os_task.lst
字号:
360 * the next instruction following the enable interrupt instruction is ignored. You can
361 * replace OSDummy() with a macro that basically executes a NO OP (i.e. OS_NOP()). The
362 * NO OP macro would avoid the execution time of the function call and return.
363 * 3) An ISR cannot delete a task.
364 * 4) The lock nesting counter is incremented because, for a brief instant, if the current
365 * task is being deleted, the current task would not be able to be rescheduled because it
366 * is removed from the ready list. Incrementing the nesting counter prevents another task
367 * from being schedule. This means that the ISR would return to the current task which is
368 * being deleted. The rest of the deletion would thus be able to be completed.
369 *********************************************************************************************************
370 */
371 /*$PAGE*/
372 #if OS_TASK_DEL_EN
INT8U OSTaskDel (INT8U prio) REENTRANT
{
OS_TCB DT_XDATA *ptcb;
OS_EVENT DT_XDATA *pevent;
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);
}
OS_ENTER_CRITICAL();
if (OSIntNesting > 0) { /* See if trying to delete from ISR */
OS_EXIT_CRITICAL();
return (OS_TASK_DEL_ISR);
}
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 DT_XDATA *)0) { /* Task to delete must exist
- */
if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {/* Make task not ready */
OSRdyGrp &= ~ptcb->OSTCBBitY;
}
if ((pevent = ptcb->OSTCBEventPtr) != (OS_EVENT DT_XDATA *)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 */
}
}
ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from updating */
ptcb->OSTCBStat = OS_STAT_RDY; /* Prevent task from being resumed */
OSLockNesting++;
OS_EXIT_CRITICAL(); /* Enabling INT. ignores next instruc. */
OSDummy(); /* ... Dummy ensures that INTs will be */
OS_ENTER_CRITICAL(); /* ... disabled HERE! */
OSLockNesting--;
OSTaskDelHook(ptcb); /* Call user defined hook */
C51 COMPILER V7.02a OS_TASK 10/16/2006 15:27:52 PAGE 8
OSTaskCtr--; /* One less task being managed */
OSTCBPrioTbl[prio] = (OS_TCB DT_XDATA *)0; /* Clear old priority entry
- */
if (ptcb->OSTCBPrev == (OS_TCB DT_XDATA *)0) { /* Remove from TCB chain
- */
ptcb->OSTCBNext->OSTCBPrev = (OS_TCB DT_XDATA *)0;
OSTCBList = ptcb->OSTCBNext;
} else {
ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
}
ptcb->OSTCBNext = OSTCBFreeList; /* Return TCB to free TCB list */
OSTCBFreeList = ptcb;
OS_EXIT_CRITICAL();
OSSched(); /* Find new highest priority task */
return (OS_NO_ERR);
} else {
OS_EXIT_CRITICAL();
return (OS_TASK_DEL_ERR);
}
}
#endif
430 /*$PAGE*/
431 /*
432 *********************************************************************************************************
433 * REQUEST THAT A TASK DELETE ITSELF
434 *
435 * Description: This function is used to:
436 * a) notify a task to delete itself.
437 * b) to see if a task requested that the current task delete itself.
438 * This function is a little tricky to understand. Basically, you have a task that needs
439 * to be deleted however, this task has resources that it has allocated (memory buffers,
440 * semaphores, mailboxes, queues etc.). The task cannot be deleted otherwise these
441 * resources would not be freed. The requesting task calls OSTaskDelReq() to indicate that
442 * the task needs to be deleted. Deleting of the task is however, deferred to the task to
443 * be deleted. For example, suppose that task #10 needs to be deleted. The requesting task
444 * example, task #5, would call OSTaskDelReq(10). When task #10 gets to execute, it calls
445 * this function by specifying OS_PRIO_SELF and monitors the returned value. If the return
446 * value is OS_TASK_DEL_REQ, another task requested a task delete. Task #10 would look like
447 * this:
448 *
449 * void Task(void *data)
450 * {
451 * .
452 * .
453 * while (1) {
454 * OSTimeDly(1);
455 * if (OSTaskDelReq(OS_PRIO_SELF) == OS_TASK_DEL_REQ) {
456 * Release any owned resources;
457 * De-allocate any dynamic memory;
458 * OSTaskDel(OS_PRIO_SELF);
459 * }
460 * }
461 * }
462 *
463 * Arguments : prio is the priority of the task to request the delete from
464 *
465 * Returns : OS_NO_ERR if the task exist and the request has been registered
466 * OS_TASK_NOT_EXIST if the task has been deleted. This allows the caller to know whether
467 * the request has been executed.
468 * OS_TASK_DEL_IDLE if you requested to delete uC/OS-II's idle task
469 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
C51 COMPILER V7.02a OS_TASK 10/16/2006 15:27:52 PAGE 9
470 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
471 * OS_TASK_DEL_REQ if a task (possibly another task) requested that the running task be
472 * deleted.
473 *********************************************************************************************************
474 */
475 /*$PAGE*/
476 #if OS_TASK_DEL_EN
INT8U OSTaskDelReq (INT8U prio) REENTRANT
{
BOOLEAN stat;
INT8U err;
OS_TCB DT_XDATA *ptcb;
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);
}
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);
} else {
OS_ENTER_CRITICAL();
if ((ptcb = OSTCBPrioTbl[prio]) != (OS_TCB DT_XDATA *)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
508 /*$PAGE*/
509 /*
510 *********************************************************************************************************
511 * RESUME A SUSPENDED TASK
512 *
513 * Description: This function is called to resume a previously suspended task. This is the only call that
514 * will remove an explicit task suspension.
515 *
516 * Arguments : prio is the priority of the task to resume.
517 *
518 * Returns : OS_NO_ERR if the requested task is resumed
519 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
520 * (i.e. >= OS_LOWEST_PRIO)
521 * OS_TASK_RESUME_PRIO if the task to resume does not exist
522 * OS_TASK_NOT_SUSPENDED if the task to resume has not been suspended
523 *********************************************************************************************************
524 */
525
526 #if OS_TASK_SUSPEND_EN
INT8U OSTaskResume (INT8U prio) REENTRANT
{
OS_TCB DT_XDATA *ptcb;
C51 COMPILER V7.02a OS_TASK 10/16/2006 15:27:52 PAGE 10
if (prio >= OS_LOWEST_PRIO) { /* Make sure task priority is valid */
return (OS_PRIO_INVALID);
}
OS_ENTER_CRITICAL();
if ((ptcb = OSTCBPrioTbl[prio]) == (OS_TCB DT_XDATA *)0) { /* Task to suspend must exist
- */
OS_EXIT_CRITICAL();
return (OS_TASK_RESUME_PRIO);
} else {
if (ptcb->OSTCBStat & OS_STAT_SUSPEND) { /* 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();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -