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

📄 os_task.lst

📁 在51上运行的小的OS系统
💻 LST
📖 第 1 页 / 共 5 页
字号:
 742          
 743          #if OS_ARG_CHK_EN > 0
 744              if (prio >= OS_LOWEST_PRIO) {                             /* Make sure task priority is valid      */
 745                  return (OS_PRIO_INVALID);
 746              }
 747          #endif
 748              OS_ENTER_CRITICAL();
 749              ptcb = OSTCBPrioTbl[prio];
 750              if (ptcb == (OS_TCB *)0) {                                /* Task to suspend must exist            */
 751                  OS_EXIT_CRITICAL();
 752                  return (OS_TASK_RESUME_PRIO);
 753              }
 754              if (ptcb == (OS_TCB *)1) {                                /* See if assigned to Mutex              */
 755                  OS_EXIT_CRITICAL();
 756                  return (OS_TASK_NOT_EXIST);
 757              }
 758              if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) { /* Task must be suspended                */
 759                  ptcb->OSTCBStat &= ~OS_STAT_SUSPEND;                  /* Remove suspension                     */
 760                  if (ptcb->OSTCBStat == OS_STAT_RDY) {                 /* See if task is now ready              */
 761                      if (ptcb->OSTCBDly == 0) {
 762                          OSRdyGrp               |= ptcb->OSTCBBitY;    /* Yes, Make task ready to run           */
 763                          OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
 764                          OS_EXIT_CRITICAL();
 765                          OS_Sched();
 766                      } else {
 767                          OS_EXIT_CRITICAL();
 768                      }
 769                  } else {                                              /* Must be pending on event              */
 770                      OS_EXIT_CRITICAL();
 771                  }
 772                  return (OS_NO_ERR);
 773              }
 774              OS_EXIT_CRITICAL();
 775              return (OS_TASK_NOT_SUSPENDED);
 776          }
 777          #endif
 778          /*$PAGE*/
 779          /*
 780          *********************************************************************************************************
 781          *                                             STACK CHECKING
 782          *
 783          * Description: This function is called to check the amount of free memory left on the specified task's
 784          *              stack.
 785          *
 786          * Arguments  : prio          is the task priority
 787          *
 788          *              p_stk_data    is a pointer to a data structure of type OS_STK_DATA.
 789          *
 790          * Returns    : OS_NO_ERR           upon success
 791          *              OS_PRIO_INVALID     if the priority you specify is higher that the maximum allowed
 792          *                                  (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 793          *              OS_TASK_NOT_EXIST   if the desired task has not been created or is assigned to a Mutex PIP
 794          *              OS_TASK_OPT_ERR     if you did NOT specified OS_TASK_OPT_STK_CHK when the task was created
 795          *              OS_ERR_PDATA_NULL   if 'p_stk_data' is a NULL pointer
 796          *********************************************************************************************************
 797          */
 798          #if OS_TASK_CREATE_EXT_EN > 0
 799          INT8U  OSTaskStkChk (INT8U prio, OS_STK_DATA *p_stk_data)
 800          {
 801              OS_TCB    *ptcb;
C51 COMPILER V8.08   OS_TASK                                                               08/04/2008 21:49:52 PAGE 15  

 802              OS_STK    *pchk;
 803              INT32U     free;
 804              INT32U     size;
 805          #if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register     */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 808          
 809          
 810          
 811          #if OS_ARG_CHK_EN > 0
 812              if (prio > OS_LOWEST_PRIO) {                       /* Make sure task priority is valid             */
 813                  if (prio != OS_PRIO_SELF) {
 814                      return (OS_PRIO_INVALID);
 815                  }
 816              }
 817              if (p_stk_data == (OS_STK_DATA *)0) {              /* Validate 'p_stk_data'                        */
 818                  return (OS_ERR_PDATA_NULL);
 819              }
 820          #endif
 821              p_stk_data->OSFree = 0;                            /* Assume failure, set to 0 size                */
 822              p_stk_data->OSUsed = 0;
 823              OS_ENTER_CRITICAL();
 824              if (prio == OS_PRIO_SELF) {                        /* See if check for SELF                        */
 825                  prio = OSTCBCur->OSTCBPrio;
 826              }
 827              ptcb = OSTCBPrioTbl[prio];
 828              if (ptcb == (OS_TCB *)0) {                         /* Make sure task exist                         */
 829                  OS_EXIT_CRITICAL();
 830                  return (OS_TASK_NOT_EXIST);
 831              }
 832              if (ptcb == (OS_TCB *)1) {
 833                  OS_EXIT_CRITICAL();
 834                  return (OS_TASK_NOT_EXIST);
 835              }
 836              if ((ptcb->OSTCBOpt & OS_TASK_OPT_STK_CHK) == 0) { /* Make sure stack checking option is set       */
 837                  OS_EXIT_CRITICAL();
 838                  return (OS_TASK_OPT_ERR);
 839              }
 840              free = 0;
 841              size = ptcb->OSTCBStkSize;
 842              pchk = ptcb->OSTCBStkBottom;
 843              OS_EXIT_CRITICAL();
 844          #if OS_STK_GROWTH == 1
 845              while (*pchk++ == (OS_STK)0) {                    /* Compute the number of zero entries on the stk */
 846                  free++;
 847              }
 848          #else
                  while (*pchk-- == (OS_STK)0) {
                      free++;
                  }
              #endif
 853              p_stk_data->OSFree = free * sizeof(OS_STK);           /* Compute number of free bytes on the stack */
 854              p_stk_data->OSUsed = (size - free) * sizeof(OS_STK);  /* Compute number of bytes used on the stack */
 855              return (OS_NO_ERR);
 856          }
 857          #endif
 858          /*$PAGE*/
 859          /*
 860          *********************************************************************************************************
 861          *                                            SUSPEND A TASK
 862          *
 863          * Description: This function is called to suspend a task.  The task can be the calling task if the
C51 COMPILER V8.08   OS_TASK                                                               08/04/2008 21:49:52 PAGE 16  

 864          *              priority passed to OSTaskSuspend() is the priority of the calling task or OS_PRIO_SELF.
 865          *
 866          * Arguments  : prio     is the priority of the task to suspend.  If you specify OS_PRIO_SELF, the
 867          *                       calling task will suspend itself and rescheduling will occur.
 868          *
 869          * Returns    : OS_NO_ERR                if the requested task is suspended
 870          *              OS_TASK_SUSPEND_IDLE     if you attempted to suspend the idle task which is not allowed.
 871          *              OS_PRIO_INVALID          if the priority you specify is higher that the maximum allowed
 872          *                                       (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 873          *              OS_TASK_SUSPEND_PRIO     if the task to suspend does not exist
 874          *              OS_TASK_NOT_EXITS        if the task is assigned to a Mutex PIP
 875          *
 876          * Note       : You should use this function with great care.  If you suspend a task that is waiting for
 877          *              an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from
 878          *              running when the event arrives.
 879          *********************************************************************************************************
 880          */
 881          
 882          #if OS_TASK_SUSPEND_EN > 0
 883          INT8U  OSTaskSuspend (INT8U prio)
 884          {
 885              BOOLEAN    self;
 886              OS_TCB    *ptcb;
 887              INT8U      y;
 888          #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 891          
 892          
 893          
 894          #if OS_ARG_CHK_EN > 0
 895              if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to suspend idle task    */
 896                  return (OS_TASK_SUSPEND_IDLE);
 897              }
 898              if (prio >= OS_LOWEST_PRIO) {                                /* Task priority valid ?               */
 899                  if (prio != OS_PRIO_SELF) {
 900                      return (OS_PRIO_INVALID);
 901                  }
 902              }
 903          #endif
 904              OS_ENTER_CRITICAL();
 905              if (prio == OS_PRIO_SELF) {                                 /* See if suspend SELF                 */
 906                  prio = OSTCBCur->OSTCBPrio;
 907                  self = TRUE;
 908              } else if (prio == OSTCBCur->OSTCBPrio) {                   /* See if suspending self              */
 909                  self = TRUE;
 910              } else {
 911                  self = FALSE;                                           /* No suspending another task          */
 912              }
 913              ptcb = OSTCBPrioTbl[prio];
 914              if (ptcb == (OS_TCB *)0) {                                  /* Task to suspend must exist          */
 915                  OS_EXIT_CRITICAL();
 916                  return (OS_TASK_SUSPEND_PRIO);
 917              }
 918              if (ptcb == (OS_TCB *)1) {                                  /* See if assigned to Mutex            */
 919                  OS_EXIT_CRITICAL();
 920                  return (OS_TASK_NOT_EXIST);
 921              }
 922              y            = ptcb->OSTCBY;
 923              OSRdyTbl[y] &= ~ptcb->OSTCBBitX;                            /* Make task not ready                 */
 924              if (OSRdyTbl[y] == 0) {
 925                  OSRdyGrp &= ~ptcb->OSTCBBitY;
C51 COMPILER V8.08   OS_TASK                                                               08/04/2008 21:49:52 PAGE 17  

 926              }
 927              ptcb->OSTCBStat |= OS_STAT_SUSPEND;                         /* Status of task is 'SUSPENDED'       */
 928              OS_EXIT_CRITICAL();
 929              if (self == TRUE) {                                         /* Context switch only if SELF         */
 930                  OS_Sched();
 931              }
 932              return (OS_NO_ERR);
 933          }
 934          #endif
 935          /*$PAGE*/
 936          /*
 937          *********************************************************************************************************
 938          *                                            QUERY A TASK
 939          *
 940          * Description: This function is called to o

⌨️ 快捷键说明

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