?? os_task.lst
字號(hào):
409 3 }
410 2 OS_EXIT_CRITICAL(); /* Enabling INT. ignores next instruc. */
411 2 OS_Dummy(); /* ... Dummy ensures that INTs will be */
412 2 OS_ENTER_CRITICAL(); /* ... disabled HERE! */
413 2 if (OSLockNesting > 0) {
414 3 OSLockNesting--;
415 3 }
416 2 OSTaskDelHook(ptcb); /* Call user defined hook */
417 2 OSTaskCtr--; /* One less task being managed */
418 2 OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Clear old priority entry */
419 2 if (ptcb->OSTCBPrev == (OS_TCB *)0) { /* Remove from TCB chain */
420 3 ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
421 3 OSTCBList = ptcb->OSTCBNext;
422 3 } else {
423 3 ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
424 3 ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
425 3 }
426 2 ptcb->OSTCBNext = OSTCBFreeList; /* Return TCB to free TCB list */
C51 COMPILER V7.06 OS_TASK 07/18/2003 11:06:04 PAGE 8
427 2 OSTCBFreeList = ptcb;
428 2 // ptcb->OSTCBStkPtr = (OS_STK *)0;//#Lin /* Show that TCB is 'unused'
- */
429 2 #if OS_TASK_NAME_SIZE > 0
430 2 (void)strcpy(ptcb->OSTCBTaskName, "?"); /* Unknown name */
431 2 #endif
432 2 OS_EXIT_CRITICAL();
433 2 OS_Sched(); /* Find new highest priority task */
434 2 return (OS_NO_ERR);
435 2 }
436 1 OS_EXIT_CRITICAL();
437 1 return (OS_TASK_DEL_ERR);
438 1 }
439 #endif
440 /*$PAGE*/
441 /*
442 *********************************************************************************************************
443 * REQUEST THAT A TASK DELETE ITSELF
444 *
445 * Description: This function is used to:
446 * a) notify a task to delete itself.
447 * b) to see if a task requested that the current task delete itself.
448 * This function is a little tricky to understand. Basically, you have a task that needs
449 * to be deleted however, this task has resources that it has allocated (memory buffers,
450 * semaphores, mailboxes, queues etc.). The task cannot be deleted otherwise these
451 * resources would not be freed. The requesting task calls OSTaskDelReq() to indicate that
452 * the task needs to be deleted. Deleting of the task is however, deferred to the task to
453 * be deleted. For example, suppose that task #10 needs to be deleted. The requesting task
454 * example, task #5, would call OSTaskDelReq(10). When task #10 gets to execute, it calls
455 * this function by specifying OS_PRIO_SELF and monitors the returned value. If the return
456 * value is OS_TASK_DEL_REQ, another task requested a task delete. Task #10 would look like
457 * this:
458 *
459 * void Task(void *data)
460 * {
461 * .
462 * .
463 * while (1) {
464 * OSTimeDly(1);
465 * if (OSTaskDelReq(OS_PRIO_SELF) == OS_TASK_DEL_REQ) {
466 * Release any owned resources;
467 * De-allocate any dynamic memory;
468 * OSTaskDel(OS_PRIO_SELF);
469 * }
470 * }
471 * }
472 *
473 * Arguments : prio is the priority of the task to request the delete from
474 *
475 * Returns : OS_NO_ERR if the task exist and the request has been registered
476 * OS_TASK_NOT_EXIST if the task has been deleted. This allows the caller to know whether
477 * the request has been executed.
478 * OS_TASK_DEL_IDLE if you requested to delete uC/OS-II's idle task
479 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
480 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
481 * OS_TASK_DEL_REQ if a task (possibly another task) requested that the running task be
482 * deleted.
483 *********************************************************************************************************
484 */
485 /*$PAGE*/
486 #if OS_TASK_DEL_EN > 0
487 INT8U OSTaskDelReq (INT8U prio) reentrant //using 0
C51 COMPILER V7.06 OS_TASK 07/18/2003 11:06:04 PAGE 9
488 {
489 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
490 1 OS_CPU_SR cpu_sr;
491 1 #endif
492 1 BOOLEAN stat;
493 1 INT8U err;
494 1 OS_TCB *ptcb;
495 1
496 1
497 1 #if OS_ARG_CHK_EN > 0
498 1 if (prio == OS_IDLE_PRIO) { /* Not allowed to delete idle task */
499 2 return (OS_TASK_DEL_IDLE);
500 2 }
501 1 if (prio >= OS_LOWEST_PRIO) { /* Task priority valid ? */
502 2 if (prio != OS_PRIO_SELF) {
503 3 return (OS_PRIO_INVALID);
504 3 }
505 2 }
506 1 #endif
507 1 if (prio == OS_PRIO_SELF) { /* See if a task is requesting to ... */
508 2 OS_ENTER_CRITICAL(); /* ... this task to delete itself */
509 2 stat = OSTCBCur->OSTCBDelReq; /* Return request status to caller */
510 2 OS_EXIT_CRITICAL();
511 2 return (stat);
512 2 }
513 1 OS_ENTER_CRITICAL();
514 1 ptcb = OSTCBPrioTbl[prio];
515 1 if (ptcb != (OS_TCB *)0) { /* Task to delete must exist */
516 2 ptcb->OSTCBDelReq = OS_TASK_DEL_REQ; /* Set flag indicating task to be DEL. */
517 2 err = OS_NO_ERR;
518 2 } else {
519 2 err = OS_TASK_NOT_EXIST; /* Task must be deleted */
520 2 }
521 1 OS_EXIT_CRITICAL();
522 1 return (err);
523 1 }
524 #endif
525 /*$PAGE*/
526 /*
527 *********************************************************************************************************
528 * GET THE NAME OF A TASK
529 *
530 * Description: This function is called to obtain the name of a task.
531 *
532 * Arguments : prio is the priority of the task that you want to obtain the name from.
533 *
534 * pname is a pointer to an ASCII string that will receive the name of the task. The
535 * string must be able to hold at least OS_TASK_NAME_SIZE characters.
536 *
537 * err is a pointer to an error code that can contain one of the following values:
538 *
539 * OS_NO_ERR if the requested task is resumed
540 * OS_TASK_NOT_EXIST if the task has not been created
541 * OS_PRIO_INVALID if you specified an invalid priority:
542 * A higher value than the idle task or not OS_PRIO_SELF.
543 * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
544 *
545 * Returns : The length of the string or 0 if the task does not exist.
546 *********************************************************************************************************
547 */
548
549 #if OS_TASK_NAME_SIZE > 0
C51 COMPILER V7.06 OS_TASK 07/18/2003 11:06:04 PAGE 10
550 INT8U OSTaskNameGet (INT8U prio, char *pname, INT8U *err) reentrant //using 0
551 {
552 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
553 1 OS_CPU_SR cpu_sr;
554 1 #endif
555 1 OS_TCB *ptcb;
556 1 INT8U len;
557 1
558 1
559 1 OS_ENTER_CRITICAL();
560 1 #if OS_ARG_CHK_EN > 0
561 1 if (prio > OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
562 2 *err = OS_PRIO_INVALID; /* No */
563 2 return (0);
564 2 }
565 1 if (pname == (char *)0) { /* Is 'pname' a NULL pointer? */
566 2 OS_EXIT_CRITICAL(); /* Yes */
567 2 *err = OS_ERR_PNAME_NULL;
568 2 return (0);
569 2 }
570 1 #endif
571 1 if (prio == OS_PRIO_SELF) { /* See if caller desires it's own name */
572 2 prio = OSTCBCur->OSTCBPrio;
573 2 }
574 1 ptcb = OSTCBPrioTbl[prio];
575 1 if (ptcb == (OS_TCB *)0) { /* Does task exist? */
576 2 OS_EXIT_CRITICAL(); /* No */
577 2 *err = OS_TASK_NOT_EXIST;
578 2 return (0);
579 2 }
580 1 (void)strcpy(pname, ptcb->OSTCBTaskName); /* Yes, copy name from TCB */
581 1 len = strlen(pname);
582 1 OS_EXIT_CRITICAL();
583 1 *err = OS_NO_ERR;
584 1 return (len);
585 1 }
586 #endif
587
588 /*$PAGE*/
589 /*
590 *********************************************************************************************************
591 * ASSIGN A NAME TO A TASK
592 *
593 * Description: This function is used to set the name of a task.
594 *
595 * Arguments : prio is the priority of the task that you want the assign a name to.
596 *
597 * pname is a pointer to an ASCII string that contains the name of the task. The ASCII
598 * string must be NUL terminated.
599 *
600 * err is a pointer to an error code that can contain one of the following values:
601 *
602 * OS_NO_ERR if the requested task is resumed
603 * OS_TASK_NOT_EXIST if the task has not been created
604 * OS_ERR_TASK_NAME_TOO_LONG if the name you are giving to the task exceeds the
605 * storage capacity of a task name as specified by
606 * OS_TASK_NAME_SIZE.
607 * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
608 * OS_PRIO_INVALID if you specified an invalid priority:
609 * A higher value than the idle task or not OS_PRIO_SELF.
610 *
611 * Returns : None
C51 COMPILER V7.06 OS_TASK 07/18/2003 11:06:04 PAGE 11
612 *********************************************************************************************************
613 */
614 #if OS_TASK_NAME_SIZE > 0
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -