📄 os_task.lst
字号:
404 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
407 1
408 1
409 1
410 1 if (OSIntNesting > 0) { /* See if trying to delete from ISR */
411 2 return (OS_ERR_TASK_DEL_ISR);
412 2 }
413 1 if (prio == OS_TASK_IDLE_PRIO) { /* Not allowed to delete idle task */
414 2 return (OS_ERR_TASK_DEL_IDLE);
415 2 }
416 1 #if OS_ARG_CHK_EN > 0
if (prio >= OS_LOWEST_PRIO) { /* Task priority valid ? */
if (prio != OS_PRIO_SELF) {
return (OS_ERR_PRIO_INVALID);
}
}
#endif
423 1
C51 COMPILER V7.50 OS_TASK 12/14/2007 08:25:42 PAGE 8
424 1 OS_ENTER_CRITICAL();
425 1 if (prio == OS_PRIO_SELF) { /* See if requesting to delete self */
426 2 prio = OSTCBCur->OSTCBPrio; /* Set priority to delete to current */
427 2 }
428 1 ptcb = OSTCBPrioTbl[prio];
429 1 if (ptcb == (OS_TCB *)0) { /* Task to delete must exist */
430 2 OS_EXIT_CRITICAL();
431 2 return (OS_ERR_TASK_NOT_EXIST);
432 2 }
433 1 if (ptcb == OS_TCB_RESERVED) { /* Must not be assigned to Mutex */
434 2 OS_EXIT_CRITICAL();
435 2 return (OS_ERR_TASK_DEL);
436 2 }
437 1 y = ptcb->OSTCBY;
438 1 OSRdyTbl[y] &= ~ptcb->OSTCBBitX;
439 1 if (OSRdyTbl[y] == 0) { /* Make task not ready */
440 2 OSRdyGrp &= ~ptcb->OSTCBBitY;
441 2 }
442 1
443 1 #if OS_EVENT_EN
444 1 pevent = ptcb->OSTCBEventPtr;
445 1 if (pevent != (OS_EVENT *)0) { /* If task is waiting on event */
446 2 pevent->OSEventTbl[y] &= ~ptcb->OSTCBBitX;
447 2 if (pevent->OSEventTbl[y] == 0) { /* ... remove task from ... */
448 3 pevent->OSEventGrp &= ~ptcb->OSTCBBitY; /* ... event ctrl block */
449 3 }
450 2 }
451 1 #endif
452 1
453 1 #if (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
459 1
460 1 ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from updating */
461 1 ptcb->OSTCBStat = OS_STAT_RDY; /* Prevent task from being resumed */
462 1 ptcb->OSTCBStatPend = OS_STAT_PEND_OK;
463 1 if (OSLockNesting < 255u) { /* Make sure we don't context switch */
464 2 OSLockNesting++;
465 2 }
466 1 OS_EXIT_CRITICAL(); /* Enabling INT. ignores next instruc. */
467 1 OS_Dummy(); /* ... Dummy ensures that INTs will be */
468 1 OS_ENTER_CRITICAL(); /* ... disabled HERE! */
469 1 if (OSLockNesting > 0) { /* Remove context switch lock */
470 2 OSLockNesting--;
471 2 }
472 1 OSTaskDelHook(ptcb); /* Call user defined hook */
473 1 OSTaskCtr--; /* One less task being managed */
474 1 OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Clear old priority entry */
475 1 if (ptcb->OSTCBPrev == (OS_TCB *)0) { /* Remove from TCB chain */
476 2 ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
477 2 OSTCBList = ptcb->OSTCBNext;
478 2 } else {
479 2 ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
480 2 ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
481 2 }
482 1 ptcb->OSTCBNext = OSTCBFreeList; /* Return TCB to free TCB list */
483 1 OSTCBFreeList = ptcb;
484 1 #if OS_TASK_NAME_SIZE > 1
485 1 ptcb->OSTCBTaskName[0] = '?'; /* Unknown name */
C51 COMPILER V7.50 OS_TASK 12/14/2007 08:25:42 PAGE 9
486 1 ptcb->OSTCBTaskName[1] = OS_ASCII_NUL;
487 1 #endif
488 1 OS_EXIT_CRITICAL();
489 1 if (OSRunning == OS_TRUE) {
490 2 OS_Sched(); /* Find new highest priority task */
491 2 }
492 1 return (OS_ERR_NONE);
493 1 }
494 #endif
495 /*$PAGE*/
496 /*
497 *********************************************************************************************************
498 * REQUEST THAT A TASK DELETE ITSELF
499 *
500 * Description: This function is used to:
501 * a) notify a task to delete itself.
502 * b) to see if a task requested that the current task delete itself.
503 * This function is a little tricky to understand. Basically, you have a task that needs
504 * to be deleted however, this task has resources that it has allocated (memory buffers,
505 * semaphores, mailboxes, queues etc.). The task cannot be deleted otherwise these
506 * resources would not be freed. The requesting task calls OSTaskDelReq() to indicate that
507 * the task needs to be deleted. Deleting of the task is however, deferred to the task to
508 * be deleted. For example, suppose that task #10 needs to be deleted. The requesting task
509 * example, task #5, would call OSTaskDelReq(10). When task #10 gets to execute, it calls
510 * this function by specifying OS_PRIO_SELF and monitors the returned value. If the return
511 * value is OS_ERR_TASK_DEL_REQ, another task requested a task delete. Task #10 would look li
-ke
512 * this:
513 *
514 * void Task(void *p_arg)
515 * {
516 * .
517 * .
518 * while (1) {
519 * OSTimeDly(1);
520 * if (OSTaskDelReq(OS_PRIO_SELF) == OS_ERR_TASK_DEL_REQ) {
521 * Release any owned resources;
522 * De-allocate any dynamic memory;
523 * OSTaskDel(OS_PRIO_SELF);
524 * }
525 * }
526 * }
527 *
528 * Arguments : prio is the priority of the task to request the delete from
529 *
530 * Returns : OS_ERR_NONE if the task exist and the request has been registered
531 * OS_ERR_TASK_NOT_EXIST if the task has been deleted. This allows the caller to know whethe
-r
532 * the request has been executed.
533 * OS_ERR_TASK_DEL if the task is assigned to a Mutex.
534 * OS_ERR_TASK_DEL_IDLE if you requested to delete uC/OS-II's idle task
535 * OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allowed
536 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
537 * OS_ERR_TASK_DEL_REQ if a task (possibly another task) requested that the running task be
538 * deleted.
539 *********************************************************************************************************
540 */
541 /*$PAGE*/
542 #if OS_TASK_DEL_EN > 0
543 INT8U OSTaskDelReq (INT8U prio) reentrant
544 {
545 1 INT8U stat;
C51 COMPILER V7.50 OS_TASK 12/14/2007 08:25:42 PAGE 10
546 1 OS_TCB *ptcb;
547 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
550 1
551 1
552 1
553 1 if (prio == OS_TASK_IDLE_PRIO) { /* Not allowed to delete idle task */
554 2 return (OS_ERR_TASK_DEL_IDLE);
555 2 }
556 1 #if OS_ARG_CHK_EN > 0
if (prio >= OS_LOWEST_PRIO) { /* Task priority valid ? */
if (prio != OS_PRIO_SELF) {
return (OS_ERR_PRIO_INVALID);
}
}
#endif
563 1 if (prio == OS_PRIO_SELF) { /* See if a task is requesting to ... */
564 2 OS_ENTER_CRITICAL(); /* ... this task to delete itself */
565 2 stat = OSTCBCur->OSTCBDelReq; /* Return request status to caller */
566 2 OS_EXIT_CRITICAL();
567 2 return (stat);
568 2 }
569 1 OS_ENTER_CRITICAL();
570 1 ptcb = OSTCBPrioTbl[prio];
571 1 if (ptcb == (OS_TCB *)0) { /* Task to delete must exist */
572 2 OS_EXIT_CRITICAL();
573 2 return (OS_ERR_TASK_NOT_EXIST); /* Task must already be deleted */
574 2 }
575 1 if (ptcb == OS_TCB_RESERVED) { /* Must NOT be assigned to a Mutex */
576 2 OS_EXIT_CRITICAL();
577 2 return (OS_ERR_TASK_DEL);
578 2 }
579 1 ptcb->OSTCBDelReq = OS_ERR_TASK_DEL_REQ; /* Set flag indicating task to be DEL. */
580 1 OS_EXIT_CRITICAL();
581 1 return (OS_ERR_NONE);
582 1 }
583 #endif
584 /*$PAGE*/
585 /*
586 *********************************************************************************************************
587 * GET THE NAME OF A TASK
588 *
589 * Description: This function is called to obtain the name of a task.
590 *
591 * Arguments : prio is the priority of the task that you want to obtain the name from.
592 *
593 * pname is a pointer to an ASCII string that will receive the name of the task. The
594 * string must be able to hold at least OS_TASK_NAME_SIZE characters.
595 *
596 * perr is a pointer to an error code that can contain one of the following values:
597 *
598 * OS_ERR_NONE if the requested task is resumed
599 * OS_ERR_TASK_NOT_EXIST if the task has not been created or is assigned to a M
-utex
600 * OS_ERR_PRIO_INVALID if you specified an invalid priority:
601 * A higher value than the idle task or not OS_PRIO_SELF.
602 * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
603 * OS_ERR_NAME_GET_ISR You called this function from an ISR
604 *
605 *
606 * Returns : The length of the string or 0 if the task does not exist.
C51 COMPILER V7.50 OS_TASK 12/14/2007 08:25:42 PAGE 11
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -