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

📄 os_core.lst

📁 一个基于C51指令系统的简易uCOS示范程序,有完整的代码分析
💻 LST
📖 第 1 页 / 共 4 页
字号:
                  
                  ppdata = ppdata;                               /* Prevent compiler warning for not using 'pdata'     *
             -/
                  while (OSStatRdy == FALSE) {
                      OSTimeDly(2 * OS_TICKS_PER_SEC);             /* Wait until statistic task is ready                
             - */
                  }
                  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 (OSIdleCtrMax > 0L) {
                          usage = (INT8S)(100L - 100L * run / OSIdleCtrMax);
                          if (usage > 100) {
                              OSCPUUsage = 100;
                          } else if (usage < 0) {
                              OSCPUUsage =   0;
                          } else {
                              OSCPUUsage = usage;
                          }
                      } else {
                          OSCPUUsage = 0;
                      }
                      OSTaskStatHook();                        /* Invoke user definable hook                         */
                      OSTimeDly(OS_TICKS_PER_SEC);             /* Accumulate OSIdleCtr for the next second           */
                  }
              }
              #endif
 661          /*$PAGE*/
 662          /*
 663          *********************************************************************************************************
 664          *                                            INITIALIZE TCB
 665          *
 666          * Description: This function is internal to uC/OS-II and is used to initialize a Task Control Block when
 667          *              a task is created (see OSTaskCreate() and OSTaskCreateExt()).
 668          *
 669          * Arguments  : prio          is the priority of the task being created
 670          *
 671          *              ptos          is a pointer to the task's top-of-stack assuming that the CPU registers
C51 COMPILER V7.07   OS_CORE                                                               05/31/2008 20:36:05 PAGE 12  

 672          *                            have been placed on the stack.  Note that the top-of-stack corresponds to a 
 673          *                            'high' memory location is OS_STK_GROWTH is set to 1 and a 'low' memory
 674          *                            location if OS_STK_GROWTH is set to 0.  Note that stack growth is CPU
 675          *                            specific.
 676          *
 677          *              pbos          is a pointer to the bottom of stack.  A NULL pointer is passed if called by
 678          *                            'OSTaskCreate()'.
 679          *
 680          *              id            is the task's ID (0..65535)
 681          *
 682          *              stk_size      is the size of the stack (in 'stack units').  If the stack units are INT8Us
 683          *                            then, 'stk_size' contains the number of bytes for the stack.  If the stack
 684          *                            units are INT32Us then, the stack contains '4 * stk_size' bytes.  The stack
 685          *                            units are established by the #define constant OS_STK which is CPU
 686          *                            specific.  'stk_size' is 0 if called by 'OSTaskCreate()'.
 687          *
 688          *              pext          is a pointer to a user supplied memory area that is used to extend the task
 689          *                            control block.  This allows you to store the contents of floating-point
 690          *                            registers, MMU registers or anything else you could find useful during a 
 691          *                            context switch.  You can even assign a name to each task and store this name
 692          *                            in this TCB extension.  A NULL pointer is passed if called by OSTaskCreate().
 693          *
 694          *              opt           options as passed to 'OSTaskCreateExt()' or, 
 695          *                            0 if called from 'OSTaskCreate()'.
 696          *
 697          * Returns    : OS_NO_ERR         if the call was successful
 698          *              OS_NO_MORE_TCB    if there are no more free TCBs to be allocated and thus, the task cannot
 699          *                                be created.
 700          *
 701          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
 702          *********************************************************************************************************
 703          */
 704          
 705          INT8U OSTCBInit (INT8U prio, OS_STK *ptos, OS_STK *pbos, INT16U id, INT16U stk_size, void *pext, INT16U op
             -t) reentrant
 706          {
 707   1          OS_TCB *ptcb;
 708   1      
 709   1      
 710   1          OS_ENTER_CRITICAL();
 711   1          ptcb = OSTCBFreeList;                                  /* Get a free TCB from the free TCB list    */
 712   1          if (ptcb != (OS_TCB *)0) {
 713   2              OSTCBFreeList        = ptcb->OSTCBNext;            /* Update pointer to free TCB list          */
 714   2              OS_EXIT_CRITICAL();
 715   2              ptcb->OSTCBStkPtr    = ptos;                       /* Load Stack pointer in TCB                */
 716   2              ptcb->OSTCBPrio      = (INT8U)prio;                /* Load task priority into TCB              */
 717   2              ptcb->OSTCBStat      = OS_STAT_RDY;                /* Task is ready to run                     */
 718   2              ptcb->OSTCBDly       = 0;                          /* Task is not delayed                      */
 719   2      
 720   2      #if OS_TASK_CREATE_EXT_EN        
                      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
 727   2              pext                 = pext;                       /* Prevent compiler warning if not used     */
 728   2              stk_size             = stk_size;
 729   2              pbos                 = pbos;
 730   2              opt                  = opt;
 731   2              id                   = id;
 732   2      #endif
C51 COMPILER V7.07   OS_CORE                                                               05/31/2008 20:36:05 PAGE 13  

 733   2      
 734   2      #if OS_TASK_DEL_EN        
                      ptcb->OSTCBDelReq    = OS_NO_ERR;
              #endif
 737   2      
 738   2              ptcb->OSTCBY         = prio >> 3;                  /* Pre-compute X, Y, BitX and BitY          */
 739   2              ptcb->OSTCBBitY      = OSMapTbl[ptcb->OSTCBY];
 740   2              ptcb->OSTCBX         = prio & 0x07;
 741   2              ptcb->OSTCBBitX      = OSMapTbl[ptcb->OSTCBX];
 742   2      
 743   2      #if     OS_MBOX_EN || (OS_Q_EN && (OS_MAX_QS >= 2)) || OS_SEM_EN
 744   2              ptcb->OSTCBEventPtr  = (OS_EVENT *)0;              /* Task is not pending on an event          */
 745   2      #endif
 746   2      
 747   2      #if     OS_MBOX_EN || (OS_Q_EN && (OS_MAX_QS >= 2))
 748   2              ptcb->OSTCBMsg       = (void *)0;                  /* No message received                      */
 749   2      #endif
 750   2      
 751   2              OS_ENTER_CRITICAL();
 752   2              OSTCBPrioTbl[prio]   = ptcb;
 753   2              ptcb->OSTCBNext      = OSTCBList;                  /* Link into TCB chain                      */
 754   2              ptcb->OSTCBPrev      = (OS_TCB *)0;
 755   2              if (OSTCBList != (OS_TCB *)0) {
 756   3                  OSTCBList->OSTCBPrev = ptcb;
 757   3              }
 758   2              OSTCBList               = ptcb;
 759   2              OSRdyGrp               |= ptcb->OSTCBBitY;         /* Make task ready to run                   */
 760   2              OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
 761   2              OS_EXIT_CRITICAL();
 762   2              return (OS_NO_ERR);
 763   2          } else {
 764   2              OS_EXIT_CRITICAL();
 765   2              return (OS_NO_MORE_TCB);
 766   2          }
 767   1      }
 768          /*$PAGE*/
 769          /*
 770          *********************************************************************************************************
 771          *                                         PROCESS SYSTEM TICK
 772          *
 773          * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
 774          *              as a 'clock tick').  This function should be called by the ticker ISR but, can also be
 775          *              called by a high priority task.
 776          *
 777          * Arguments  : none
 778          *
 779          * Returns    : none
 780          *********************************************************************************************************
 781          */
 782          
 783          void OSTimeTick (void) reentrant
 784          {
 785   1          OS_TCB *ptcb;
 786   1      
 787   1      
 788   1          OSTimeTickHook();                                      /* Call user definable hook                 */
 789   1          ptcb = OSTCBList;                                      /* Point at first TCB in TCB list           */
 790   1          while (ptcb->OSTCBPrio != OS_IDLE_PRIO) {              /* Go through all TCBs in TCB list          */
 791   2              OS_ENTER_CRITICAL();
 792   2              if (ptcb->OSTCBDly != 0) {                         /* Delayed or waiting for event with TO     */
 793   3                  if (--ptcb->OSTCBDly == 0) {                   /* Decrement nbr of ticks to end of delay   */
 794   4                      if (!(ptcb->OSTCBStat & OS_STAT_SUSPEND)) {    /* Is task suspended?                   */
C51 COMPILER V7.07   OS_CORE                                                               05/31/2008 20:36:05 PAGE 14  

 795   5                          OSRdyGrp               |= ptcb->OSTCBBitY; /* No,  Make task Rdy to Run (timed out)*/
 796   5                          OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
 797   5                      } else {                                       /* Yes, Leave 1 tick to prevent ...     */
 798   5                          ptcb->OSTCBDly = 1;                        /* ... loosing the task when the ...    */
 799   5                      }                                              /* ... suspension is removed.           */
 800   4                  }
 801   3              }
 802   2              ptcb = ptcb->OSTCBNext;                            /* Point at next TCB in TCB list            */
 803   2              OS_EXIT_CRITICAL();
 804   2          }
 805   1          OS_ENTER_CRITICAL();                                   /* Update the 32-bit tick counter           */
 806   1          OSTime++;
 807   1          OS_EXIT_CRITICAL();
 808   1      }
 809          /*$PAGE*/
 810          /*
 811          *********************************************************************************************************
 812          *                                             GET VERSION
 813          *
 814          * Description: This function is used to return the version number of uC/OS-II.  The returned value
 815          *              corresponds to uC/OS-II's version number multiplied by 100.  In other words, version 2.00
 816          *              would be returned as 200.
 817          *
 818          * Arguments  : none
 819          *
 820          * Returns    : the version number of uC/OS-II multiplied by 100.
 821          *********************************************************************************************************
 822          */
 823          
 824          INT16U OSVersion (void) reentrant
 825          {
 826   1          return (OS_VERSION);
 827   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   3176    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =    725    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =      9    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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