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

📄 os_core.lst

📁 一个基于C51指令系统的简易uCOS示范程序,有完整的代码分析
💻 LST
📖 第 1 页 / 共 4 页
字号:
 421          *              and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
 422          *
 423          * Arguments  : none
 424          *
 425          * Returns    : none
 426          *
C51 COMPILER V7.07   OS_CORE                                                               05/31/2008 20:36:05 PAGE 8   

 427          * Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
 428          *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
 429          *********************************************************************************************************
 430          */
 431          
 432          void OSSched (void) reentrant
 433          {
 434   1          INT8U y;
 435   1      
 436   1      
 437   1          OS_ENTER_CRITICAL();
 438   1          if ((OSLockNesting | OSIntNesting) == 0) {   /* Task scheduling must be enabled and not ISR level  */
 439   2              y             = OSUnMapTbl[OSRdyGrp];    /* Get pointer to highest priority task ready to run  */
 440   2              OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
 441   2              if (OSPrioHighRdy != OSPrioCur) {         /* No context switch if current task is highest ready */
 442   3                  OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
 443   3                  OSCtxSwCtr++;                        /* Increment context switch counter                   */
 444   3                  OS_TASK_SW();                        /* Perform a context switch                           */
 445   3              }
 446   2          }
 447   1          OS_EXIT_CRITICAL();
 448   1      }
 449          /*$PAGE*/
 450          /*
 451          *********************************************************************************************************
 452          *                                          PREVENT SCHEDULING
 453          *
 454          * Description: This function is used to prevent rescheduling to take place.  This allows your application
 455          *              to prevent context switches until you are ready to permit context switching.
 456          *
 457          * Arguments  : none
 458          *
 459          * Returns    : none
 460          *
 461          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every 
 462          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 463          *********************************************************************************************************
 464          */
 465          
 466          void OSSchedLock (void) reentrant
 467          {
 468   1          if (OSRunning == TRUE) {                     /* Make sure multitasking is running                  */
 469   2              OS_ENTER_CRITICAL();
 470   2              OSLockNesting++;                         /* Increment lock nesting level                       */
 471   2              OS_EXIT_CRITICAL();
 472   2          }
 473   1      }
 474          /*$PAGE*/
 475          /*
 476          *********************************************************************************************************
 477          *                                          ENABLE SCHEDULING
 478          *
 479          * Description: This function is used to re-allow rescheduling.  
 480          *
 481          * Arguments  : none
 482          *
 483          * Returns    : none
 484          *
 485          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every 
 486          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 487          *********************************************************************************************************
 488          */
C51 COMPILER V7.07   OS_CORE                                                               05/31/2008 20:36:05 PAGE 9   

 489          
 490          void OSSchedUnlock (void) reentrant
 491          {
 492   1          if (OSRunning == TRUE) {                           /* Make sure multitasking is running            */
 493   2              OS_ENTER_CRITICAL();
 494   2              if (OSLockNesting > 0) {                       /* Do not decrement if already 0                */
 495   3                  OSLockNesting--;                           /* Decrement lock nesting level                 */
 496   3                  if ((OSLockNesting | OSIntNesting) == 0) { /* See if scheduling re-enabled and not an ISR  */
 497   4                      OS_EXIT_CRITICAL();
 498   4                      OSSched();                             /* See if a higher priority task is ready       */
 499   4                  } else {
 500   4                      OS_EXIT_CRITICAL();
 501   4                  }
 502   3              } else {
 503   3                  OS_EXIT_CRITICAL();
 504   3              }
 505   2          }
 506   1      }
 507          /*$PAGE*/
 508          /*
 509          *********************************************************************************************************
 510          *                                          START MULTITASKING
 511          *
 512          * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
 513          *              task that you have created.  Before you can call OSStart(), you MUST have called OSInit()
 514          *              and you MUST have created at least one task.
 515          *
 516          * Arguments  : none
 517          *
 518          * Returns    : none
 519          *
 520          * Note       : OSStartHighRdy() MUST:
 521          *                 a) Call OSTaskSwHook() then,
 522          *                 b) Set OSRunning to TRUE.
 523          *********************************************************************************************************
 524          */
 525          
 526          void OSStart (void) reentrant
 527          {
 528   1          INT8U y;
 529   1          INT8U x;
 530   1      
 531   1      
 532   1          if (OSRunning == FALSE) {
 533   2              y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's task priority number   */
 534   2              x             = OSUnMapTbl[OSRdyTbl[y]];
 535   2              OSPrioHighRdy = (INT8U)((y << 3) + x);
 536   2              OSPrioCur     = OSPrioHighRdy;
 537   2              OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
 538   2              OSTCBCur      = OSTCBHighRdy;
 539   2              OSStartHighRdy();                            /* Execute target specific code to start task     */
 540   2          }
 541   1      }
 542          /*$PAGE*/
 543          /*
 544          *********************************************************************************************************
 545          *                                        STATISTICS INITIALIZATION
 546          *
 547          * Description: This function is called by your application to establish CPU usage by first determining
 548          *              how high a 32-bit counter would count to in 1 second if no other tasks were to execute
 549          *              during that time.  CPU usage is then determined by a low priority task which keeps track
 550          *              of this 32-bit counter every second but this time, with other tasks running.  CPU usage is
C51 COMPILER V7.07   OS_CORE                                                               05/31/2008 20:36:05 PAGE 10  

 551          *              determined by:
 552          *
 553          *                                             OSIdleCtr
 554          *                 CPU Usage (%) = 100 * (1 - ------------)
 555          *                                            OSIdleCtrMax
 556          *
 557          * Arguments  : none
 558          *
 559          * Returns    : none
 560          *********************************************************************************************************
 561          */
 562          
 563          #if OS_TASK_STAT_EN
              void OSStatInit (void) reentrant
              {
                  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
 577          /*$PAGE*/
 578          /*
 579          *********************************************************************************************************
 580          *                                              IDLE TASK
 581          *
 582          * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
 583          *              executes because they are waiting for event(s) to occur.
 584          *
 585          * Arguments  : none
 586          *
 587          * Returns    : none
 588          *********************************************************************************************************
 589          */
 590          
 591          void OSTaskIdle (void *ppdata) reentrant
 592          {
 593   1          ppdata = ppdata;                               /* Prevent compiler warning for not using 'pdata'     *
             -/
 594   1          for (;;) {
 595   2              OS_ENTER_CRITICAL();
 596   2              OSIdleCtr++;
 597   2              OS_EXIT_CRITICAL();
 598   2          }
 599   1      }
 600          /*$PAGE*/
 601          /*
 602          *********************************************************************************************************
 603          *                                            STATISTICS TASK
 604          *
 605          * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
 606          *              multitasking environment.  Specifically, OSTaskStat() computes the CPU usage.
 607          *              CPU usage is determined by:
 608          *
 609          *                                          OSIdleCtr
 610          *                 OSCPUUsage = 100 * (1 - ------------)     (units are in %)
 611          *                                         OSIdleCtrMax
C51 COMPILER V7.07   OS_CORE                                                               05/31/2008 20:36:05 PAGE 11  

 612          *
 613          * Arguments  : pdata     this pointer is not used at this time.
 614          *
 615          * Returns    : none
 616          *
 617          * Notes      : 1) This task runs at a priority level higher than the idle task.  In fact, it runs at the
 618          *                 next higher priority, OS_IDLE_PRIO-1.
 619          *              2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
 620          *              3) We delay for 5 seconds in the beginning to allow the system to reach steady state and
 621          *                 have all other tasks created before we do statistics.  You MUST have at least a delay
 622          *                 of 2 seconds to allow for the system to establish the maximum value for the idle 
 623          *                 counter.
 624          *********************************************************************************************************
 625          */
 626          
 627          #if OS_TASK_STAT_EN
              void OSTaskStat (void *ppdata) reentrant
              {
                  INT32U run;
                  INT8S  usage;
                  

⌨️ 快捷键说明

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