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

📄 os_task.lst

📁 UCOSII2.85针对8051单片机的移植版本
💻 LST
📖 第 1 页 / 共 5 页
字号:
 814          *********************************************************************************************************
 815          *                                             STACK CHECKING
 816          *
 817          * Description: This function is called to check the amount of free memory left on the specified task's
 818          *              stack.
 819          *
 820          * Arguments  : prio          is the task priority
 821          *
 822          *              p_stk_data    is a pointer to a data structure of type OS_STK_DATA.
 823          *
 824          * Returns    : OS_ERR_NONE            upon success
 825          *              OS_ERR_PRIO_INVALID    if the priority you specify is higher that the maximum allowed
 826          *                                     (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 827          *              OS_ERR_TASK_NOT_EXIST  if the desired task has not been created or is assigned to a Mutex P
             -IP
 828          *              OS_ERR_TASK_OPT        if you did NOT specified OS_TASK_OPT_STK_CHK when the task was creat
             -ed
 829          *              OS_ERR_PDATA_NULL      if 'p_stk_data' is a NULL pointer
 830          *********************************************************************************************************
 831          */
 832          #if OS_TASK_CREATE_EXT_EN > 0
 833          INT8U  OSTaskStkChk (INT8U prio, OS_STK_DATA *p_stk_data) reentrant
 834          {
 835   1          OS_TCB    *ptcb;
 836   1          OS_STK    *pchk;
 837   1          INT32U     free;
 838   1          INT32U     size;
 839   1      #if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register     */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 842   1      
 843   1      
 844   1      
 845   1      #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'                        */
C51 COMPILER V7.50   OS_TASK                                                               12/14/2007 08:25:42 PAGE 15  

                      return (OS_ERR_PDATA_NULL);
                  }
              #endif
 855   1          p_stk_data->OSFree = 0;                            /* Assume failure, set to 0 size                */
 856   1          p_stk_data->OSUsed = 0;
 857   1          OS_ENTER_CRITICAL();
 858   1          if (prio == OS_PRIO_SELF) {                        /* See if check for SELF                        */
 859   2              prio = OSTCBCur->OSTCBPrio;
 860   2          }
 861   1          ptcb = OSTCBPrioTbl[prio];
 862   1          if (ptcb == (OS_TCB *)0) {                         /* Make sure task exist                         */
 863   2              OS_EXIT_CRITICAL();
 864   2              return (OS_ERR_TASK_NOT_EXIST);
 865   2          }
 866   1          if (ptcb == OS_TCB_RESERVED) {
 867   2              OS_EXIT_CRITICAL();
 868   2              return (OS_ERR_TASK_NOT_EXIST);
 869   2          }
 870   1          if ((ptcb->OSTCBOpt & OS_TASK_OPT_STK_CHK) == 0) { /* Make sure stack checking option is set       */
 871   2              OS_EXIT_CRITICAL();
 872   2              return (OS_ERR_TASK_OPT);
 873   2          }
 874   1          free = 0;
 875   1          size = ptcb->OSTCBStkSize;
 876   1          pchk = ptcb->OSTCBStkBottom;
 877   1          OS_EXIT_CRITICAL();
 878   1      #if OS_STK_GROWTH == 1
                  while (*pchk++ == (OS_STK)0) {                    /* Compute the number of zero entries on the stk */
                      free++;
                  }
              #else
 883   1          while (*pchk-- == (OS_STK)0) {
 884   2              free++;
 885   2          }
 886   1      #endif
 887   1          p_stk_data->OSFree = free * sizeof(OS_STK);           /* Compute number of free bytes on the stack */
 888   1          p_stk_data->OSUsed = (size - free) * sizeof(OS_STK);  /* Compute number of bytes used on the stack */
 889   1          return (OS_ERR_NONE);
 890   1      }
 891          #endif
 892          /*$PAGE*/
 893          /*
 894          *********************************************************************************************************
 895          *                                            SUSPEND A TASK
 896          *
 897          * Description: This function is called to suspend a task.  The task can be the calling task if the
 898          *              priority passed to OSTaskSuspend() is the priority of the calling task or OS_PRIO_SELF.
 899          *
 900          * Arguments  : prio     is the priority of the task to suspend.  If you specify OS_PRIO_SELF, the
 901          *                       calling task will suspend itself and rescheduling will occur.
 902          *
 903          * Returns    : OS_ERR_NONE               if the requested task is suspended
 904          *              OS_ERR_TASK_SUSPEND_IDLE  if you attempted to suspend the idle task which is not allowed.
 905          *              OS_ERR_PRIO_INVALID       if the priority you specify is higher that the maximum allowed
 906          *                                        (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 907          *              OS_ERR_TASK_SUSPEND_PRIO  if the task to suspend does not exist
 908          *              OS_ERR_TASK_NOT_EXITS     if the task is assigned to a Mutex PIP
 909          *
 910          * Note       : You should use this function with great care.  If you suspend a task that is waiting for
 911          *              an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from
 912          *              running when the event arrives.
 913          *********************************************************************************************************
C51 COMPILER V7.50   OS_TASK                                                               12/14/2007 08:25:42 PAGE 16  

 914          */
 915          
 916          #if OS_TASK_SUSPEND_EN > 0
 917          INT8U  OSTaskSuspend (INT8U prio) reentrant
 918          {
 919   1          BOOLEAN    self;
 920   1          OS_TCB    *ptcb;
 921   1          INT8U      y;
 922   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 925   1      
 926   1      
 927   1      
 928   1      #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
 938   1          OS_ENTER_CRITICAL();
 939   1          if (prio == OS_PRIO_SELF) {                                 /* See if suspend SELF                 */
 940   2              prio = OSTCBCur->OSTCBPrio;
 941   2              self = OS_TRUE;
 942   2          } else if (prio == OSTCBCur->OSTCBPrio) {                   /* See if suspending self              */
 943   2              self = OS_TRUE;
 944   2          } else {
 945   2              self = OS_FALSE;                                        /* No suspending another task          */
 946   2          }
 947   1          ptcb = OSTCBPrioTbl[prio];
 948   1          if (ptcb == (OS_TCB *)0) {                                  /* Task to suspend must exist          */
 949   2              OS_EXIT_CRITICAL();
 950   2              return (OS_ERR_TASK_SUSPEND_PRIO);
 951   2          }
 952   1          if (ptcb == OS_TCB_RESERVED) {                              /* See if assigned to Mutex            */
 953   2              OS_EXIT_CRITICAL();
 954   2              return (OS_ERR_TASK_NOT_EXIST);
 955   2          }
 956   1          y            = ptcb->OSTCBY;
 957   1          OSRdyTbl[y] &= ~ptcb->OSTCBBitX;                            /* Make task not ready                 */
 958   1          if (OSRdyTbl[y] == 0) {
 959   2              OSRdyGrp &= ~ptcb->OSTCBBitY;
 960   2          }
 961   1          ptcb->OSTCBStat |= OS_STAT_SUSPEND;                         /* Status of task is 'SUSPENDED'       */
 962   1          OS_EXIT_CRITICAL();
 963   1          if (self == OS_TRUE) {                                      /* Context switch only if SELF         */
 964   2              OS_Sched();                                             /* Find new highest priority task      */
 965   2          }
 966   1          return (OS_ERR_NONE);
 967   1      }
 968          #endif
 969          /*$PAGE*/
 970          /*
 971          *********************************************************************************************************
 972          *                                            QUERY A TASK
 973          *
 974          * Description: This function is called to obtain a copy of the desired task's TCB.
 975          *
C51 COMPILER V7.50   OS_TASK                                                               12/14/2007 08:25:42 PAGE 17  

 976          * Arguments  : prio         is the priority of the task to obtain information from.
 977          *
 978          *              p_task_data  is a pointer to where the desired task's OS_TCB will be stored.
 979          *
 980          * Returns    : OS_ERR_NONE            if the requested task is suspended
 981          *              OS_ERR_PRIO_INVALID    if the priority you specify is higher that the maximum allowed
 982          *                                     (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 983          *              OS_ERR_PRIO            if the desired task has not been created
 984          *              OS_ERR_TASK_NOT_EXIST  if the task is assigned to a Mutex PIP
 985          *              OS_ERR_PDATA_NULL      if 'p_task_data' is a NULL pointer
 986          *********************************************************************************************************
 987          */
 988          
 989          #if OS_TASK_QUERY_EN > 0
 990          INT8U  OSTaskQuery (INT8U prio, OS_TCB *p_task_data) reentrant
 991          {
 992   1          OS_TCB    *ptcb;
 993   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 996   1      
 997   1      
 998   1      
 999   1      #if OS_ARG_CHK_EN > 0
                  if (prio > OS_LOWEST_PRIO) {                 /* Task priority valid ?                              */
                      if (prio != OS_PRIO_SELF) {
                          return (OS_ERR_PRIO_INVALID);
                      }
                  }
                  if (p_task_data == (OS_TCB *)0) {            /* Validate 'p_task_data'                             */
                      return (OS_ERR_PDATA_NULL);
                  }
              #endif
1009   1          OS_ENTER_CRITICAL();
1010   1          if (prio == OS_PRIO_SELF) {                  /* See if suspend SELF                                */
1011   2              prio = OSTCBCur->OSTCBPrio;
1012   2          }
1013   1          ptcb = OSTCBPrioTbl[prio];
1014   1          if (ptcb == (OS_TCB *)0) {                   /* Task to query must exist                           */
1015   2              OS_EXIT_CRITICAL();
1016   2              return (OS_ERR_PRIO);
1017   2          }
1018   1          if (ptcb == OS_TCB_RESERVED) {               /* Task to query must not be assigned to a Mutex      */
101

⌨️ 快捷键说明

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