OS_CORE.lst
上传用户:tzjinxin1
上传日期:2022-08-08
资源大小:272k
文件大小:60k
开发平台:

Visual C++

  1. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 1   
  2. C51 COMPILER V8.02, COMPILATION OF MODULE OS_CORE
  3. OBJECT MODULE PLACED IN .objOS_CORE.obj
  4. COMPILER INVOKED BY: C:KeilC51BINC51.EXE uCosiiOS_CORE.C LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.lstOS_CORE.lst) O
  5.                     -BJECT(.objOS_CORE.obj)
  6. line level    source
  7.    1          /*
  8.    2          *********************************************************************************************************
  9.    3          *                                                uC/OS-II
  10.    4          *                                          The Real-Time Kernel
  11.    5          *                                             CORE FUNCTIONS
  12.    6          *
  13.    7          *                          (c) Copyright 1992-2001, Jean J. Labrosse, Weston, FL
  14.    8          *                                           All Rights Reserved
  15.    9          *
  16.   10          * File : OS_CORE.C
  17.   11          * By   : Jean J. Labrosse
  18.   12          *********************************************************************************************************
  19.   13          */
  20.   14          
  21.   15          #ifndef  OS_MASTER_FILE
  22.   16          #define  OS_GLOBALS
  23.   17          #include "sourceincludes.h"
  24.   18          #endif
  25.   19          
  26.   20          /*
  27.   21          *********************************************************************************************************
  28.   22          *                              MAPPING TABLE TO MAP BIT POSITION TO BIT MASK
  29.   23          *
  30.   24          * Note: Index into table is desired bit position, 0..7
  31.   25          *       Indexed value corresponds to bit mask
  32.   26          *********************************************************************************************************
  33.   27          */
  34.   28          
  35.   29          INT8U  const  OSMapTbl[]   = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
  36.   30          
  37.   31          /*
  38.   32          *********************************************************************************************************
  39.   33          *                                       PRIORITY RESOLUTION TABLE
  40.   34          *
  41.   35          * Note: Index into table is bit pattern to resolve highest priority
  42.   36          *       Indexed value corresponds to highest priority bit position (i.e. 0..7)
  43.   37          *********************************************************************************************************
  44.   38          */
  45.   39          
  46.   40          INT8U  const  OSUnMapTbl[] = {
  47.   41              0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  48.   42              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  49.   43              5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  50.   44              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  51.   45              6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  52.   46              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  53.   47              5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  54.   48              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  55.   49              7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  56.   50              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  57.   51              5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  58.   52              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  59.   53              6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  60.   54              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  61. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 2   
  62.   55              5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  63.   56              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
  64.   57          };
  65.   58          /*$PAGE*/
  66.   59          /*
  67.   60          *********************************************************************************************************
  68.   61          *                                             INITIALIZATION
  69.   62          *
  70.   63          * Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
  71.   64          *              creating any uC/OS-II object and, prior to calling OSStart().
  72.   65          *
  73.   66          * Arguments  : none
  74.   67          *
  75.   68          * Returns    : none
  76.   69          *********************************************************************************************************
  77.   70          */
  78.   71          
  79.   72          void  OSInit (void) reentrant
  80.   73          {
  81.   74   1          INT16U     i;
  82.   75   1          INT8U     *prdytbl;
  83.   76   1          OS_TCB    *ptcb1;
  84.   77   1          OS_TCB    *ptcb2;
  85.   78   1      #if (OS_EVENT_EN > 0) && (OS_MAX_EVENTS > 1)
  86.                   OS_EVENT  *pevent1;
  87.                   OS_EVENT  *pevent2;
  88.               #endif
  89.   82   1      
  90.   83   1      
  91.   84   1      #if OS_VERSION >= 204
  92.   85   1          OSInitHookBegin();                                           /* Call port specific initialization code
  93.              -   */
  94.   86   1      #endif
  95.   87   1      
  96.   88   1      #if OS_TIME_GET_SET_EN > 0   
  97.   89   1          OSTime        = 0L;                                          /* Clear the 32-bit system clock         
  98.              -   */
  99.   90   1      #endif
  100.   91   1          OSIntNesting  = 0;                                           /* Clear the interrupt nesting counter   
  101.              -   */
  102.   92   1          OSLockNesting = 0;                                           /* Clear the scheduling lock counter     
  103.              -   */
  104.   93   1          OSTaskCtr     = 0;                                           /* Clear the number of tasks             
  105.              -   */
  106.   94   1          OSRunning     = FALSE;                                       /* Indicate that multitasking not started
  107.              -   */
  108.   95   1          OSIdleCtr     = 0L;                                          /* Clear the 32-bit idle counter         
  109.              -   */
  110.   96   1      #if (OS_TASK_STAT_EN > 0) && (OS_TASK_CREATE_EXT_EN > 0)
  111.                   OSIdleCtrRun  = 0L;
  112.                   OSIdleCtrMax  = 0L;
  113.                   OSStatRdy     = FALSE;                                       /* Statistic task is not ready           
  114.              -   */
  115.               #endif
  116.  101   1          OSCtxSwCtr    = 0;                                           /* Clear the context switch counter      
  117.              -   */
  118.  102   1          OSRdyGrp      = 0x00;                                        /* Clear the ready list                  
  119.              -   */
  120.  103   1          prdytbl       = &OSRdyTbl[0];
  121.  104   1          for (i = 0; i < OS_RDY_TBL_SIZE; i++) {
  122.  105   2              *prdytbl++ = 0x00;
  123.  106   2          }
  124. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 3   
  125.  107   1      
  126.  108   1          OSPrioCur     = 0;
  127.  109   1          OSPrioHighRdy = 0;
  128.  110   1          OSTCBHighRdy  = (OS_TCB *)0;                                 /* TCB Initialization                    
  129.              -   */
  130.  111   1          OSTCBCur      = (OS_TCB *)0;
  131.  112   1          OSTCBList     = (OS_TCB *)0;
  132.  113   1          for (i = 0; i < (OS_LOWEST_PRIO + 1); i++) {                 /* Clear the priority table              
  133.              -   */
  134.  114   2              OSTCBPrioTbl[i] = (OS_TCB *)0;
  135.  115   2          }
  136.  116   1          ptcb1 = &OSTCBTbl[0];
  137.  117   1          ptcb2 = &OSTCBTbl[1];
  138.  118   1          for (i = 0; i < (OS_MAX_TASKS + OS_N_SYS_TASKS - 1); i++) {  /* Init. list of free TCBs               
  139.              -   */
  140.  119   2              ptcb1->OSTCBNext = ptcb2;
  141.  120   2              ptcb1++;
  142.  121   2              ptcb2++;
  143.  122   2          }
  144.  123   1          ptcb1->OSTCBNext = (OS_TCB *)0;                              /* Last OS_TCB                           
  145.              -   */
  146.  124   1          OSTCBFreeList    = &OSTCBTbl[0];
  147.  125   1      
  148.  126   1      #if (OS_EVENT_EN > 0) && (OS_MAX_EVENTS > 0)
  149.                   #if OS_MAX_EVENTS == 1                                       
  150.                   OSEventFreeList              = &OSEventTbl[0];               /* Only have ONE event control block     
  151.              -   */
  152.                   OSEventFreeList->OSEventType = OS_EVENT_TYPE_UNUSED;
  153.                   OSEventFreeList->OSEventPtr  = (OS_EVENT *)0;
  154.                   #else
  155.                   pevent1 = &OSEventTbl[0];
  156.                   pevent2 = &OSEventTbl[1];
  157.                   for (i = 0; i < (OS_MAX_EVENTS - 1); i++) {                  /* Init. list of free EVENT control block
  158.              -s  */
  159.                       pevent1->OSEventType = OS_EVENT_TYPE_UNUSED;
  160.                       pevent1->OSEventPtr  = pevent2;
  161.                       pevent1++;
  162.                       pevent2++;
  163.                   }
  164.                   pevent1->OSEventType = OS_EVENT_TYPE_UNUSED;
  165.                   pevent1->OSEventPtr  = (OS_EVENT *)0;
  166.                   OSEventFreeList      = &OSEventTbl[0];
  167.                   #endif
  168.               #endif
  169.  145   1      
  170.  146   1      #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
  171.                   OS_FlagInit();                                               /* Initialize the event flag structures  
  172.              -   */
  173.               #endif
  174.  149   1      
  175.  150   1      #if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
  176.                   OS_QInit();                                                  /* Initialize the message queue structure
  177.              -s  */
  178.               #endif
  179.  153   1      
  180.  154   1      #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
  181.                   OS_MemInit();                                                /* Initialize the memory manager         
  182.              -   */
  183.               #endif
  184.  157   1      
  185.  158   1          /* ------------------------------------- CREATION OF 'IDLE' TASK -------------------------------------
  186.              --- */
  187. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 4   
  188.  159   1      #if OS_TASK_CREATE_EXT_EN > 0
  189.                   #if OS_STK_GROWTH == 1
  190.                   (void)OSTaskCreateExt(OS_TaskIdle,
  191.                                         (void *)0,                                 /* No arguments passed to OS_TaskIdle
  192.              -() */
  193.                                         &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], /* Set Top-Of-Stack                  
  194.              -   */
  195.                                         OS_IDLE_PRIO,                              /* Lowest priority level             
  196.              -   */
  197.                                         OS_TASK_IDLE_ID,
  198.                                         &OSTaskIdleStk[0],                         /* Set Bottom-Of-Stack               
  199.              -   */
  200.                                         OS_TASK_IDLE_STK_SIZE,
  201.                                         (void *)0,                                 /* No TCB extension                  
  202.              -   */
  203.                                         OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stac
  204.              -k  */
  205.                   #else
  206.                   (void)OSTaskCreateExt(OS_TaskIdle,
  207.                                         (void *)0,                                 /* No arguments passed to OS_TaskIdle
  208.              -() */
  209.                                         &OSTaskIdleStk[0],                         /* Set Top-Of-Stack                  
  210.              -   */
  211.                                         OS_IDLE_PRIO,                              /* Lowest priority level             
  212.              -   */
  213.                                         OS_TASK_IDLE_ID,
  214.                                         &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], /* Set Bottom-Of-Stack               
  215.              -   */
  216.                                         OS_TASK_IDLE_STK_SIZE,
  217.                                         (void *)0,                                 /* No TCB extension                  
  218.              -   */
  219.                                         OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stac
  220.              -k  */
  221.                   #endif
  222.               #else
  223.  182   1          #if OS_STK_GROWTH == 1
  224.                   (void)OSTaskCreate(OS_TaskIdle,
  225.                                      (void *)0,
  226.                                      &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1],
  227.                                      OS_IDLE_PRIO);
  228.                   #else
  229.  188   1          (void)OSTaskCreate(OS_TaskIdle,
  230.  189   1                             (void *)0,
  231.  190   1                             &OSTaskIdleStk[0],
  232.  191   1                             OS_IDLE_PRIO);
  233.  192   1          #endif
  234.  193   1      #endif
  235.  194   1      
  236.  195   1          /* ------------------------------- CREATION OF 'STATISTIC' TASK ---------------------------------- */
  237.  196   1      #if OS_TASK_STAT_EN > 0
  238.                   #if OS_TASK_CREATE_EXT_EN > 0
  239.                       #if OS_STK_GROWTH == 1
  240.                       (void)OSTaskCreateExt(OS_TaskStat,
  241.                                             (void *)0,                                   /* No args passed to OS_TaskSta
  242.              -t()*/
  243.                                             &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],   /* Set Top-Of-Stack            
  244.              -   */
  245.                                             OS_STAT_PRIO,                                /* One higher than the idle tas
  246.              -k  */
  247.                                             OS_TASK_STAT_ID,
  248.                                             &OSTaskStatStk[0],                           /* Set Bottom-Of-Stack         
  249.              -   */
  250. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 5   
  251.                                             OS_TASK_STAT_STK_SIZE,
  252.                                             (void *)0,                                   /* No TCB extension            
  253.              -   */
  254.                                             OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);  /* Enable stack checking + clea
  255.              -r  */
  256.                       #else
  257.                       (void)OSTaskCreateExt(OS_TaskStat,
  258.                                             (void *)0,                                   /* No args passed to OS_TaskSta
  259.              -t()*/
  260.                                             &OSTaskStatStk[0],                           /* Set Top-Of-Stack            
  261.              -   */
  262.                                             OS_STAT_PRIO,                                /* One higher than the idle tas
  263.              -k  */
  264.                                             OS_TASK_STAT_ID,
  265.                                             &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],   /* Set Bottom-Of-Stack         
  266.              -   */
  267.                                             OS_TASK_STAT_STK_SIZE,
  268.                                             (void *)0,                                   /* No TCB extension            
  269.              -   */
  270.                                             OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);  /* Enable stack checking + clea
  271.              -r  */
  272.                       #endif
  273.                   #else
  274.                       #if OS_STK_GROWTH == 1
  275.                       (void)OSTaskCreate(OS_TaskStat,
  276.                                          (void *)0,                                      /* No args passed to OS_TaskSta
  277.              -t()*/
  278.                                          &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],      /* Set Top-Of-Stack            
  279.              -   */
  280.                                          OS_STAT_PRIO);                                  /* One higher than the idle tas
  281.              -k  */
  282.                       #else
  283.                       (void)OSTaskCreate(OS_TaskStat,
  284.                                          (void *)0,                                      /* No args passed to OS_TaskSta
  285.              -t()*/
  286.                                          &OSTaskStatStk[0],                              /* Set Top-Of-Stack            
  287.              -   */
  288.                                          OS_STAT_PRIO);                                  /* One higher than the idle tas
  289.              -k  */
  290.                       #endif
  291.                   #endif
  292.               #endif
  293.  233   1      
  294.  234   1      #if OS_VERSION >= 204
  295.  235   1          OSInitHookEnd();                                                       /* Call port specific init. cod
  296.              -e  */
  297.  236   1      #endif
  298.  237   1      }
  299.  238          /*$PAGE*/
  300.  239          /*
  301.  240          *********************************************************************************************************
  302.  241          *                                              ENTER ISR
  303.  242          *
  304.  243          * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
  305.  244          *              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
  306.  245          *              only perform rescheduling at the last nested ISR.
  307.  246          *
  308.  247          * Arguments  : none
  309.  248          *
  310.  249          * Returns    : none
  311.  250          *
  312.  251          * Notes      : 1) Your ISR can directly increment OSIntNesting without calling this function because
  313. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 6   
  314.  252          *                 OSIntNesting has been declared 'global'.  You MUST, however, be sure that the increment
  315.  253          *                 is performed 'indivisibly' by your processor to ensure proper access to this critical
  316.  254          *                 resource.
  317.  255          *              2) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
  318.  256          *              3) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
  319.  257          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
  320.  258          *                 end of the ISR.
  321.  259          *********************************************************************************************************
  322.  260          */
  323.  261          
  324.  262          void  OSIntEnter (void) reentrant
  325.  263          {
  326.  264   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
  327.                   OS_CPU_SR  cpu_sr;
  328.               #endif    
  329.  267   1          
  330.  268   1          
  331.  269   1          OS_ENTER_CRITICAL();
  332.  270   1          if (OSIntNesting < 255) {
  333.  271   2              OSIntNesting++;                          /* Increment ISR nesting level                        */
  334.  272   2          }
  335.  273   1          OS_EXIT_CRITICAL();
  336.  274   1      }
  337.  275          /*$PAGE*/
  338.  276          /*
  339.  277          *********************************************************************************************************
  340.  278          *                                               EXIT ISR
  341.  279          *
  342.  280          * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When
  343.  281          *              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
  344.  282          *              a new, high-priority task, is ready to run.
  345.  283          *
  346.  284          * Arguments  : none
  347.  285          *
  348.  286          * Returns    : none
  349.  287          *
  350.  288          * Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
  351.  289          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
  352.  290          *                 end of the ISR.
  353.  291          *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
  354.  292          *********************************************************************************************************
  355.  293          */
  356.  294          
  357.  295          void  OSIntExit (void) reentrant
  358.  296          {
  359.  297   1      #if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register     */
  360.                   OS_CPU_SR  cpu_sr;
  361.               #endif
  362.  300   1          
  363.  301   1          
  364.  302   1          OS_ENTER_CRITICAL();
  365.  303   1          if (OSIntNesting > 0) {                            /* Prevent OSIntNesting from wrapping           */
  366.  304   2              OSIntNesting--;
  367.  305   2          }
  368.  306   1          if ((OSIntNesting == 0) && (OSLockNesting == 0)) { /* Reschedule only if all ISRs complete ...     */
  369.  307   2              OSIntExitY    = OSUnMapTbl[OSRdyGrp];          /* ... and not locked.                          */
  370.  308   2              OSPrioHighRdy = (INT8U)((OSIntExitY << 3) + OSUnMapTbl[OSRdyTbl[OSIntExitY]]);
  371.  309   2              if (OSPrioHighRdy != OSPrioCur) {              /* No Ctx Sw if current task is highest rdy     */
  372.  310   3                  OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
  373.  311   3                  OSCtxSwCtr++;                              /* Keep track of the number of context switches */
  374.  312   3                  OSIntCtxSw();                              /* Perform interrupt level context switch       */
  375.  313   3              }
  376. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 7   
  377.  314   2          }
  378.  315   1          OS_EXIT_CRITICAL();
  379.  316   1      }
  380.  317          /*$PAGE*/
  381.  318          /*
  382.  319          *********************************************************************************************************
  383.  320          *                                          PREVENT SCHEDULING
  384.  321          *
  385.  322          * Description: This function is used to prevent rescheduling to take place.  This allows your application
  386.  323          *              to prevent context switches until you are ready to permit context switching.
  387.  324          *
  388.  325          * Arguments  : none
  389.  326          *
  390.  327          * Returns    : none
  391.  328          *
  392.  329          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
  393.  330          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
  394.  331          *********************************************************************************************************
  395.  332          */
  396.  333          
  397.  334          #if OS_SCHED_LOCK_EN > 0
  398.               void  OSSchedLock (void) reentrant
  399.               {
  400.               #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
  401.                   OS_CPU_SR  cpu_sr;
  402.               #endif    
  403.                   
  404.                   
  405.                   if (OSRunning == TRUE) {                     /* Make sure multitasking is running                  */
  406.                       OS_ENTER_CRITICAL();
  407.                       if (OSLockNesting < 255) {               /* Prevent OSLockNesting from wrapping back to 0      */
  408.                           OSLockNesting++;                     /* Increment lock nesting level                       */
  409.                       }
  410.                       OS_EXIT_CRITICAL();
  411.                   }
  412.               }
  413.               #endif    
  414.  351          
  415.  352          /*$PAGE*/
  416.  353          /*
  417.  354          *********************************************************************************************************
  418.  355          *                                          ENABLE SCHEDULING
  419.  356          *
  420.  357          * Description: This function is used to re-allow rescheduling.
  421.  358          *
  422.  359          * Arguments  : none
  423.  360          *
  424.  361          * Returns    : none
  425.  362          *
  426.  363          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
  427.  364          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
  428.  365          *********************************************************************************************************
  429.  366          */
  430.  367          
  431.  368          #if OS_SCHED_LOCK_EN > 0
  432.               void  OSSchedUnlock (void) reentrant
  433.               {
  434.               #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
  435.                   OS_CPU_SR  cpu_sr;
  436.               #endif    
  437.                   
  438.                   
  439. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 8   
  440.                   if (OSRunning == TRUE) {                                   /* Make sure multitasking is running    */
  441.                       OS_ENTER_CRITICAL();
  442.                       if (OSLockNesting > 0) {                               /* Do not decrement if already 0        */
  443.                           OSLockNesting--;                                   /* Decrement lock nesting level         */
  444.                           if ((OSLockNesting == 0) && (OSIntNesting == 0)) { /* See if sched. enabled and not an ISR */
  445.                               OS_EXIT_CRITICAL();
  446.                               OS_Sched();                                    /* See if a HPT is ready                */
  447.                           } else {
  448.                               OS_EXIT_CRITICAL();
  449.                           }
  450.                       } else {
  451.                           OS_EXIT_CRITICAL();
  452.                       }
  453.                   }
  454.               }
  455.               #endif    
  456.  392          
  457.  393          /*$PAGE*/
  458.  394          /*
  459.  395          *********************************************************************************************************
  460.  396          *                                          START MULTITASKING
  461.  397          *
  462.  398          * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
  463.  399          *              task that you have created.  Before you can call OSStart(), you MUST have called OSInit()
  464.  400          *              and you MUST have created at least one task.
  465.  401          *
  466.  402          * Arguments  : none
  467.  403          *
  468.  404          * Returns    : none
  469.  405          *
  470.  406          * Note       : OSStartHighRdy() MUST:
  471.  407          *                 a) Call OSTaskSwHook() then,
  472.  408          *                 b) Set OSRunning to TRUE.
  473.  409          *********************************************************************************************************
  474.  410          */
  475.  411          
  476.  412          void  OSStart (void) reentrant
  477.  413          {
  478.  414   1          INT8U y;
  479.  415   1          INT8U x;
  480.  416   1      
  481.  417   1      
  482.  418   1          if (OSRunning == FALSE) {
  483.  419   2              y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's task priority number   */
  484.  420   2              x             = OSUnMapTbl[OSRdyTbl[y]];
  485.  421   2              OSPrioHighRdy = (INT8U)((y << 3) + x);
  486.  422   2              OSPrioCur     = OSPrioHighRdy;
  487.  423   2              OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
  488.  424   2              OSTCBCur      = OSTCBHighRdy;
  489.  425   2              OSStartHighRdy();                            /* Execute target specific code to start task     */
  490.  426   2          }
  491.  427   1      }
  492.  428          /*$PAGE*/
  493.  429          /*
  494.  430          *********************************************************************************************************
  495.  431          *                                        STATISTICS INITIALIZATION
  496.  432          *
  497.  433          * Description: This function is called by your application to establish CPU usage by first determining
  498.  434          *              how high a 32-bit counter would count to in 1 second if no other tasks were to execute
  499.  435          *              during that time.  CPU usage is then determined by a low priority task which keeps track
  500.  436          *              of this 32-bit counter every second but this time, with other tasks running.  CPU usage is
  501.  437          *              determined by:
  502. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 9   
  503.  438          *
  504.  439          *                                             OSIdleCtr
  505.  440          *                 CPU Usage (%) = 100 * (1 - ------------)
  506.  441          *                                            OSIdleCtrMax
  507.  442          *
  508.  443          * Arguments  : none
  509.  444          *
  510.  445          * Returns    : none
  511.  446          *********************************************************************************************************
  512.  447          */
  513.  448          
  514.  449          #if OS_TASK_STAT_EN > 0
  515.               void  OSStatInit (void) reentrant
  516.               {
  517.               #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
  518.                   OS_CPU_SR  cpu_sr;
  519.               #endif    
  520.                   
  521.                   
  522.                   OSTimeDly(2);                                /* Synchronize with clock tick                        */
  523.                   OS_ENTER_CRITICAL();
  524.                   OSIdleCtr    = 0L;                           /* Clear idle counter                                 */
  525.                   OS_EXIT_CRITICAL();
  526.                   OSTimeDly(OS_TICKS_PER_SEC);                 /* Determine MAX. idle counter value for 1 second     */
  527.                   OS_ENTER_CRITICAL();
  528.                   OSIdleCtrMax = OSIdleCtr;                    /* Store maximum idle counter count in 1 second       */
  529.                   OSStatRdy    = TRUE;
  530.                   OS_EXIT_CRITICAL();
  531.               }
  532.               #endif
  533.  468          /*$PAGE*/
  534.  469          /*
  535.  470          *********************************************************************************************************
  536.  471          *                                         PROCESS SYSTEM TICK
  537.  472          *
  538.  473          * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
  539.  474          *              as a 'clock tick').  This function should be called by the ticker ISR but, can also be
  540.  475          *              called by a high priority task.
  541.  476          *
  542.  477          * Arguments  : none
  543.  478          *
  544.  479          * Returns    : none
  545.  480          *********************************************************************************************************
  546.  481          */
  547.  482          
  548.  483          void  OSTimeTick (void) reentrant
  549.  484          {
  550.  485   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
  551.                   OS_CPU_SR  cpu_sr;
  552.               #endif    
  553.  488   1          OS_TCB    *ptcb;
  554.  489   1      
  555.  490   1      
  556.  491   1          OSTimeTickHook();                                      /* Call user definable hook                 */
  557.  492   1      #if OS_TIME_GET_SET_EN > 0   
  558.  493   1          OS_ENTER_CRITICAL();                                   /* Update the 32-bit tick counter           */
  559.  494   1          OSTime++;
  560.  495   1          OS_EXIT_CRITICAL();
  561.  496   1      #endif    
  562.  497   1          ptcb = OSTCBList;                                      /* Point at first TCB in TCB list           */
  563.  498   1          while (ptcb->OSTCBPrio != OS_IDLE_PRIO) {              /* Go through all TCBs in TCB list          */
  564.  499   2              OS_ENTER_CRITICAL();
  565. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 10  
  566.  500   2              if (ptcb->OSTCBDly != 0) {                         /* Delayed or waiting for event with TO     */
  567.  501   3                  if (--ptcb->OSTCBDly == 0) {                   /* Decrement nbr of ticks to end of delay   */
  568.  502   4                      if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == 0x00) {   /* Is task suspended?             */
  569.  503   5                          OSRdyGrp               |= ptcb->OSTCBBitY; /* No,  Make task Rdy to Run (timed out)*/
  570.  504   5                          OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
  571.  505   5                      } else {                                       /* Yes, Leave 1 tick to prevent ...     */
  572.  506   5                          ptcb->OSTCBDly = 1;                        /* ... loosing the task when the ...    */
  573.  507   5                      }                                              /* ... suspension is removed.           */
  574.  508   4                  }
  575.  509   3              }
  576.  510   2              ptcb = ptcb->OSTCBNext;                                /* Point at next TCB in TCB list        */
  577.  511   2              OS_EXIT_CRITICAL();
  578.  512   2          }
  579.  513   1      }
  580.  514          /*$PAGE*/
  581.  515          /*
  582.  516          *********************************************************************************************************
  583.  517          *                                             GET VERSION
  584.  518          *
  585.  519          * Description: This function is used to return the version number of uC/OS-II.  The returned value
  586.  520          *              corresponds to uC/OS-II's version number multiplied by 100.  In other words, version 2.00
  587.  521          *              would be returned as 200.
  588.  522          *
  589.  523          * Arguments  : none
  590.  524          *
  591.  525          * Returns    : the version number of uC/OS-II multiplied by 100.
  592.  526          *********************************************************************************************************
  593.  527          */
  594.  528          
  595.  529          INT16U  OSVersion (void) reentrant
  596.  530          {
  597.  531   1          return (OS_VERSION);
  598.  532   1      }
  599.  533          
  600.  534          /*$PAGE*/
  601.  535          /*
  602.  536          *********************************************************************************************************
  603.  537          *                                            DUMMY FUNCTION
  604.  538          *
  605.  539          * Description: This function doesn't do anything.  It is called by OSTaskDel().
  606.  540          *
  607.  541          * Arguments  : none
  608.  542          *
  609.  543          * Returns    : none
  610.  544          *********************************************************************************************************
  611.  545          */
  612.  546          
  613.  547          #if OS_TASK_DEL_EN > 0
  614.               void  OS_Dummy (void) reentrant
  615.               {
  616.               }
  617.               #endif
  618.  552          
  619.  553          /*$PAGE*/
  620.  554          /*
  621.  555          *********************************************************************************************************
  622.  556          *                             MAKE TASK READY TO RUN BASED ON EVENT OCCURING
  623.  557          *
  624.  558          * Description: This function is called by other uC/OS-II services and is used to ready a task that was
  625.  559          *              waiting for an event to occur.
  626.  560          *
  627.  561          * Arguments  : pevent    is a pointer to the event control block corresponding to the event.
  628. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 11  
  629.  562          *
  630.  563          *              msg       is a pointer to a message.  This pointer is used by message oriented services
  631.  564          *                        such as MAILBOXEs and QUEUEs.  The pointer is not used when called by other
  632.  565          *                        service functions.
  633.  566          *
  634.  567          *              msk       is a mask that is used to clear the status byte of the TCB.  For example,
  635.  568          *                        OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
  636.  569          *
  637.  570          * Returns    : none
  638.  571          *
  639.  572          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
  640.  573          *********************************************************************************************************
  641.  574          */
  642.  575          #if OS_EVENT_EN > 0
  643.               INT8U  OS_EventTaskRdy (OS_EVENT *pevent, void *msg, INT8U msk) reentrant
  644.               {
  645.                   OS_TCB *ptcb;
  646.                   INT8U   x;
  647.                   INT8U   y;
  648.                   INT8U   bitx;
  649.                   INT8U   bity;
  650.                   INT8U   prio;
  651.               
  652.               
  653.                   y    = OSUnMapTbl[pevent->OSEventGrp];            /* Find highest prio. task waiting for message   */
  654.                   bity = OSMapTbl[y];
  655.                   x    = OSUnMapTbl[pevent->OSEventTbl[y]];
  656.                   bitx = OSMapTbl[x];
  657.                   prio = (INT8U)((y << 3) + x);                     /* Find priority of task getting the msg         */
  658.                   if ((pevent->OSEventTbl[y] &= ~bitx) == 0x00) {   /* Remove this task from the waiting list        */
  659.                       pevent->OSEventGrp &= ~bity;                  /* Clr group bit if this was only task pending   */
  660.                   }
  661.                   ptcb                 =  OSTCBPrioTbl[prio];       /* Point to this task's OS_TCB                   */
  662.                   ptcb->OSTCBDly       =  0;                        /* Prevent OSTimeTick() from readying task       */
  663.                   ptcb->OSTCBEventPtr  = (OS_EVENT *)0;             /* Unlink ECB from this task                     */
  664.               #if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0)
  665.                   ptcb->OSTCBMsg       = msg;                       /* Send message directly to waiting task         */
  666.               #else
  667.                   msg                  = msg;                       /* Prevent compiler warning if not used          */
  668.               #endif
  669.                   ptcb->OSTCBStat     &= ~msk;                      /* Clear bit associated with event type          */
  670.                   if (ptcb->OSTCBStat == OS_STAT_RDY) {             /* See if task is ready (could be susp'd)        */
  671.                       OSRdyGrp        |=  bity;                     /* Put task in the ready to run list             */
  672.                       OSRdyTbl[y]     |=  bitx;
  673.                   }
  674.                   return (prio);
  675.               }
  676.               #endif
  677.  610          /*$PAGE*/
  678.  611          /*
  679.  612          *********************************************************************************************************
  680.  613          *                                   MAKE TASK WAIT FOR EVENT TO OCCUR
  681.  614          *
  682.  615          * Description: This function is called by other uC/OS-II services to suspend a task because an event has
  683.  616          *              not occurred.
  684.  617          *
  685.  618          * Arguments  : pevent   is a pointer to the event control block for which the task will be waiting for.
  686.  619          *
  687.  620          * Returns    : none
  688.  621          *
  689.  622          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
  690.  623          *********************************************************************************************************
  691. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 12  
  692.  624          */
  693.  625          #if OS_EVENT_EN > 0
  694.               void  OS_EventTaskWait (OS_EVENT *pevent) reentrant
  695.               {
  696.                   OSTCBCur->OSTCBEventPtr = pevent;            /* Store pointer to event control block in TCB        */
  697.                   if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0x00) {   /* Task no longer ready      */
  698.                       OSRdyGrp &= ~OSTCBCur->OSTCBBitY;        /* Clear event grp bit if this was only task pending  */
  699.                   }
  700.                   pevent->OSEventTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX;          /* Put task in waiting list  */
  701.                   pevent->OSEventGrp                   |= OSTCBCur->OSTCBBitY;
  702.               }
  703.               #endif
  704.  636          /*$PAGE*/
  705.  637          /*
  706.  638          *********************************************************************************************************
  707.  639          *                              MAKE TASK READY TO RUN BASED ON EVENT TIMEOUT
  708.  640          *
  709.  641          * Description: This function is called by other uC/OS-II services to make a task ready to run because a
  710.  642          *              timeout occurred.
  711.  643          *
  712.  644          * Arguments  : pevent   is a pointer to the event control block which is readying a task.
  713.  645          *
  714.  646          * Returns    : none
  715.  647          *
  716.  648          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
  717.  649          *********************************************************************************************************
  718.  650          */
  719.  651          #if OS_EVENT_EN > 0
  720.               void  OS_EventTO (OS_EVENT *pevent) reentrant
  721.               {
  722.                   if ((pevent->OSEventTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0x00) {
  723.                       pevent->OSEventGrp &= ~OSTCBCur->OSTCBBitY;
  724.                   }
  725.                   OSTCBCur->OSTCBStat     = OS_STAT_RDY;       /* Set status to ready                                */
  726.                   OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;     /* No longer waiting for event                        */
  727.               }
  728.               #endif
  729.  661          /*$PAGE*/
  730.  662          /*
  731.  663          *********************************************************************************************************
  732.  664          *                                 INITIALIZE EVENT CONTROL BLOCK'S WAIT LIST
  733.  665          *
  734.  666          * Description: This function is called by other uC/OS-II services to initialize the event wait list.
  735.  667          *
  736.  668          * Arguments  : pevent    is a pointer to the event control block allocated to the event.
  737.  669          *
  738.  670          * Returns    : none
  739.  671          *
  740.  672          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
  741.  673          *********************************************************************************************************
  742.  674          */
  743.  675          #if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0) || (OS_SEM_EN > 0) || (OS_MUTEX_EN > 0)
  744.               void  OS_EventWaitListInit (OS_EVENT *pevent) reentrant
  745.               {
  746.                   INT8U  *ptbl;
  747.               
  748.               
  749.                   pevent->OSEventGrp = 0x00;                   /* No task waiting on event                           */
  750.                   ptbl               = &pevent->OSEventTbl[0];
  751.               
  752.               #if OS_EVENT_TBL_SIZE > 0
  753.                   *ptbl++            = 0x00;
  754. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 13  
  755.               #endif
  756.               
  757.               #if OS_EVENT_TBL_SIZE > 1
  758.                   *ptbl++            = 0x00;
  759.               #endif
  760.               
  761.               #if OS_EVENT_TBL_SIZE > 2
  762.                   *ptbl++            = 0x00;
  763.               #endif
  764.               
  765.               #if OS_EVENT_TBL_SIZE > 3
  766.                   *ptbl++            = 0x00;
  767.               #endif
  768.               
  769.               #if OS_EVENT_TBL_SIZE > 4
  770.                   *ptbl++            = 0x00;
  771.               #endif
  772.               
  773.               #if OS_EVENT_TBL_SIZE > 5
  774.                   *ptbl++            = 0x00;
  775.               #endif
  776.               
  777.               #if OS_EVENT_TBL_SIZE > 6
  778.                   *ptbl++            = 0x00;
  779.               #endif
  780.               
  781.               #if OS_EVENT_TBL_SIZE > 7
  782.                   *ptbl              = 0x00;
  783.               #endif
  784.               }
  785.               #endif
  786.  717          /*$PAGE*/
  787.  718          /*
  788.  719          *********************************************************************************************************
  789.  720          *                                              SCHEDULER
  790.  721          *
  791.  722          * Description: This function is called by other uC/OS-II services to determine whether a new, high
  792.  723          *              priority task has been made ready to run.  This function is invoked by TASK level code
  793.  724          *              and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
  794.  725          *
  795.  726          * Arguments  : none
  796.  727          *
  797.  728          * Returns    : none
  798.  729          *
  799.  730          * Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
  800.  731          *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
  801.  732          *********************************************************************************************************
  802.  733          */
  803.  734          
  804.  735          void  OS_Sched (void) reentrant
  805.  736          {
  806.  737   1      #if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register     */
  807.                   OS_CPU_SR  cpu_sr;
  808.               #endif    
  809.  740   1          INT8U      y;
  810.  741   1      
  811.  742   1      
  812.  743   1          OS_ENTER_CRITICAL();
  813.  744   1          if ((OSIntNesting == 0) && (OSLockNesting == 0)) { /* Sched. only if all ISRs done & not locked    */
  814.  745   2              y             = OSUnMapTbl[OSRdyGrp];          /* Get pointer to HPT ready to run              */
  815.  746   2              OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
  816.  747   2              if (OSPrioHighRdy != OSPrioCur) {              /* No Ctx Sw if current task is highest rdy     */
  817. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 14  
  818.  748   3                  OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
  819.  749   3                  OSCtxSwCtr++;                              /* Increment context switch counter             */
  820.  750   3                  OS_TASK_SW();                              /* Perform a context switch                     */
  821.  751   3              }
  822.  752   2          }
  823.  753   1          OS_EXIT_CRITICAL();
  824.  754   1      }
  825.  755          /*$PAGE*/
  826.  756          /*
  827.  757          *********************************************************************************************************
  828.  758          *                                              IDLE TASK
  829.  759          *
  830.  760          * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
  831.  761          *              executes because they are ALL waiting for event(s) to occur.
  832.  762          *
  833.  763          * Arguments  : none
  834.  764          *
  835.  765          * Returns    : none
  836.  766          *
  837.  767          * Note(s)    : 1) OSTaskIdleHook() is called after the critical section to ensure that interrupts will be
  838.  768          *                 enabled for at least a few instructions.  On some processors (ex. Philips XA), enabling
  839.  769          *                 and then disabling interrupts didn't allow the processor enough time to have interrupts
  840.  770          *                 enabled before they were disabled again.  uC/OS-II would thus never recognize
  841.  771          *                 interrupts.
  842.  772          *              2) This hook has been added to allow you to do such things as STOP the CPU to conserve 
  843.  773          *                 power.
  844.  774          *********************************************************************************************************
  845.  775          */
  846.  776          
  847.  777          void  OS_TaskIdle (void *ppdata) reentrant
  848.  778          {
  849.  779   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
  850.                   OS_CPU_SR  cpu_sr;
  851.               #endif    
  852.  782   1          
  853.  783   1          
  854.  784   1          ppdata = ppdata;                               /* Prevent compiler warning for not using 'ppdata'     
  855.              -*/
  856.  785   1          for (;;) {
  857.  786   2              OS_ENTER_CRITICAL();
  858.  787   2              OSIdleCtr++;
  859.  788   2              OS_EXIT_CRITICAL();
  860.  789   2              OSTaskIdleHook();                        /* Call user definable HOOK                           */
  861.  790   2          }
  862.  791   1      }
  863.  792          /*$PAGE*/
  864.  793          /*
  865.  794          *********************************************************************************************************
  866.  795          *                                            STATISTICS TASK
  867.  796          *
  868.  797          * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
  869.  798          *              multitasking environment.  Specifically, OS_TaskStat() computes the CPU usage.
  870.  799          *              CPU usage is determined by:
  871.  800          *
  872.  801          *                                          OSIdleCtr
  873.  802          *                 OSCPUUsage = 100 * (1 - ------------)     (units are in %)
  874.  803          *                                         OSIdleCtrMax
  875.  804          *
  876.  805          * Arguments  : ppdata     this pointer is not used at this time.
  877.  806          *
  878.  807          * Returns    : none
  879.  808          *
  880. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 15  
  881.  809          * Notes      : 1) This task runs at a priority level higher than the idle task.  In fact, it runs at the
  882.  810          *                 next higher priority, OS_IDLE_PRIO-1.
  883.  811          *              2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
  884.  812          *              3) We delay for 5 seconds in the beginning to allow the system to reach steady state and
  885.  813          *                 have all other tasks created before we do statistics.  You MUST have at least a delay
  886.  814          *                 of 2 seconds to allow for the system to establish the maximum value for the idle
  887.  815          *                 counter.
  888.  816          *********************************************************************************************************
  889.  817          */
  890.  818          
  891.  819          #if OS_TASK_STAT_EN > 0
  892.               void  OS_TaskStat (void *ppdata) reentrant
  893.               {
  894.               #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
  895.                   OS_CPU_SR  cpu_sr;
  896.               #endif    
  897.                   INT32U     run;
  898.                   INT8S      usage;
  899.               
  900.               
  901.                   ppdata = ppdata;                             /* Prevent compiler warning for not using 'ppdata'     */
  902.                   while (OSStatRdy == FALSE) {
  903.                       OSTimeDly(2 * OS_TICKS_PER_SEC);         /* Wait until statistic task is ready                 */
  904.                   }
  905.                   for (;;) {
  906.                       OS_ENTER_CRITICAL();
  907.                       OSIdleCtrRun = OSIdleCtr;                /* Obtain the of the idle counter for the past second */
  908.                       run          = OSIdleCtr;
  909.                       OSIdleCtr    = 0L;                       /* Reset the idle counter for the next second         */
  910.                       OS_EXIT_CRITICAL();
  911.                       if (OSIdleCtrMax > 0L) {
  912.                           usage = (INT8S)(100L - 100L * run / OSIdleCtrMax);
  913.                           if (usage >= 0) {                    /* Make sure we don't have a negative percentage      */
  914.                               OSCPUUsage = usage;
  915.                           } else {
  916.                               OSCPUUsage = 0;
  917.                           }
  918.                       } else {
  919.                           OSCPUUsage = 0;
  920.                       }
  921.                       OSTaskStatHook();                        /* Invoke user definable hook                         */
  922.                       OSTimeDly(OS_TICKS_PER_SEC);             /* Accumulate OSIdleCtr for the next second           */
  923.                   }
  924.               }
  925.               #endif
  926.  854          /*$PAGE*/
  927.  855          /*
  928.  856          *********************************************************************************************************
  929.  857          *                                            INITIALIZE TCB
  930.  858          *
  931.  859          * Description: This function is internal to uC/OS-II and is used to initialize a Task Control Block when
  932.  860          *              a task is created (see OSTaskCreate() and OSTaskCreateExt()).
  933.  861          *
  934.  862          * Arguments  : prio          is the priority of the task being created
  935.  863          *
  936.  864          *              ptos          is a pointer to the task's top-of-stack assuming that the CPU registers
  937.  865          *                            have been placed on the stack.  Note that the top-of-stack corresponds to a
  938.  866          *                            'high' memory location is OS_STK_GROWTH is set to 1 and a 'low' memory
  939.  867          *                            location if OS_STK_GROWTH is set to 0.  Note that stack growth is CPU
  940.  868          *                            specific.
  941.  869          *
  942.  870          *              pbos          is a pointer to the bottom of stack.  A NULL pointer is passed if called by
  943. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 16  
  944.  871          *                            'OSTaskCreate()'.
  945.  872          *
  946.  873          *              id            is the task's ID (0..65535)
  947.  874          *
  948.  875          *              stk_size      is the size of the stack (in 'stack units').  If the stack units are INT8Us
  949.  876          *                            then, 'stk_size' contains the number of bytes for the stack.  If the stack
  950.  877          *                            units are INT32Us then, the stack contains '4 * stk_size' bytes.  The stack
  951.  878          *                            units are established by the #define constant OS_STK which is CPU
  952.  879          *                            specific.  'stk_size' is 0 if called by 'OSTaskCreate()'.
  953.  880          *
  954.  881          *              pext          is a pointer to a user supplied memory area that is used to extend the task
  955.  882          *                            control block.  This allows you to store the contents of floating-point
  956.  883          *                            registers, MMU registers or anything else you could find useful during a
  957.  884          *                            context switch.  You can even assign a name to each task and store this name
  958.  885          *                            in this TCB extension.  A NULL pointer is passed if called by OSTaskCreate().
  959.  886          *
  960.  887          *              opt           options as passed to 'OSTaskCreateExt()' or,
  961.  888          *                            0 if called from 'OSTaskCreate()'.
  962.  889          *
  963.  890          * Returns    : OS_NO_ERR         if the call was successful
  964.  891          *              OS_NO_MORE_TCB    if there are no more free TCBs to be allocated and thus, the task cannot
  965.  892          *                                be created.
  966.  893          *
  967.  894          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
  968.  895          *********************************************************************************************************
  969.  896          */
  970.  897          
  971.  898          INT8U  OS_TCBInit (INT8U prio, OS_STK *ptos, OS_STK *pbos, INT16U id, INT32U stk_size, void *pext, INT16U 
  972.              -opt) reentrant
  973.  899          {
  974.  900   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
  975.                   OS_CPU_SR  cpu_sr;
  976.               #endif    
  977.  903   1          OS_TCB    *ptcb;
  978.  904   1      
  979.  905   1      
  980.  906   1          OS_ENTER_CRITICAL();
  981.  907   1          ptcb = OSTCBFreeList;                                  /* Get a free TCB from the free TCB list    */
  982.  908   1          if (ptcb != (OS_TCB *)0) {
  983.  909   2              OSTCBFreeList        = ptcb->OSTCBNext;            /* Update pointer to free TCB list          */
  984.  910   2              OS_EXIT_CRITICAL();
  985.  911   2              ptcb->OSTCBStkPtr    = ptos;                       /* Load Stack pointer in TCB                */
  986.  912   2              ptcb->OSTCBPrio      = (INT8U)prio;                /* Load task priority into TCB              */
  987.  913   2              ptcb->OSTCBStat      = OS_STAT_RDY;                /* Task is ready to run                     */
  988.  914   2              ptcb->OSTCBDly       = 0;                          /* Task is not delayed                      */
  989.  915   2      
  990.  916   2      #if OS_TASK_CREATE_EXT_EN > 0
  991.                       ptcb->OSTCBExtPtr    = pext;                       /* Store pointer to TCB extension           */
  992.                       ptcb->OSTCBStkSize   = stk_size;                   /* Store stack size                         */
  993.                       ptcb->OSTCBStkBottom = pbos;                       /* Store pointer to bottom of stack         */
  994.                       ptcb->OSTCBOpt       = opt;                        /* Store task options                       */
  995.                       ptcb->OSTCBId        = id;                         /* Store task ID                            */
  996.               #else
  997.  923   2              pext                 = pext;                       /* Prevent compiler warning if not used     */
  998.  924   2              stk_size             = stk_size;
  999.  925   2              pbos                 = pbos;
  1000.  926   2              opt                  = opt;
  1001.  927   2              id                   = id;
  1002.  928   2      #endif
  1003.  929   2      
  1004.  930   2      #if OS_TASK_DEL_EN > 0
  1005.                       ptcb->OSTCBDelReq    = OS_NO_ERR;
  1006. C51 COMPILER V8.02   OS_CORE                                                               06/22/2006 11:44:34 PAGE 17  
  1007.               #endif
  1008.  933   2      
  1009.  934   2              ptcb->OSTCBY         = prio >> 3;                  /* Pre-compute X, Y, BitX and BitY          */
  1010.  935   2              ptcb->OSTCBBitY      = OSMapTbl[ptcb->OSTCBY];
  1011.  936   2              ptcb->OSTCBX         = prio & 0x07;
  1012.  937   2              ptcb->OSTCBBitX      = OSMapTbl[ptcb->OSTCBX];
  1013.  938   2      
  1014.  939   2      #if OS_EVENT_EN > 0
  1015.                       ptcb->OSTCBEventPtr  = (OS_EVENT *)0;              /* Task is not pending on an event          */
  1016.               #endif
  1017.  942   2      
  1018.  943   2      #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0) && (OS_TASK_DEL_EN > 0)
  1019.                       ptcb->OSTCBFlagNode  = (OS_FLAG_NODE *)0;          /* Task is not pending on an event flag     */
  1020.               #endif
  1021.  946   2      
  1022.  947   2      #if (OS_MBOX_EN > 0) || ((OS_Q_EN > 0) && (OS_MAX_QS > 0))
  1023.                       ptcb->OSTCBMsg       = (void *)0;                  /* No message received                      */
  1024.               #endif
  1025.  950   2      
  1026.  951   2      #if OS_VERSION >= 204
  1027.  952   2              OSTCBInitHook(ptcb);
  1028.  953   2      #endif
  1029.  954   2      
  1030.  955   2              OSTaskCreateHook(ptcb);                            /* Call user defined hook                   */
  1031.  956   2              
  1032.  957   2              OS_ENTER_CRITICAL();
  1033.  958   2              OSTCBPrioTbl[prio] = ptcb;
  1034.  959   2              ptcb->OSTCBNext    = OSTCBList;                    /* Link into TCB chain                      */
  1035.  960   2              ptcb->OSTCBPrev    = (OS_TCB *)0;
  1036.  961   2              if (OSTCBList != (OS_TCB *)0) {
  1037.  962   3                  OSTCBList->OSTCBPrev = ptcb;
  1038.  963   3              }
  1039.  964   2              OSTCBList               = ptcb;
  1040.  965   2              OSRdyGrp               |= ptcb->OSTCBBitY;         /* Make task ready to run                   */
  1041.  966   2              OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
  1042.  967   2              OS_EXIT_CRITICAL();
  1043.  968   2              return (OS_NO_ERR);
  1044.  969   2          }
  1045.  970   1          OS_EXIT_CRITICAL();
  1046.  971   1          return (OS_NO_MORE_TCB);
  1047.  972   1      }
  1048. MODULE INFORMATION:   STATIC OVERLAYABLE
  1049.    CODE SIZE        =   1978    ----
  1050.    CONSTANT SIZE    =   ----    ----
  1051.    XDATA SIZE       =    619    ----
  1052.    PDATA SIZE       =   ----    ----
  1053.    DATA SIZE        =   ----    ----
  1054.    IDATA SIZE       =     22    ----
  1055.    BIT SIZE         =   ----    ----
  1056. END OF MODULE INFORMATION.
  1057. C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)