📄 os_task.lst
字号:
}
(void)strcpy(pname, ptcb->OSTCBTaskName); /* Yes, copy name from TCB */
len = strlen(pname);
OS_EXIT_CRITICAL();
*err = OS_NO_ERR;
return (len);
}
#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
612 *********************************************************************************************************
C51 COMPILER V8.05a OS_TASK 04/11/2007 16:19:49 PAGE 11
613 */
614 #if OS_TASK_NAME_SIZE > 0
void OSTaskNameSet (INT8U prio, char *pname, INT8U *err) KCREENTRANT
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT8U len;
OS_TCB *ptcb;
OS_ENTER_CRITICAL();
#if OS_ARG_CHK_EN > 0
if (prio > OS_LOWEST_PRIO) { /* Task priority valid ? */
if (prio != OS_PRIO_SELF) {
*err = OS_PRIO_INVALID; /* No */
return;
}
}
if (pname == (char *)0) { /* Is 'pname' a NULL pointer? */
OS_EXIT_CRITICAL(); /* Yes */
*err = OS_ERR_PNAME_NULL;
return;
}
#endif
if (prio == OS_PRIO_SELF) { /* See if caller desires to set it's own name */
prio = OSTCBCur->OSTCBPrio;
}
ptcb = OSTCBPrioTbl[prio];
if (ptcb == (OS_TCB *)0) { /* Does task exist? */
OS_EXIT_CRITICAL(); /* No */
*err = OS_TASK_NOT_EXIST;
return;
}
len = strlen(pname); /* Yes, Can we fit the string in the TCB? */
if (len > (OS_TASK_NAME_SIZE - 1)) { /* No */
OS_EXIT_CRITICAL();
*err = OS_ERR_TASK_NAME_TOO_LONG;
return;
}
(void)strcpy(ptcb->OSTCBTaskName, pname); /* Yes, copy to TCB */
OS_EXIT_CRITICAL();
*err = OS_NO_ERR;
}
#endif
658
659 /*$PAGE*/
660 /*
661 *********************************************************************************************************
662 * RESUME A SUSPENDED TASK
663 *
664 * Description: This function is called to resume a previously suspended task. This is the only call that
665 * will remove an explicit task suspension.
666 *
667 * Arguments : prio is the priority of the task to resume.
668 *
669 * Returns : OS_NO_ERR if the requested task is resumed
670 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
671 * (i.e. >= OS_LOWEST_PRIO)
672 * OS_TASK_RESUME_PRIO if the task to resume does not exist
673 * OS_TASK_NOT_SUSPENDED if the task to resume has not been suspended
674 *********************************************************************************************************
C51 COMPILER V8.05a OS_TASK 04/11/2007 16:19:49 PAGE 12
675 */
676
677 #if OS_TASK_SUSPEND_EN > 0
678 INT8U OSTaskResume (INT8U prio) KCREENTRANT
679 {
680 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
683 1 OS_TCB *ptcb;
684 1
685 1
686 1 #if OS_ARG_CHK_EN > 0
687 1 if (prio >= OS_LOWEST_PRIO) { /* Make sure task priority is valid */
688 2 return (OS_PRIO_INVALID);
689 2 }
690 1 #endif
691 1 OS_ENTER_CRITICAL();
692 1 ptcb = OSTCBPrioTbl[prio];
693 1 if (ptcb == (OS_TCB *)0) { /* Task to suspend must exist */
694 2 OS_EXIT_CRITICAL();
695 2 return (OS_TASK_RESUME_PRIO);
696 2 }
697 1 if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) { /* Task must be suspended */
698 2 ptcb->OSTCBStat &= ~OS_STAT_SUSPEND; /* Remove suspension */
699 2 if (ptcb->OSTCBStat == OS_STAT_RDY) {
700 3 if (ptcb->OSTCBDly == 0) { /* Must not be delayed */
701 4 OSRdyGrp |= ptcb->OSTCBBitY; /* Make task ready to run */
702 4 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
703 4 OS_EXIT_CRITICAL();
704 4 OS_Sched();
705 4 } else {
706 4 OS_EXIT_CRITICAL();
707 4 }
708 3 } else {
709 3 OS_EXIT_CRITICAL();
710 3 }
711 2 return (OS_NO_ERR);
712 2 }
713 1 OS_EXIT_CRITICAL();
714 1 return (OS_TASK_NOT_SUSPENDED);
715 1 }
716 #endif
717 /*$PAGE*/
718 /*
719 *********************************************************************************************************
720 * STACK CHECKING
721 *
722 * Description: This function is called to check the amount of free memory left on the specified task's
723 * stack.
724 *
725 * Arguments : prio is the task priority
726 *
727 * pdata is a pointer to a data structure of type OS_STK_DATA.
728 *
729 * Returns : OS_NO_ERR upon success
730 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
731 * (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
732 * OS_TASK_NOT_EXIST if the desired task has not been created
733 * OS_TASK_OPT_ERR if you did NOT specified OS_TASK_OPT_STK_CHK when the task was created
734 *********************************************************************************************************
735 */
736 #if OS_TASK_CREATE_EXT_EN > 0
C51 COMPILER V8.05a OS_TASK 04/11/2007 16:19:49 PAGE 13
737 INT8U OSTaskStkChk (INT8U prio, OS_STK_DATA *pdata) KCREENTRANT
738 {
739 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
742 1 OS_TCB *ptcb;
743 1 OS_STK *pchk;
744 1 INT32U free;
745 1 INT32U size;
746 1
747 1
748 1 #if OS_ARG_CHK_EN > 0
749 1 if (prio > OS_LOWEST_PRIO) { /* Make sure task priority is valid */
750 2 if (prio != OS_PRIO_SELF) {
751 3 return (OS_PRIO_INVALID);
752 3 }
753 2 }
754 1 #endif
755 1 pdata->OSFree = 0; /* Assume failure, set to 0 size */
756 1 pdata->OSUsed = 0;
757 1 OS_ENTER_CRITICAL();
758 1 if (prio == OS_PRIO_SELF) { /* See if check for SELF */
759 2 prio = OSTCBCur->OSTCBPrio;
760 2 }
761 1 ptcb = OSTCBPrioTbl[prio];
762 1 if (ptcb == (OS_TCB *)0) { /* Make sure task exist */
763 2 OS_EXIT_CRITICAL();
764 2 return (OS_TASK_NOT_EXIST);
765 2 }
766 1 if (ptcb == (OS_TCB *)1) {
767 2 OS_EXIT_CRITICAL();
768 2 return (OS_TASK_NOT_EXIST);
769 2 }
770 1 if ((ptcb->OSTCBOpt & OS_TASK_OPT_STK_CHK) == 0) { /* Make sure stack checking option is set */
771 2 OS_EXIT_CRITICAL();
772 2 return (OS_TASK_OPT_ERR);
773 2 }
774 1 free = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -