📄 os_task.lst
字号:
}
#endif
385 1 OS_ENTER_CRITICAL();
386 1 if (prio == OS_PRIO_SELF) { /* See if requesting to delete self */
387 2 prio = OSTCBCur->OSTCBPrio; /* Set priority to delete to current */
388 2 }
389 1 ptcb = OSTCBPrioTbl[prio];
390 1 if (ptcb != (OS_TCB *)0) { /* Task to delete must exist */
391 2 if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) { /* Make task not ready */
392 3 OSRdyGrp &= ~ptcb->OSTCBBitY;
393 3 }
394 2 #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
402 2
403 2 #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
409 2 ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from updating */
410 2 ptcb->OSTCBStat = OS_STAT_RDY; /* Prevent task from being resumed */
411 2 if (OSLockNesting < 255) {
412 3 OSLockNesting++;
413 3 }
414 2 OS_EXIT_CRITICAL(); /* Enabling INT. ignores next instruc. */
415 2 OS_Dummy(); /* ... Dummy ensures that INTs will be */
416 2 OS_ENTER_CRITICAL(); /* ... disabled HERE! */
417 2 if (OSLockNesting > 0) {
418 3 OSLockNesting--;
419 3 }
420 2
421 2 OSTaskDelHook(ptcb); /* Call user defined hook */
422 2 OSTaskCtr--; /* One less task being managed */
423 2 OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Clear old priority entry */
424 2 if (ptcb->OSTCBPrev == (OS_TCB *)0) { /* Remove from TCB chain */
425 3 ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
426 3 OSTCBList = ptcb->OSTCBNext;
C51 COMPILER V9.01 OS_TASK 10/31/2012 17:19:07 PAGE 8
427 3 } else {
428 3 ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
429 3 ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
430 3 }
431 2
432 2 ptcb->OSTCBNext = OSTCBFreeList; /* Return TCB to free TCB list */
433 2 OSTCBFreeList = ptcb; // led=!led;
434 2 OS_EXIT_CRITICAL();
435 2 OS_Sched(); /* Find new highest priority task */
436 2 return (OS_NO_ERR);
437 2 }
438 1 // led=!led;
439 1 OS_EXIT_CRITICAL();
440 1
441 1 return (OS_TASK_DEL_ERR);
442 1 }
443 #endif
444 /*$PAGE*/
445 /*
446 *********************************************************************************************************
447 * REQUEST THAT A TASK DELETE ITSELF
448 *
449 * Description: This function is used to:
450 * a) notify a task to delete itself.
451 * b) to see if a task requested that the current task delete itself.
452 * This function is a little tricky to understand. Basically, you have a task that needs
453 * to be deleted however, this task has resources that it has allocated (memory buffers,
454 * semaphores, mailboxes, queues etc.). The task cannot be deleted otherwise these
455 * resources would not be freed. The requesting task calls OSTaskDelReq() to indicate that
456 * the task needs to be deleted. Deleting of the task is however, deferred to the task to
457 * be deleted. For example, suppose that task #10 needs to be deleted. The requesting task
458 * example, task #5, would call OSTaskDelReq(10). When task #10 gets to execute, it calls
459 * this function by specifying OS_PRIO_SELF and monitors the returned value. If the return
460 * value is OS_TASK_DEL_REQ, another task requested a task delete. Task #10 would look like
461 * this:
462 *
463 * void Task(void *data)
464 * {
465 * .
466 * .
467 * while (1) {
468 * OSTimeDly(1);
469 * if (OSTaskDelReq(OS_PRIO_SELF) == OS_TASK_DEL_REQ) {
470 * Release any owned resources;
471 * De-allocate any dynamic memory;
472 * OSTaskDel(OS_PRIO_SELF);
473 * }
474 * }
475 * }
476 *
477 * Arguments : prio is the priority of the task to request the delete from
478 *
479 * Returns : OS_NO_ERR if the task exist and the request has been registered
480 * OS_TASK_NOT_EXIST if the task has been deleted. This allows the caller to know whether
481 * the request has been executed.
482 * OS_TASK_DEL_IDLE if you requested to delete uC/OS-II's idle task
483 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
484 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
485 * OS_TASK_DEL_REQ if a task (possibly another task) requested that the running task be
486 * deleted.
487 *********************************************************************************************************
488 */
C51 COMPILER V9.01 OS_TASK 10/31/2012 17:19:07 PAGE 9
489 /*$PAGE*/
490 #if OS_TASK_DEL_EN > 0
491 INT8U OSTaskDelReq (INT8U prio)
492 {
493 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
496 1 BOOLEAN stat;
497 1 INT8U err;
498 1 OS_TCB *ptcb;
499 1
500 1
501 1 #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
509 1 if (prio == OS_PRIO_SELF) { /* See if a task is requesting to ... */
510 2 OS_ENTER_CRITICAL(); /* ... this task to delete itself */
511 2 stat = OSTCBCur->OSTCBDelReq; /* Return request status to caller */
512 2 OS_EXIT_CRITICAL();
513 2 return (stat);
514 2 }
515 1 OS_ENTER_CRITICAL();
516 1 ptcb = OSTCBPrioTbl[prio];
517 1 if (ptcb != (OS_TCB *)0) { /* Task to delete must exist */
518 2 ptcb->OSTCBDelReq = OS_TASK_DEL_REQ; /* Set flag indicating task to be DEL. */
519 2 err = OS_NO_ERR;
520 2 } else {
521 2 err = OS_TASK_NOT_EXIST; /* Task must be deleted */
522 2 }
523 1 OS_EXIT_CRITICAL();
524 1 return (err);
525 1 }
526 #endif
527 /*$PAGE*/
528 /*
529 *********************************************************************************************************
530 * RESUME A SUSPENDED TASK
531 *
532 * Description: This function is called to resume a previously suspended task. This is the only call that
533 * will remove an explicit task suspension.
534 *
535 * Arguments : prio is the priority of the task to resume.
536 *
537 * Returns : OS_NO_ERR if the requested task is resumed
538 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
539 * (i.e. >= OS_LOWEST_PRIO)
540 * OS_TASK_RESUME_PRIO if the task to resume does not exist
541 * OS_TASK_NOT_SUSPENDED if the task to resume has not been suspended
542 *********************************************************************************************************
543 */
544
545 #if OS_TASK_SUSPEND_EN > 0
INT8U OSTaskResume (INT8U prio)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
C51 COMPILER V9.01 OS_TASK 10/31/2012 17:19:07 PAGE 10
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();
ptcb = OSTCBPrioTbl[prio];
if (ptcb == (OS_TCB *)0) { /* Task to suspend must exist */
OS_EXIT_CRITICAL();
return (OS_TASK_RESUME_PRIO);
}
if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) { /* 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 + -