📄 os_task.lst
字号:
607 *********************************************************************************************************
608 */
609
610 #if OS_TASK_NAME_SIZE > 1
611 INT8U OSTaskNameGet (INT8U prio, INT8U *pname, INT8U *perr) reentrant
612 {
613 1 OS_TCB *ptcb;
614 1 INT8U len;
615 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
618 1
619 1
620 1
621 1 #if OS_ARG_CHK_EN > 0
if (perr == (INT8U *)0) { /* Validate 'perr' */
return (0);
}
if (prio > OS_LOWEST_PRIO) { /* Task priority valid ? */
if (prio != OS_PRIO_SELF) {
*perr = OS_ERR_PRIO_INVALID; /* No */
return (0);
}
}
if (pname == (INT8U *)0) { /* Is 'pname' a NULL pointer? */
*perr = OS_ERR_PNAME_NULL; /* Yes */
return (0);
}
#endif
636 1 if (OSIntNesting > 0) { /* See if trying to call from an ISR */
637 2 *perr = OS_ERR_NAME_GET_ISR;
638 2 return (0);
639 2 }
640 1 OS_ENTER_CRITICAL();
641 1 if (prio == OS_PRIO_SELF) { /* See if caller desires it's own name */
642 2 prio = OSTCBCur->OSTCBPrio;
643 2 }
644 1 ptcb = OSTCBPrioTbl[prio];
645 1 if (ptcb == (OS_TCB *)0) { /* Does task exist? */
646 2 OS_EXIT_CRITICAL(); /* No */
647 2 *perr = OS_ERR_TASK_NOT_EXIST;
648 2 return (0);
649 2 }
650 1 if (ptcb == OS_TCB_RESERVED) { /* Task assigned to a Mutex? */
651 2 OS_EXIT_CRITICAL(); /* Yes */
652 2 *perr = OS_ERR_TASK_NOT_EXIST;
653 2 return (0);
654 2 }
655 1 len = OS_StrCopy(pname, ptcb->OSTCBTaskName); /* Yes, copy name from TCB */
656 1 OS_EXIT_CRITICAL();
657 1 *perr = OS_ERR_NONE;
658 1 return (len);
659 1 }
660 #endif
661
662 /*$PAGE*/
663 /*
664 *********************************************************************************************************
665 * ASSIGN A NAME TO A TASK
666 *
667 * Description: This function is used to set the name of a task.
668 *
C51 COMPILER V7.50 OS_TASK 12/14/2007 08:25:42 PAGE 12
669 * Arguments : prio is the priority of the task that you want the assign a name to.
670 *
671 * pname is a pointer to an ASCII string that contains the name of the task. The ASCII
672 * string must be NUL terminated.
673 *
674 * perr is a pointer to an error code that can contain one of the following values:
675 *
676 * OS_ERR_NONE if the requested task is resumed
677 * OS_ERR_TASK_NOT_EXIST if the task has not been created or is assigned to a M
-utex
678 * OS_ERR_TASK_NAME_TOO_LONG if the name you are giving to the task exceeds the
679 * storage capacity of a task name as specified by
680 * OS_TASK_NAME_SIZE.
681 * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
682 * OS_ERR_PRIO_INVALID if you specified an invalid priority:
683 * A higher value than the idle task or not OS_PRIO_SELF.
684 * OS_ERR_NAME_SET_ISR if you called this function from an ISR
685 *
686 * Returns : None
687 *********************************************************************************************************
688 */
689 #if OS_TASK_NAME_SIZE > 1
690 void OSTaskNameSet (INT8U prio, INT8U *pname, INT8U *perr) reentrant
691 {
692 1 INT8U len;
693 1 OS_TCB *ptcb;
694 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
697 1
698 1
699 1
700 1 #if OS_ARG_CHK_EN > 0
if (perr == (INT8U *)0) { /* Validate 'perr' */
return;
}
if (prio > OS_LOWEST_PRIO) { /* Task priority valid ? */
if (prio != OS_PRIO_SELF) {
*perr = OS_ERR_PRIO_INVALID; /* No */
return;
}
}
if (pname == (INT8U *)0) { /* Is 'pname' a NULL pointer? */
*perr = OS_ERR_PNAME_NULL; /* Yes */
return;
}
#endif
715 1 if (OSIntNesting > 0) { /* See if trying to call from an ISR */
716 2 *perr = OS_ERR_NAME_SET_ISR;
717 2 return;
718 2 }
719 1 OS_ENTER_CRITICAL();
720 1 if (prio == OS_PRIO_SELF) { /* See if caller desires to set it's own name */
721 2 prio = OSTCBCur->OSTCBPrio;
722 2 }
723 1 ptcb = OSTCBPrioTbl[prio];
724 1 if (ptcb == (OS_TCB *)0) { /* Does task exist? */
725 2 OS_EXIT_CRITICAL(); /* No */
726 2 *perr = OS_ERR_TASK_NOT_EXIST;
727 2 return;
728 2 }
729 1 if (ptcb == OS_TCB_RESERVED) { /* Task assigned to a Mutex? */
C51 COMPILER V7.50 OS_TASK 12/14/2007 08:25:42 PAGE 13
730 2 OS_EXIT_CRITICAL(); /* Yes */
731 2 *perr = OS_ERR_TASK_NOT_EXIST;
732 2 return;
733 2 }
734 1 len = OS_StrLen(pname); /* Yes, Can we fit the string in the TCB? */
735 1 if (len > (OS_TASK_NAME_SIZE - 1)) { /* No */
736 2 OS_EXIT_CRITICAL();
737 2 *perr = OS_ERR_TASK_NAME_TOO_LONG;
738 2 return;
739 2 }
740 1 (void)OS_StrCopy(ptcb->OSTCBTaskName, pname); /* Yes, copy to TCB */
741 1 OS_EXIT_CRITICAL();
742 1 *perr = OS_ERR_NONE;
743 1 }
744 #endif
745
746 /*$PAGE*/
747 /*
748 *********************************************************************************************************
749 * RESUME A SUSPENDED TASK
750 *
751 * Description: This function is called to resume a previously suspended task. This is the only call that
752 * will remove an explicit task suspension.
753 *
754 * Arguments : prio is the priority of the task to resume.
755 *
756 * Returns : OS_ERR_NONE if the requested task is resumed
757 * OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allowed
758 * (i.e. >= OS_LOWEST_PRIO)
759 * OS_ERR_TASK_RESUME_PRIO if the task to resume does not exist
760 * OS_ERR_TASK_NOT_EXIST if the task is assigned to a Mutex PIP
761 * OS_ERR_TASK_NOT_SUSPENDED if the task to resume has not been suspended
762 *********************************************************************************************************
763 */
764
765 #if OS_TASK_SUSPEND_EN > 0
766 INT8U OSTaskResume (INT8U prio) reentrant
767 {
768 1 OS_TCB *ptcb;
769 1 #if OS_CRITICAL_METHOD == 3 /* Storage for CPU status register */
OS_CPU_SR cpu_sr = 0;
#endif
772 1
773 1
774 1
775 1 #if OS_ARG_CHK_EN > 0
if (prio >= OS_LOWEST_PRIO) { /* Make sure task priority is valid */
return (OS_ERR_PRIO_INVALID);
}
#endif
780 1 OS_ENTER_CRITICAL();
781 1 ptcb = OSTCBPrioTbl[prio];
782 1 if (ptcb == (OS_TCB *)0) { /* Task to suspend must exist */
783 2 OS_EXIT_CRITICAL();
784 2 return (OS_ERR_TASK_RESUME_PRIO);
785 2 }
786 1 if (ptcb == OS_TCB_RESERVED) { /* See if assigned to Mutex */
787 2 OS_EXIT_CRITICAL();
788 2 return (OS_ERR_TASK_NOT_EXIST);
789 2 }
790 1 if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) { /* Task must be suspended */
791 2 ptcb->OSTCBStat &= ~(INT8U)OS_STAT_SUSPEND; /* Remove suspension */
C51 COMPILER V7.50 OS_TASK 12/14/2007 08:25:42 PAGE 14
792 2 if (ptcb->OSTCBStat == OS_STAT_RDY) { /* See if task is now ready */
793 3 if (ptcb->OSTCBDly == 0) {
794 4 OSRdyGrp |= ptcb->OSTCBBitY; /* Yes, Make task ready to run */
795 4 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
796 4 OS_EXIT_CRITICAL();
797 4 if (OSRunning == OS_TRUE) {
798 5 OS_Sched(); /* Find new highest priority task */
799 5 }
800 4 } else {
801 4 OS_EXIT_CRITICAL();
802 4 }
803 3 } else { /* Must be pending on event */
804 3 OS_EXIT_CRITICAL();
805 3 }
806 2 return (OS_ERR_NONE);
807 2 }
808 1 OS_EXIT_CRITICAL();
809 1 return (OS_ERR_TASK_NOT_SUSPENDED);
810 1 }
811 #endif
812 /*$PAGE*/
813 /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -