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

📄 os_core.lst

📁 在C8051F060上实现嵌入式系统ucos
💻 LST
📖 第 1 页 / 共 5 页
字号:
             -   */
 837   2              ptcb1->OSTCBNext = ptcb2;
 838   2              ptcb1++;
 839   2              ptcb2++;
 840   2          }
 841   1          ptcb1->OSTCBNext = (OS_TCB *)0;                              /* Last OS_TCB                           
             -   */
 842   1          OSTCBFreeList    = &OSTCBTbl[0];
 843   1      }
 844          /*$PAGE*/
 845          /*
 846          *********************************************************************************************************
 847          *                                              SCHEDULER
 848          *
 849          * Description: This function is called by other uC/OS-II services to determine whether a new, high
 850          *              priority task has been made ready to run.  This function is invoked by TASK level code
 851          *              and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
 852          *
 853          * Arguments  : none
 854          *
 855          * Returns    : none
 856          *
 857          * Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
 858          *              2) Rescheduling is prevented when the scheduler is locked (see OS_SchedLock())
 859          *********************************************************************************************************
 860          */
 861          
 862          void  OS_Sched (void)   reentrant
 863          {
 864   1        
 865   1          INT8U      y;
 866   1      
C51 COMPILER V8.08   OS_CORE                                                               03/02/2009 10:42:35 PAGE 16  

 867   1      
 868   1          OS_ENTER_CRITICAL();
 869   1          if ((OSIntNesting == 0) && (OSLockNesting == 0)) { /* Sched. only if all ISRs done & not locked    */
 870   2              y             = OSUnMapTbl[OSRdyGrp];          /* Get pointer to HPT ready to run              */
 871   2              OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
 872   2              if (OSPrioHighRdy != OSPrioCur) {              /* No Ctx Sw if current task is highest rdy     */
 873   3                  OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
 874   3                  OSCtxSwCtr++;                              /* Increment context switch counter             */
 875   3                  OS_TASK_SW();                              /* Perform a context switch                     */
 876   3              }
 877   2          }
 878   1          OS_EXIT_CRITICAL();
 879   1      }
 880          /*$PAGE*/
 881          /*
 882          *********************************************************************************************************
 883          *                                              IDLE TASK
 884          *
 885          * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
 886          *              executes because they are ALL waiting for event(s) to occur.
 887          *
 888          * Arguments  : none
 889          *
 890          * Returns    : none
 891          *
 892          * Note(s)    : 1) OSTaskIdleHook() is called after the critical section to ensure that interrupts will be
 893          *                 enabled for at least a few instructions.  On some processors (ex. Philips XA), enabling
 894          *                 and then disabling interrupts didn't allow the processor enough time to have interrupts
 895          *                 enabled before they were disabled again.  uC/OS-II would thus never recognize
 896          *                 interrupts.
 897          *              2) This hook has been added to allow you to do such things as STOP the CPU to conserve 
 898          *                 power.
 899          *********************************************************************************************************
 900          */
 901          
 902          void  OS_TaskIdle (void *ppdata)reentrant
 903          {        
 904   1          
 905   1          ppdata = ppdata;                               /* Prevent compiler warning for not using 'pdata'     *
             -/
 906   1          for (;;) {
 907   2              OS_ENTER_CRITICAL();
 908   2              OSIdleCtr++;
 909   2              OS_EXIT_CRITICAL();
 910   2              OSTaskIdleHook();                        /* Call user definable HOOK                           */
 911   2          }
 912   1      }
 913          /*$PAGE*/
 914          /*
 915          *********************************************************************************************************
 916          *                                            STATISTICS TASK
 917          *
 918          * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
 919          *              multitasking environment.  Specifically, OS_TaskStat() computes the CPU usage.
 920          *              CPU usage is determined by:
 921          *
 922          *                                          OSIdleCtr
 923          *                 OSCPUUsage = 100 * (1 - ------------)     (units are in %)
 924          *                                         OSIdleCtrMax
 925          *
 926          * Arguments  : pdata     this pointer is not used at this time.
 927          *
C51 COMPILER V8.08   OS_CORE                                                               03/02/2009 10:42:35 PAGE 17  

 928          * Returns    : none
 929          *
 930          * Notes      : 1) This task runs at a priority level higher than the idle task.  In fact, it runs at the
 931          *                 next higher priority, OS_IDLE_PRIO-1.
 932          *              2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
 933          *              3) We delay for 5 seconds in the beginning to allow the system to reach steady state and
 934          *                 have all other tasks created before we do statistics.  You MUST have at least a delay
 935          *                 of 2 seconds to allow for the system to establish the maximum value for the idle
 936          *                 counter.
 937          *********************************************************************************************************
 938          */
 939          
 940          #if OS_TASK_STAT_EN > 0
              void  OS_TaskStat (void *ppdata) reentrant
              {
                 
                  INT32U     run;
                  INT32U     max;
                  INT8S      usage;
              
              
                  ppdata = ppdata;                               /* Prevent compiler warning for not using 'pdata'     *
             -/
                  while (OSStatRdy == FALSE) {
                      OSTimeDly(2 * OS_TICKS_PER_SEC);         /* Wait until statistic task is ready                 */
                  }
                  max = OSIdleCtrMax / 100L;
                  for (;;) {
                      OS_ENTER_CRITICAL();
                      OSIdleCtrRun = OSIdleCtr;                /* Obtain the of the idle counter for the past second */
                      run          = OSIdleCtr;
                      OSIdleCtr    = 0L;                       /* Reset the idle counter for the next second         */
                      OS_EXIT_CRITICAL();
                      if (max > 0L) {
                          usage = (INT8S)(100L - run / max);
                          if (usage >= 0) {                    /* Make sure we don't have a negative percentage      */
                              OSCPUUsage = usage;
                          } else {
                              OSCPUUsage = 0;
                          }
                      } else {
                          OSCPUUsage = 0;
                          max        = OSIdleCtrMax / 100L;
                      }
                      OSTaskStatHook();                        /* Invoke user definable hook                         */
                      OSTimeDly(OS_TICKS_PER_SEC);             /* Accumulate OSIdleCtr for the next second           */
                  }
              }
              #endif
 976          /*$PAGE*/
 977          /*
 978          *********************************************************************************************************
 979          *                                            INITIALIZE TCB
 980          *
 981          * Description: This function is internal to uC/OS-II and is used to initialize a Task Control Block when
 982          *              a task is created (see OSTaskCreate() and OSTaskCreateExt()).
 983          *
 984          * Arguments  : prio          is the priority of the task being created
 985          *
 986          *              ptos          is a pointer to the task's top-of-stack assuming that the CPU registers
 987          *                            have been placed on the stack.  Note that the top-of-stack corresponds to a
 988          *                            'high' memory location is OS_STK_GROWTH is set to 1 and a 'low' memory
C51 COMPILER V8.08   OS_CORE                                                               03/02/2009 10:42:35 PAGE 18  

 989          *                            location if OS_STK_GROWTH is set to 0.  Note that stack growth is CPU
 990          *                            specific.
 991          *
 992          *              pbos          is a pointer to the bottom of stack.  A NULL pointer is passed if called by
 993          *                            'OSTaskCreate()'.
 994          *
 995          *              id            is the task's ID (0..65535)
 996          *
 997          *              stk_size      is the size of the stack (in 'stack units').  If the stack units are INT8Us
 998          *                            then, 'stk_size' contains the number of bytes for the stack.  If the stack
 999          *                            units are INT32Us then, the stack contains '4 * stk_size' bytes.  The stack
1000          *                            units are established by the #define constant OS_STK which is CPU
1001          *                            specific.  'stk_size' is 0 if called by 'OSTaskCreate()'.
1002          *
1003          *              pext          is a pointer to a user supplied memory area that is used to extend the task
1004          *                            control block.  This allows you to store the contents of floating-point
1005          *                            registers, MMU registers or anything else you could find useful during a
1006          *                            context switch.  You can even assign a name to each task and store this name
1007          *                            in this TCB extension.  A NULL pointer is passed if called by OSTaskCreate().
1008          *
1009          *              opt           options as passed to 'OSTaskCreateExt()' or,
1010          *                            0 if called from 'OSTaskCreate()'.
1011          *
1012          * Returns    : OS_NO_ERR         if the call was successful
1013          *              OS_NO_MORE_TCB    if there are no more free TCBs to be allocated and thus, the task cannot
1014          *                                be created.
1015          *
1016          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
1017          *********************************************************************************************************
1018          */
1019          
1020          INT8U  OS_TCBInit (INT8U prio, OS_STK *ptos, OS_STK *pbos, INT16U id, INT32U stk_size, void *pext, INT16U 
             -opt) reentrant
1021          {
1022   1         
1023   1          OS_TCB    *ptcb;
1024   1      
1025   1      
1026   1          OS_ENTER_CRITICAL();
1027   1          ptcb = OSTCBFreeList;                                  /* Get a free TCB from the free TCB list    */
1028   1          if (ptcb != (OS_TCB *)0) {
1029   2              OSTCBFreeList        = ptcb->OSTCBNext;            /* Update pointer to free TCB list          */
1030   2              OS_EXIT_CRITICAL();
1031   2              ptcb->OSTCBStkPtr    = ptos;                       /* Load Stack pointer in TCB                */
1032   2              ptcb->OSTCBPrio      = (INT8U)prio;                /* Load task priority into TCB              */
1033   2              ptcb->OSTCBStat      = OS_STAT_RDY;                /* Task is ready to run                     */
1034   2              ptcb->OSTCBDly       = 0;                          /* Task is not delayed                      */
1035   2      
1036   2      #if OS_TASK_CREATE_EXT_EN > 0
                      ptcb->OSTCBExtPtr    = pext;                       /* Store pointer to TCB extension           */
                      ptcb->OSTCBStkSize   = stk_size;                   /* Store stack size                         */
                      ptcb->OSTCBStkBottom = pbos;                       /* Store pointer to bottom of stack         */
                      ptcb->OSTCBOpt       = opt;                        /* Store task options                       */
                      ptcb->OSTCBId        = id;                         /* Store task ID                            */
              #else
1043   2              pext                 = pext;                       /* Prevent compiler warning if not used     */
1044   2              stk_size             = stk_size;
1045   2              pbos                 = pbos;
1046   2              opt                  = opt;
1047   2              id                   = id;
1048   2      #endif
1049   2      
C51 COMPILER V8.08   OS_CORE                                                               03/02/2009 10:42:35 PAGE 19  

1050   2      #if OS_TASK_DEL_EN > 0
                      ptcb->OSTCBD

⌨️ 快捷键说明

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