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

📄 os_core.lst

📁 成功的将UCOS操作系统
💻 LST
📖 第 1 页 / 共 5 页
字号:
 360          *
 361          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 362          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 363          *********************************************************************************************************
 364          */
 365          
 366          #if OS_SCHED_LOCK_EN > 0
              void  OSSchedUnlock (void) KCREENTRANT
              {
              #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        */
C51 COMPILER V8.02   OS_CORE                                                               08/05/2007 21:31:18 PAGE 8   

                          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    
 389          
 390          /*$PAGE*/
 391          /*
 392          *********************************************************************************************************
 393          *                                          START MULTITASKING
 394          *
 395          * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
 396          *              task that you have created.  Before you can call OSStart(), you MUST have called OSInit()
 397          *              and you MUST have created at least one task.
 398          *
 399          * Arguments  : none
 400          *
 401          * Returns    : none
 402          *
 403          * Note       : OSStartHighRdy() MUST:
 404          *                 a) Call OSTaskSwHook() then,
 405          *                 b) Set OSRunning to TRUE.
 406          *********************************************************************************************************
 407          */
 408          
 409          void  OSStart (void) KCREENTRANT
 410          {
 411   1          INT8U y;
 412   1          INT8U x;
 413   1      
 414   1      
 415   1          if (OSRunning == FALSE) {
 416   2              y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's task priority number   */
 417   2              x             = OSUnMapTbl[OSRdyTbl[y]];
 418   2              OSPrioHighRdy = (INT8U)((y << 3) + x);
 419   2              OSPrioCur     = OSPrioHighRdy;
 420   2              OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
 421   2              OSTCBCur      = OSTCBHighRdy;
 422   2              OSStartHighRdy();                            /* Execute target specific code to start task     */
 423   2          }
 424   1      }
 425          /*$PAGE*/
 426          /*
 427          *********************************************************************************************************
 428          *                                        STATISTICS INITIALIZATION
 429          *
 430          * Description: This function is called by your application to establish CPU usage by first determining
 431          *              how high a 32-bit counter would count to in 1 second if no other tasks were to execute
 432          *              during that time.  CPU usage is then determined by a low priority task which keeps track
 433          *              of this 32-bit counter every second but this time, with other tasks running.  CPU usage is
 434          *              determined by:
 435          *
 436          *                                             OSIdleCtr
 437          *                 CPU Usage (%) = 100 * (1 - ------------)
C51 COMPILER V8.02   OS_CORE                                                               08/05/2007 21:31:18 PAGE 9   

 438          *                                            OSIdleCtrMax
 439          *
 440          * Arguments  : none
 441          *
 442          * Returns    : none
 443          *********************************************************************************************************
 444          */
 445          
 446          #if OS_TASK_STAT_EN > 0
              void  OSStatInit (void) KCREENTRANT
              {
              #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
 465          /*$PAGE*/
 466          /*
 467          *********************************************************************************************************
 468          *                                         PROCESS SYSTEM TICK
 469          *
 470          * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
 471          *              as a 'clock tick').  This function should be called by the ticker ISR but, can also be
 472          *              called by a high priority task.
 473          *
 474          * Arguments  : none
 475          *
 476          * Returns    : none
 477          *********************************************************************************************************
 478          */
 479          
 480          void  OSTimeTick (void) KCREENTRANT
 481          {
 482   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;
              #endif    
 485   1          OS_TCB    *ptcb;
 486   1      
 487   1      
 488   1          OSTimeTickHook();                                      /* Call user definable hook                 */
 489   1      #if OS_TIME_GET_SET_EN > 0   
                  OS_ENTER_CRITICAL();                                   /* Update the 32-bit tick counter           */
                  OSTime++;
                  OS_EXIT_CRITICAL();
              #endif    
 494   1          ptcb = OSTCBList;                                      /* Point at first TCB in TCB list           */
 495   1          while (ptcb->OSTCBPrio != OS_IDLE_PRIO) {              /* Go through all TCBs in TCB list          */
 496   2              OS_ENTER_CRITICAL();
 497   2              if (ptcb->OSTCBDly != 0) {                         /* Delayed or waiting for event with TO     */
 498   3                  if (--ptcb->OSTCBDly == 0) {                   /* Decrement nbr of ticks to end of delay   */
 499   4                      if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == 0x00) {   /* Is task suspended?             */
C51 COMPILER V8.02   OS_CORE                                                               08/05/2007 21:31:18 PAGE 10  

 500   5                          OSRdyGrp               |= ptcb->OSTCBBitY; /* No,  Make task Rdy to Run (timed out)*/
 501   5                          OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
 502   5                      } else {                                       /* Yes, Leave 1 tick to prevent ...     */
 503   5                          ptcb->OSTCBDly = 1;                        /* ... loosing the task when the ...    */
 504   5                      }                                              /* ... suspension is removed.           */
 505   4                  }
 506   3              }
 507   2              ptcb = ptcb->OSTCBNext;                                /* Point at next TCB in TCB list        */
 508   2              OS_EXIT_CRITICAL();
 509   2          }
 510   1      }
 511          /*$PAGE*/
 512          /*
 513          *********************************************************************************************************
 514          *                                             GET VERSION
 515          *
 516          * Description: This function is used to return the version number of uC/OS-II.  The returned value
 517          *              corresponds to uC/OS-II's version number multiplied by 100.  In other words, version 2.00
 518          *              would be returned as 200.
 519          *
 520          * Arguments  : none
 521          *
 522          * Returns    : the version number of uC/OS-II multiplied by 100.
 523          *********************************************************************************************************
 524          */
 525          
 526          INT16U  OSVersion (void) KCREENTRANT
 527          {
 528   1          return (OS_VERSION);
 529   1      }
 530          
 531          /*$PAGE*/
 532          /*
 533          *********************************************************************************************************
 534          *                                            DUMMY FUNCTION
 535          *
 536          * Description: This function doesn't do anything.  It is called by OSTaskDel().
 537          *
 538          * Arguments  : none
 539          *
 540          * Returns    : none
 541          *********************************************************************************************************
 542          */
 543          
 544          #if OS_TASK_DEL_EN > 0
              void  OS_Dummy (void) KCREENTRANT
              {
              }
              #endif
 549          
 550          /*$PAGE*/
 551          /*
 552          *********************************************************************************************************
 553          *                             MAKE TASK READY TO RUN BASED ON EVENT OCCURING
 554          *
 555          * Description: This function is called by other uC/OS-II services and is used to ready a task that was
 556          *              waiting for an event to occur.
 557          *
 558          * Arguments  : pevent    is a pointer to the event control block corresponding to the event.
 559          *
 560          *              msg       is a pointer to a message.  This pointer is used by message oriented services
 561          *                        such as MAILBOXEs and QUEUEs.  The pointer is not used when called by other
C51 COMPILER V8.02   OS_CORE                                                               08/05/2007 21:31:18 PAGE 11  

 562          *                        service functions.
 563          *
 564          *              msk       is a mask that is used to clear the status byte of the TCB.  For example,
 565          *                        OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
 566          *
 567          * Returns    : none

⌨️ 快捷键说明

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