⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_task.lst

📁 uCos-ii 2.86 在C8051F410单片机上移植成功!!! 其中包括:UART驱动
💻 LST
📖 第 1 页 / 共 5 页
字号:
 609          /*
 610          *********************************************************************************************************
 611          *                                        GET THE NAME OF A TASK
 612          *
 613          * Description: This function is called to obtain the name of a task.
 614          *
 615          * Arguments  : prio      is the priority of the task that you want to obtain the name from.
 616          *
 617          *              pname     is a pointer to an ASCII string that will receive the name of the task.  The
 618          *                        string must be able to hold at least OS_TASK_NAME_SIZE characters.
 619          *
 620          *              perr      is a pointer to an error code that can contain one of the following values:
 621          *
 622          *                        OS_ERR_NONE                if the requested task is resumed
 623          *                        OS_ERR_TASK_NOT_EXIST      if the task has not been created or is assigned to a M
             -utex
 624          *                        OS_ERR_PRIO_INVALID        if you specified an invalid priority:
 625          *                                                   A higher value than the idle task or not OS_PRIO_SELF.
 626          *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
 627          *                        OS_ERR_NAME_GET_ISR        You called this function from an ISR
 628          *                        
 629          *
 630          * Returns    : The length of the string or 0 if the task does not exist.
 631          *********************************************************************************************************
 632          */
 633          
 634          #if OS_TASK_NAME_SIZE > 1
              INT8U  OSTaskNameGet (INT8U prio, INT8U *pname, INT8U *perr) reentrant
              {
                  OS_TCB    *ptcb;
                  INT8U      len;
              #if OS_CRITICAL_METHOD == 3                              /* Allocate storage for CPU status register   */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
              
              
              
              #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
                  if (OSIntNesting > 0) {                              /* See if trying to call from an ISR          */
                      *perr = OS_ERR_NAME_GET_ISR;
                      return (0);
                  }
                  OS_ENTER_CRITICAL();
                  if (prio == OS_PRIO_SELF) {                          /* See if caller desires it's own name        */
                      prio = OSTCBCur->OSTCBPrio;
                  }
                  ptcb = OSTCBPrioTbl[prio];
                  if (ptcb == (OS_TCB *)0) {                           /* Does task exist?                           */
C51 COMPILER V8.17   OS_TASK                                                               03/26/2009 14:24:25 PAGE 12  

                      OS_EXIT_CRITICAL();                              /* No                                         */
                      *perr = OS_ERR_TASK_NOT_EXIST;
                      return (0);
                  }
                  if (ptcb == OS_TCB_RESERVED) {                       /* Task assigned to a Mutex?                  */
                      OS_EXIT_CRITICAL();                              /* Yes                                        */
                      *perr = OS_ERR_TASK_NOT_EXIST;
                      return (0);
                  }
                  len   = OS_StrCopy(pname, ptcb->OSTCBTaskName);      /* Yes, copy name from TCB                    */
                  OS_EXIT_CRITICAL();
                  *perr = OS_ERR_NONE;
                  return (len);
              }
              #endif
 685          
 686          /*$PAGE*/
 687          /*
 688          *********************************************************************************************************
 689          *                                        ASSIGN A NAME TO A TASK
 690          *
 691          * Description: This function is used to set the name of a task.
 692          *
 693          * Arguments  : prio      is the priority of the task that you want the assign a name to.
 694          *
 695          *              pname     is a pointer to an ASCII string that contains the name of the task.  The ASCII
 696          *                        string must be NUL terminated.
 697          *
 698          *              perr       is a pointer to an error code that can contain one of the following values:
 699          *
 700          *                        OS_ERR_NONE                if the requested task is resumed
 701          *                        OS_ERR_TASK_NOT_EXIST      if the task has not been created or is assigned to a M
             -utex
 702          *                        OS_ERR_TASK_NAME_TOO_LONG  if the name you are giving to the task exceeds the
 703          *                                                   storage capacity of a task name as specified by
 704          *                                                   OS_TASK_NAME_SIZE.
 705          *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
 706          *                        OS_ERR_PRIO_INVALID        if you specified an invalid priority:
 707          *                                                   A higher value than the idle task or not OS_PRIO_SELF.
 708          *                        OS_ERR_NAME_SET_ISR        if you called this function from an ISR
 709          *
 710          * Returns    : None
 711          *********************************************************************************************************
 712          */
 713          #if OS_TASK_NAME_SIZE > 1
              void  OSTaskNameSet (INT8U prio, INT8U *pname, INT8U *perr)  reentrant
              {
                  INT8U      len;
                  OS_TCB    *ptcb;
              #if OS_CRITICAL_METHOD == 3                          /* Allocate storage for CPU status register       */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
              
              
              
              #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                                             */
C51 COMPILER V8.17   OS_TASK                                                               03/26/2009 14:24:25 PAGE 13  

                          return;
                      }
                  }
                  if (pname == (INT8U *)0) {                       /* Is 'pname' a NULL pointer?                     */
                      *perr = OS_ERR_PNAME_NULL;                   /* Yes                                            */
                      return;
                  }
              #endif
                  if (OSIntNesting > 0) {                          /* See if trying to call from an ISR              */
                      *perr = OS_ERR_NAME_SET_ISR;
                      return;
                  }
                  OS_ENTER_CRITICAL();
                  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                                             */
                      *perr = OS_ERR_TASK_NOT_EXIST;
                      return;
                  }
                  if (ptcb == OS_TCB_RESERVED) {                   /* Task assigned to a Mutex?                      */
                      OS_EXIT_CRITICAL();                          /* Yes                                            */
                      *perr = OS_ERR_TASK_NOT_EXIST;
                      return;
                  }
                  len = OS_StrLen(pname);                          /* Yes, Can we fit the string in the TCB?         */
                  if (len > (OS_TASK_NAME_SIZE - 1)) {             /*      No                                        */
                      OS_EXIT_CRITICAL();
                      *perr = OS_ERR_TASK_NAME_TOO_LONG;
                      return;
                  }
                  (void)OS_StrCopy(ptcb->OSTCBTaskName, pname);    /*      Yes, copy to TCB                          */
                  OS_EXIT_CRITICAL();
                  *perr = OS_ERR_NONE;
              }
              #endif
 769          
 770          /*$PAGE*/
 771          /*
 772          *********************************************************************************************************
 773          *                                        RESUME A SUSPENDED TASK
 774          *
 775          * Description: This function is called to resume a previously suspended task.  This is the only call that
 776          *              will remove an explicit task suspension.
 777          *
 778          * Arguments  : prio     is the priority of the task to resume.
 779          *
 780          * Returns    : OS_ERR_NONE                if the requested task is resumed
 781          *              OS_ERR_PRIO_INVALID        if the priority you specify is higher that the maximum allowed
 782          *                                         (i.e. >= OS_LOWEST_PRIO)
 783          *              OS_ERR_TASK_RESUME_PRIO    if the task to resume does not exist
 784          *              OS_ERR_TASK_NOT_EXIST      if the task is assigned to a Mutex PIP
 785          *              OS_ERR_TASK_NOT_SUSPENDED  if the task to resume has not been suspended
 786          *********************************************************************************************************
 787          */
 788          
 789          #if OS_TASK_SUSPEND_EN > 0
              INT8U  OSTaskResume (INT8U prio) reentrant
              {
                  OS_TCB    *ptcb;
C51 COMPILER V8.17   OS_TASK                                                               03/26/2009 14:24:25 PAGE 14  

              #if OS_CRITICAL_METHOD == 3                                   /* Storage for CPU status register       */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
              
              
              
              #if OS_ARG_CHK_EN > 0
                  if (prio >= OS_LOWEST_PRIO) {                             /* Make sure task priority is valid      */
                      return (OS_ERR_PRIO_INVALID);
                  }
              #endif
                  OS_ENTER_CRITICAL();
                  ptcb = OSTCBPrioTbl[prio];
                  if (ptcb == (OS_TCB *)0) {                                /* Task to suspend must exist            */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_TASK_RESUME_PRIO);
                  }
                  if (ptcb == OS_TCB_RESERVED) {                            /* See if assigned to Mutex              */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_TASK_NOT_EXIST);
                  }
                  if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) { /* Task must be suspended                */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -