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

📄 os_task.lst

📁 uCos-ii 2.86 在C8051F410单片机上移植成功!!! 其中包括:UART驱动
💻 LST
📖 第 1 页 / 共 5 页
字号:
                      ptcb->OSTCBStat &= ~(INT8U)OS_STAT_SUSPEND;           /* Remove suspension                     */
                      if (ptcb->OSTCBStat == OS_STAT_RDY) {                 /* See if task is now ready              */
                          if (ptcb->OSTCBDly == 0) {
                              OSRdyGrp               |= ptcb->OSTCBBitY;    /* Yes, Make task ready to run           */
                              OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
                              OS_EXIT_CRITICAL();
                              if (OSRunning == OS_TRUE) {
                                  OS_Sched();                               /* Find new highest priority task        */
                              }
                          } else {
                              OS_EXIT_CRITICAL();
                          }
                      } else {                                              /* Must be pending on event              */
                          OS_EXIT_CRITICAL();
                      }
                      return (OS_ERR_NONE);
                  }
                  OS_EXIT_CRITICAL();
                  return (OS_ERR_TASK_NOT_SUSPENDED);
              }
              #endif
 836          /*$PAGE*/
 837          /*
 838          *********************************************************************************************************
 839          *                                             STACK CHECKING
 840          *
 841          * Description: This function is called to check the amount of free memory left on the specified task's
 842          *              stack.
 843          *
 844          * Arguments  : prio          is the task priority
 845          *
 846          *              p_stk_data    is a pointer to a data structure of type OS_STK_DATA.
 847          *
 848          * Returns    : OS_ERR_NONE            upon success
 849          *              OS_ERR_PRIO_INVALID    if the priority you specify is higher that the maximum allowed
 850          *                                     (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 851          *              OS_ERR_TASK_NOT_EXIST  if the desired task has not been created or is assigned to a Mutex P
             -IP
 852          *              OS_ERR_TASK_OPT        if you did NOT specified OS_TASK_OPT_STK_CHK when the task was creat
             -ed
C51 COMPILER V8.17   OS_TASK                                                               03/26/2009 14:24:25 PAGE 15  

 853          *              OS_ERR_PDATA_NULL      if 'p_stk_data' is a NULL pointer
 854          *********************************************************************************************************
 855          */
 856          #if (OS_TASK_STAT_STK_CHK_EN > 0) && (OS_TASK_CREATE_EXT_EN > 0)
              INT8U  OSTaskStkChk (INT8U prio, OS_STK_DATA *p_stk_data) reentrant
              {
                  OS_TCB    *ptcb;
                  OS_STK    *pchk;
                  INT32U     nfree;
                  INT32U     size;
              #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 (prio > OS_LOWEST_PRIO) {                       /* Make sure task priority is valid             */
                      if (prio != OS_PRIO_SELF) {
                          return (OS_ERR_PRIO_INVALID);
                      }
                  }
                  if (p_stk_data == (OS_STK_DATA *)0) {              /* Validate 'p_stk_data'                        */
                      return (OS_ERR_PDATA_NULL);
                  }
              #endif
                  p_stk_data->OSFree = 0;                            /* Assume failure, set to 0 size                */
                  p_stk_data->OSUsed = 0;
                  OS_ENTER_CRITICAL();
                  if (prio == OS_PRIO_SELF) {                        /* See if check for SELF                        */
                      prio = OSTCBCur->OSTCBPrio;
                  }
                  ptcb = OSTCBPrioTbl[prio];
                  if (ptcb == (OS_TCB *)0) {                         /* Make sure task exist                         */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_TASK_NOT_EXIST);
                  }
                  if (ptcb == OS_TCB_RESERVED) {
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_TASK_NOT_EXIST);
                  }
                  if ((ptcb->OSTCBOpt & OS_TASK_OPT_STK_CHK) == 0) { /* Make sure stack checking option is set       */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_TASK_OPT);
                  }
                  nfree = 0;
                  size  = ptcb->OSTCBStkSize;
                  pchk  = ptcb->OSTCBStkBottom;
                  OS_EXIT_CRITICAL();
              #if OS_STK_GROWTH == 1
                  while (*pchk++ == (OS_STK)0) {                    /* Compute the number of zero entries on the stk */
                      nfree++;
                  }
              #else
                  while (*pchk-- == (OS_STK)0) {
                      nfree++;
                  }
              #endif
                  p_stk_data->OSFree = nfree * sizeof(OS_STK);          /* Compute number of free bytes on the stack */
                  p_stk_data->OSUsed = (size - nfree) * sizeof(OS_STK); /* Compute number of bytes used on the stack */
                  return (OS_ERR_NONE);
              }
C51 COMPILER V8.17   OS_TASK                                                               03/26/2009 14:24:25 PAGE 16  

              #endif
 916          /*$PAGE*/
 917          /*
 918          *********************************************************************************************************
 919          *                                            SUSPEND A TASK
 920          *
 921          * Description: This function is called to suspend a task.  The task can be the calling task if the
 922          *              priority passed to OSTaskSuspend() is the priority of the calling task or OS_PRIO_SELF.
 923          *
 924          * Arguments  : prio     is the priority of the task to suspend.  If you specify OS_PRIO_SELF, the
 925          *                       calling task will suspend itself and rescheduling will occur.
 926          *
 927          * Returns    : OS_ERR_NONE               if the requested task is suspended
 928          *              OS_ERR_TASK_SUSPEND_IDLE  if you attempted to suspend the idle task which is not allowed.
 929          *              OS_ERR_PRIO_INVALID       if the priority you specify is higher that the maximum allowed
 930          *                                        (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 931          *              OS_ERR_TASK_SUSPEND_PRIO  if the task to suspend does not exist
 932          *              OS_ERR_TASK_NOT_EXITS     if the task is assigned to a Mutex PIP
 933          *
 934          * Note       : You should use this function with great care.  If you suspend a task that is waiting for
 935          *              an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from
 936          *              running when the event arrives.
 937          *********************************************************************************************************
 938          */
 939          
 940          #if OS_TASK_SUSPEND_EN > 0
              INT8U  OSTaskSuspend (INT8U prio) reentrant
              {
                  BOOLEAN    self;
                  OS_TCB    *ptcb;
                  INT8U      y;
              #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 (prio == OS_TASK_IDLE_PRIO) {                            /* Not allowed to suspend idle task    */
                      return (OS_ERR_TASK_SUSPEND_IDLE);
                  }
                  if (prio >= OS_LOWEST_PRIO) {                               /* Task priority valid ?               */
                      if (prio != OS_PRIO_SELF) {
                          return (OS_ERR_PRIO_INVALID);
                      }
                  }
              #endif
                  OS_ENTER_CRITICAL();
                  if (prio == OS_PRIO_SELF) {                                 /* See if suspend SELF                 */
                      prio = OSTCBCur->OSTCBPrio;
                      self = OS_TRUE;
                  } else if (prio == OSTCBCur->OSTCBPrio) {                   /* See if suspending self              */
                      self = OS_TRUE;
                  } else {
                      self = OS_FALSE;                                        /* No suspending another task          */
                  }
                  ptcb = OSTCBPrioTbl[prio];
                  if (ptcb == (OS_TCB *)0) {                                  /* Task to suspend must exist          */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_TASK_SUSPEND_PRIO);
                  }
                  if (ptcb == OS_TCB_RESERVED) {                              /* See if assigned to Mutex            */
C51 COMPILER V8.17   OS_TASK                                                               03/26/2009 14:24:25 PAGE 17  

                      OS_EXIT_CRITICAL();
                      return (OS_ERR_TASK_NOT_EXIST);
                  }
                  y            = ptcb->OSTCBY;
                  OSRdyTbl[y] &= ~ptcb->OSTCBBitX;                            /* Make task not ready                 */
                  if (OSRdyTbl[y] == 0) {
                      OSRdyGrp &= ~ptcb->OSTCBBitY;
                  }
                  ptcb->OSTCBStat |= OS_STAT_SUSPEND;                         /* Status of task is 'SUSPENDED'       */
                  OS_EXIT_CRITICAL();
                  if (self == OS_TRUE) {                                      /* Context switch only if SELF         */
                      OS_Sched();                                             /* Find new highest priority task      */
                  }
                  return (OS_ERR_NONE);
              }
              #endif
 993          /*$PAGE*/
 994          /*
 995          *********************************************************************************************************
 996          *                                            QUERY A TASK
 997          *
 998          * Description: This function is called to obtain a copy of the desired task's TCB.
 999          *
1000          * Arguments  : prio         is the priority of the task to obtain information from.
1001          *
1002          *              p_task_data  is a pointer to where the desired task's OS_TCB will be stored.
1003          *
1004          * Returns    : OS_ERR_NONE            if the requested task is suspended
1005          *              OS_ERR_PRIO_INVALID    if the priority you specify is higher that the maximum allowed
1006          *                                     (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
1007          *              OS_ERR_PRIO            if the desired task has not been created
1008          *              OS_ERR_TASK_NOT_EXIST  if the task is assigned to a Mutex PIP
1009          *              OS_ERR_PDATA_NULL      if 'p_task_data' is a NULL pointer
1010          *********************************************************************************************************
1011          */
1012          
1013          #if OS_TASK_QUERY_EN > 0
              INT8U  OSTaskQuery (INT8U prio, OS_TCB *p_task_data) reentrant
              {
                  OS_TCB    *ptcb;
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  

⌨️ 快捷键说明

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