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

📄 os_core.lst

📁 基于51单片机UCOS移植
💻 LST
📖 第 1 页 / 共 5 页
字号:
 205          *
 206          * Returns    : none
 207          *
 208          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 209          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 210          *********************************************************************************************************
 211          */
 212          
 213          #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    
C51 COMPILER V9.01   OS_CORE                                                               10/31/2012 17:19:07 PAGE 5   

 230          
 231          /*$PAGE*/
 232          /*
 233          *********************************************************************************************************
 234          *                                          ENABLE SCHEDULING
 235          *
 236          * Description: This function is used to re-allow rescheduling.
 237          *
 238          * Arguments  : none
 239          *
 240          * Returns    : none
 241          *
 242          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 243          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 244          *********************************************************************************************************
 245          */
 246          
 247          #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    
 271          
 272          /*$PAGE*/
 273          /*
 274          *********************************************************************************************************
 275          *                                          START MULTITASKING
 276          *
 277          * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
 278          *              task that you have created.  Before you can call OSStart(), you MUST have called OSInit()
 279          *              and you MUST have created at least one task.
 280          *
 281          * Arguments  : none
 282          *
 283          * Returns    : none
 284          *
 285          * Note       : OSStartHighRdy() MUST:
 286          *                 a) Call OSTaskSwHook() then,
 287          *                 b) Set OSRunning to TRUE.
 288          *                 c) Load the context of the task pointed to by OSTCBHighRdy.
 289          *                 d_ Execute the task.
 290          *********************************************************************************************************
 291          */
C51 COMPILER V9.01   OS_CORE                                                               10/31/2012 17:19:07 PAGE 6   

 292          
 293          void  OSStart (void) REENTRANT
 294          {
 295   1          INT8U y;
 296   1          INT8U x;
 297   1      
 298   1      
 299   1          if (OSRunning == FALSE) {
 300   2              y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's task priority number   */
 301   2              x             = OSUnMapTbl[OSRdyTbl[y]];
 302   2              OSPrioHighRdy = (INT8U)((y << 3) + x);
 303   2              OSPrioCur     = OSPrioHighRdy;
 304   2              OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
 305   2              OSTCBCur      = OSTCBHighRdy;
 306   2              OSStartHighRdy();                            /* Execute target specific code to start task     */
 307   2          }
 308   1      }
 309          /*$PAGE*/
 310          /*
 311          *********************************************************************************************************
 312          *                                        STATISTICS INITIALIZATION
 313          *
 314          * Description: This function is called by your application to establish CPU usage by first determining
 315          *              how high a 32-bit counter would count to in 1 second if no other tasks were to execute
 316          *              during that time.  CPU usage is then determined by a low priority task which keeps track
 317          *              of this 32-bit counter every second but this time, with other tasks running.  CPU usage is
 318          *              determined by:
 319          *
 320          *                                             OSIdleCtr
 321          *                 CPU Usage (%) = 100 * (1 - ------------)
 322          *                                            OSIdleCtrMax
 323          *
 324          * Arguments  : none
 325          *
 326          * Returns    : none
 327          *********************************************************************************************************
 328          */
 329          
 330          #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
 349          /*$PAGE*/
 350          /*
 351          *********************************************************************************************************
 352          *                                         PROCESS SYSTEM TICK
 353          *
C51 COMPILER V9.01   OS_CORE                                                               10/31/2012 17:19:07 PAGE 7   

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

 416          
 417          /*$PAGE*/
 418          /*
 419          *********************************************************************************************************
 420          *                                            DUMMY FUNCTION
 421          *
 422          * Description: This function doesn't do anything.  It is called by OSTaskDel().
 423          *
 424          * Arguments  : none
 425          *
 426          * Returns    : none
 427          *********************************************************************************************************

⌨️ 快捷键说明

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