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

📄 os_core.lst

📁 该源码是本人经调试通过的UCOS2操作系统在51单片机上移植好的源代码
💻 LST
📖 第 1 页 / 共 5 页
字号:
 207          *********************************************************************************************************
 208          */
 209          
 210          #if OS_SCHED_LOCK_EN > 0
              void  OSSchedLock (void)  reentrant
              {
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif    
                  
                  
                  if (OSRunning == TRUE) {                     /* Make sure multitasking is running                  */
                      OS_ENTER_CRITICAL();
                      if (OSLockNesting < 255) {               /* Prevent OSLockNesting from wrapping back to 0      */
                          OSLockNesting++;                     /* Increment lock nesting level                       */
                      }
                      OS_EXIT_CRITICAL();
                  }
              }
              #endif    
 227          
 228          /*$PAGE*/
 229          /*
 230          *********************************************************************************************************
C51 COMPILER V7.20   OS_CORE                                                               09/25/2006 10:08:38 PAGE 5   

 231          *                                          ENABLE SCHEDULING
 232          *
 233          * Description: This function is used to re-allow rescheduling.
 234          *
 235          * Arguments  : none
 236          *
 237          * Returns    : none
 238          *
 239          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 240          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 241          *********************************************************************************************************
 242          */
 243          
 244          #if OS_SCHED_LOCK_EN > 0
              void  OSSchedUnlock (void)  reentrant
              {
              #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;
              #endif    
                  
                  
                  if (OSRunning == TRUE) {                                   /* Make sure multitasking is running    */
                      OS_ENTER_CRITICAL();
                      if (OSLockNesting > 0) {                               /* Do not decrement if already 0        */
                          OSLockNesting--;                                   /* Decrement lock nesting level         */
                          if ((OSLockNesting == 0) && (OSIntNesting == 0)) { /* See if sched. enabled and not an ISR */
                              OS_EXIT_CRITICAL();
                              OS_Sched();                                    /* See if a HPT is ready                */
                          } else {
                              OS_EXIT_CRITICAL();
                          }
                      } else {
                          OS_EXIT_CRITICAL();
                      }
                  }
              }
              #endif    
 268          
 269          /*$PAGE*/
 270          /*
 271          *********************************************************************************************************
 272          *                                          START MULTITASKING
 273          *
 274          * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
 275          *              task that you have created.  Before you can call OSStart(), you MUST have called OSInit()
 276          *              and you MUST have created at least one task.
 277          *
 278          * Arguments  : none
 279          *
 280          * Returns    : none
 281          *
 282          * Note       : OSStartHighRdy() MUST:
 283          *                 a) Call OSTaskSwHook() then,
 284          *                 b) Set OSRunning to TRUE.
 285          *                 c) Load the context of the task pointed to by OSTCBHighRdy.
 286          *                 d_ Execute the task.
 287          *********************************************************************************************************
 288          */
 289          
 290          void  OSStart (void)  reentrant
 291          {
 292   1          INT8U y;
C51 COMPILER V7.20   OS_CORE                                                               09/25/2006 10:08:38 PAGE 6   

 293   1          INT8U x;
 294   1      
 295   1      
 296   1          if (OSRunning == FALSE) {
 297   2              y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's task priority number   */
 298   2              x             = OSUnMapTbl[OSRdyTbl[y]];
 299   2              OSPrioHighRdy = (INT8U)((y << 3) + x);
 300   2              OSPrioCur     = OSPrioHighRdy;
 301   2              OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
 302   2              OSTCBCur      = OSTCBHighRdy;
 303   2              OSStartHighRdy();                            /* Execute target specific code to start task     */
 304   2          }
 305   1      }
 306          /*$PAGE*/
 307          /*
 308          *********************************************************************************************************
 309          *                                        STATISTICS INITIALIZATION
 310          *
 311          * Description: This function is called by your application to establish CPU usage by first determining
 312          *              how high a 32-bit counter would count to in 1 second if no other tasks were to execute
 313          *              during that time.  CPU usage is then determined by a low priority task which keeps track
 314          *              of this 32-bit counter every second but this time, with other tasks running.  CPU usage is
 315          *              determined by:
 316          *
 317          *                                             OSIdleCtr
 318          *                 CPU Usage (%) = 100 * (1 - ------------)
 319          *                                            OSIdleCtrMax
 320          *
 321          * Arguments  : none
 322          *
 323          * Returns    : none
 324          *********************************************************************************************************
 325          */
 326          
 327          #if OS_TASK_STAT_EN > 0
              void  OSStatInit (void)  reentrant
              {
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif    
                  
                  
                  OSTimeDly(2);                                /* Synchronize with clock tick                        */
                  OS_ENTER_CRITICAL();
                  OSIdleCtr    = 0L;                           /* Clear idle counter                                 */
                  OS_EXIT_CRITICAL();
                  OSTimeDly(OS_TICKS_PER_SEC);                 /* Determine MAX. idle counter value for 1 second     */
                  OS_ENTER_CRITICAL();
                  OSIdleCtrMax = OSIdleCtr;                    /* Store maximum idle counter count in 1 second       */
                  OSStatRdy    = TRUE;
                  OS_EXIT_CRITICAL();
              }
              #endif
 346          /*$PAGE*/
 347          /*
 348          *********************************************************************************************************
 349          *                                         PROCESS SYSTEM TICK
 350          *
 351          * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
 352          *              as a 'clock tick').  This function should be called by the ticker ISR but, can also be
 353          *              called by a high priority task.
 354          *
C51 COMPILER V7.20   OS_CORE                                                               09/25/2006 10:08:38 PAGE 7   

 355          * Arguments  : none
 356          *
 357          * Returns    : none
 358          *********************************************************************************************************
 359          */
 360          
 361          void  OSTimeTick (void) reentrant
 362          {
 363   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;
              #endif    
 366   1          OS_TCB    *ptcb;
 367   1      
 368   1      #if OS_CPU_HOOKS_EN
                  OSTimeTickHook(); 
              #endif                                     /* Call user definable hook  
                             */
 372   1      #if OS_TIME_GET_SET_EN > 0   
                  OS_ENTER_CRITICAL();                                   /* Update the 32-bit tick counter           */
                  OSTime++;
                  OS_EXIT_CRITICAL();
              #endif
 377   1          if (OSRunning == TRUE) {    
 378   2              ptcb = OSTCBList;                                  /* Point at first TCB in TCB list           */
 379   2              while (ptcb->OSTCBPrio != OS_IDLE_PRIO) {          /* Go through all TCBs in TCB list          */
 380   3                  OS_ENTER_CRITICAL();
 381   3                  if (ptcb->OSTCBDly != 0) {                     /* Delayed or waiting for event with TO     */
 382   4                      if (--ptcb->OSTCBDly == 0) {               /* Decrement nbr of ticks to end of delay   */
 383   5                          if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) { /* Is task suspended?    */
 384   6                              OSRdyGrp               |= ptcb->OSTCBBitY; /* No,  Make task R-to-R (timed out)*/
 385   6                              OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
 386   6                          } else {                               /* Yes, Leave 1 tick to prevent ...         */
 387   6                              ptcb->OSTCBDly = 1;                /* ... loosing the task when the ...        */
 388   6                          }                                      /* ... suspension is removed.               */
 389   5                      }
 390   4                  }
 391   3                  ptcb = ptcb->OSTCBNext;                        /* Point at next TCB in TCB list            */
 392   3                  OS_EXIT_CRITICAL();
 393   3              }
 394   2          }
 395   1      }
 396          /*$PAGE*/
 397          /*
 398          *********************************************************************************************************
 399          *                                             GET VERSION
 400          *
 401          * Description: This function is used to return the version number of uC/OS-II.  The returned value
 402          *              corresponds to uC/OS-II's version number multiplied by 100.  In other words, version 2.00
 403          *              would be returned as 200.
 404          *
 405          * Arguments  : none
 406          *
 407          * Returns    : the version number of uC/OS-II multiplied by 100.
 408          *********************************************************************************************************
 409          */
 410          #if 0
              INT16U  OSVersion (void)  reentrant
              {
                  return (OS_VERSION);
              }
              #endif
 416          /*$PAGE*/
C51 COMPILER V7.20   OS_CORE                                                               09/25/2006 10:08:38 PAGE 8   

 417          /*
 418          *********************************************************************************************************
 419          *                                            DUMMY FUNCTION
 420          *
 421          * Description: This function doesn't do anything.  It is called by OSTaskDel().
 422          *
 423          * Arguments  : none
 424          *
 425          * Returns    : none
 426          *********************************************************************************************************
 427          */
 428          
 429          #if OS_TASK_DEL_EN > 0
              void  OS_Dummy (void)  reentrant

⌨️ 快捷键说明

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