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

📄 os_core.lst

📁 时间触发式单片机最小系统
💻 LST
📖 第 1 页 / 共 4 页
字号:
 425          *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
 426          *********************************************************************************************************
C51 COMPILER V7.10   OS_CORE                                                               08/23/2004 01:45:17 PAGE 8   

 427          */
 428          
 429          void OSSched (void)reentrant
 430          {
 431   1          INT8U y;
 432   1      
 433   1      
 434   1          OS_ENTER_CRITICAL();
 435   1          if ((OSLockNesting | OSIntNesting) == 0) {   /* Task scheduling must be enabled and not ISR level  */
 436   2              y             = OSUnMapTbl[OSRdyGrp];    /* Get pointer to highest priority task ready to run  */
 437   2              OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
 438   2              if (OSPrioHighRdy != OSPrioCur) {         /* No context switch if current task is highest ready */
 439   3                  OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
 440   3                  OSCtxSwCtr++;                        /* Increment context switch counter                   */
 441   3                  OSCtxSw();                        /* Perform a context switch                           */
 442   3              }
 443   2          }
 444   1          OS_EXIT_CRITICAL();
 445   1      }
 446          /*$PAGE*/
 447          /*
 448          *********************************************************************************************************
 449          *                                          PREVENT SCHEDULING
 450          *
 451          * Description: This function is used to prevent rescheduling to take place.  This allows your application
 452          *              to prevent context switches until you are ready to permit context switching.
 453          *
 454          * Arguments  : none
 455          *
 456          * Returns    : none
 457          *
 458          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every 
 459          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 460          *********************************************************************************************************
 461          */
 462          #if  OSSCHED_LOCK_EN
              void OSSchedLock (void)reentrant
              {
                  if (OSRunning == TRUE) {                     /* Make sure multitasking is running                  */
                      OS_ENTER_CRITICAL();
                      OSLockNesting++;                         /* Increment lock nesting level                       */
                      OS_EXIT_CRITICAL();
                  }
              }
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                          ENABLE SCHEDULING
              *
              * Description: This function is used to re-allow rescheduling.  
              *
              * Arguments  : none
              *
              * Returns    : none
              *
              * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every 
              *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
              *********************************************************************************************************
              */
              
              void OSSchedUnlock (void)reentrant
              {
C51 COMPILER V7.10   OS_CORE                                                               08/23/2004 01:45:17 PAGE 9   

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

 551          *                                             OSIdleCtr
 552          *                 CPU Usage (%) = 100 * (1 - ------------)
 553          *                                            OSIdleCtrMax
 554          *
 555          * Arguments  : none
 556          *
 557          * Returns    : none
 558          *********************************************************************************************************
 559          */
 560          
 561          #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
 575          /*$PAGE*/
 576          /*
 577          *********************************************************************************************************
 578          *                                              IDLE TASK
 579          *
 580          * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
 581          *              executes because they are waiting for event(s) to occur.
 582          *
 583          * Arguments  : none
 584          *
 585          * Returns    : none
 586          *********************************************************************************************************
 587          */
 588          void OSTaskIdle (void *dataptr)reentrant
 589          {
 590   1          //sendstring("\r\n空闲任务:");sendbyte(EA);   
 591   1          INT8U  i;
 592   1          dataptr = dataptr;    /* Prevent compiler warning for not using 'dataptr'     */
 593   1          //sendstring("\r\n空闲任务:");sendbyte(EA);
 594   1          OS_ENTER_CRITICAL();        
 595   1          OSIdleCtr++;
 596   1          OS_EXIT_CRITICAL();
 597   1          for(i=0;i<1;i++)
 598   1          {
 599   2            ;
 600   2          }
 601   1      }
 602          /*$PAGE*/
 603          /*
 604          *********************************************************************************************************
 605          *                                            STATISTICS TASK
 606          *
 607          * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
 608          *              multitasking environment.  Specifically, OSTaskStat() computes the CPU usage.
 609          *              CPU usage is determined by:
 610          *
 611          *                                          OSIdleCtr
 612          *                 OSCPUUsage = 100 * (1 - ------------)     (units are in %)
C51 COMPILER V7.10   OS_CORE                                                               08/23/2004 01:45:17 PAGE 11  

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

⌨️ 快捷键说明

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