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

📄 os_core.lst

📁 在C8051F120内移植uCOS-II
💻 LST
📖 第 1 页 / 共 4 页
字号:
             -  */
 449   2              OSPrioHighRdy      = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
 450   2              if (OSPrioHighRdy != OSPrioCur) {         /* No context switch if current task is highest ready */
 451   3                  OSTCBHighRdy   = OSTCBPrioTbl[OSPrioHighRdy];
 452   3                  OSCtxSwCtr++;                         /* Increment context switch counter                   */
 453   3                  OSCtxSw();                            /* Perform a context switch                           */
 454   3              }
 455   2          }
 456   1          OS_EXIT_CRITICAL();
 457   1      }
 458          /*$PAGE*/
 459          /*
 460          *********************************************************************************************************
 461          *                                          PREVENT SCHEDULING
 462          *
 463          * Description: This function is used to prevent rescheduling to take place.  This allows your application
 464          *              to prevent context switches until you are ready to permit context switching.
 465          *
 466          * Arguments  : none
 467          *
 468          * Returns    : none
 469          *
 470          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every 
 471          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 472          *********************************************************************************************************
 473          */
 474          #if  OSSCHED_LOCK_EN
              void OSSchedLock (void)reentrant
              {
                  #if OS_CRITICAL_METHOD == 2
                      unsigned DTYPE int_ss;
                      #endif 
              
                      if (OSRunning == TRUE) {                     /* Make sure multitasking is running                  */
                      OS_ENTER_CRITICAL();
                      OSLockNesting++;                         /* Increment lock nesting level                       */
C51 COMPILER V8.08   OS_CORE                                                               04/13/2009 13:31:21 PAGE 9   

                      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
              {
                  #if OS_CRITICAL_METHOD == 2
                      unsigned DTYPE int_ss;
                      #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 | 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
 525          /*$PAGE*/
 526          /*
 527          *********************************************************************************************************
 528          *                                          START MULTITASKING
 529          *
 530          * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
 531          *              task that you have created.  Before you can call OSStart(), you MUST have called OSInit()
 532          *              and you MUST have created at least one task.
 533          *
 534          * Arguments  : none
 535          *
 536          * Returns    : none
 537          *
 538          * Note       : OSStartHighRdy() MUST:
 539          *                 a) Call OSTaskSwHook() then,
 540          *                 b) Set OSRunning to TRUE.
 541          *********************************************************************************************************
 542          */
 543          
 544          void OSStart()
 545          {
C51 COMPILER V8.08   OS_CORE                                                               04/13/2009 13:31:21 PAGE 10  

 546   1          INT8U y;
 547   1          INT8U x;
 548   1      
 549   1      
 550   1          if(OSRunning == FALSE) 
 551   1              {
 552   2              y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's task priority number   */
 553   2              x             = OSUnMapTbl[OSRdyTbl[y]];
 554   2              OSPrioHighRdy = (INT8U)((y << 3) + x);
 555   2              OSPrioCur     = OSPrioHighRdy;
 556   2              OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
 557   2              OSTCBCur      = OSTCBHighRdy;
 558   2              OSStartHighRdy();                            /* Execute target specific code to start task     */
 559   2          }
 560   1      }
 561          /*$PAGE*/
 562          /*
 563          *********************************************************************************************************
 564          *                                        STATISTICS INITIALIZATION
 565          *
 566          * Description: This function is called by your application to establish CPU usage by first determining
 567          *              how high a 32-bit counter would count to in 1 second if no other tasks were to execute
 568          *              during that time.  CPU usage is then determined by a low priority task which keeps track
 569          *              of this 32-bit counter every second but this time, with other tasks running.  CPU usage is
 570          *              determined by:
 571          *
 572          *                                             OSIdleCtr
 573          *                 CPU Usage (%) = 100 * (1 - ------------)
 574          *                                            OSIdleCtrMax
 575          *
 576          * Arguments  : none
 577          *
 578          * Returns    : none
 579          *********************************************************************************************************
 580          */
 581          
 582          #if OS_TASK_STAT_EN
              void OSStatInit (void)reentrant
              {
                  #if OS_CRITICAL_METHOD == 2
                      unsigned DTYPE int_ss;
                      #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
 601          /*$PAGE*/
 602          /*
 603          *********************************************************************************************************
 604          *                                              IDLE TASK
 605          *
 606          * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
 607          *              executes because they are waiting for event(s) to occur.
C51 COMPILER V8.08   OS_CORE                                                               04/13/2009 13:31:21 PAGE 11  

 608          *
 609          * Arguments  : none
 610          *
 611          * Returns    : none
 612          *********************************************************************************************************
 613          */
 614          void OSTaskIdle (void *dataptr)reentrant
 615          {
 616   1          //sendstring("\r\n空闲任务:");sendbyte(EA);   
 617   1          #if OS_CRITICAL_METHOD == 2
 618   1              unsigned DTYPE int_ss;
 619   1              #endif 
 620   1      
 621   1              INT8U  i;
 622   1          dataptr = dataptr;    /* Prevent compiler warning for not using 'dataptr'     */
 623   1          //sendstring("\r\n空闲任务:");sendbyte(EA);
 624   1          OS_ENTER_CRITICAL();        
 625   1          OSIdleCtr++;
 626   1          OS_EXIT_CRITICAL();
 627   1          for(i=0;i<1;i++)
 628   1          {
 629   2            ;
 630   2          }
 631   1      }
 632          /*$PAGE*/
 633          /*
 634          *********************************************************************************************************
 635          *                                            STATISTICS TASK
 636          *
 637          * Description: This task is internal to uC/OS-II and is used to compute some statistics about the
 638          *              multitasking environment.  Specifically, OSTaskStat() computes the CPU usage.
 639          *              CPU usage is determined by:
 640          *
 641          *                                          OSIdleCtr
 642          *                 OSCPUUsage = 100 * (1 - ------------)     (units are in %)
 643          *                                         OSIdleCtrMax
 644          *
 645          * Arguments  : dataptr     this pointer is not used at this time.
 646          *
 647          * Returns    : none
 648          *
 649          * Notes      : 1) This task runs at a priority level higher than the idle task.  In fact, it runs at the
 650          *                 next higher priority, OS_IDLE_PRIO-1.
 651          *              2) You can disable this task by setting the configuration #define OS_TASK_STAT_EN to 0.
 652          *              3) We delay for 5 seconds in the beginning to allow the system to reach steady state and
 653          *                 have all other tasks created before we do statistics.  You MUST have at least a delay
 654          *                 of 2 seconds to allow for the system to establish the maximum value for the idle 
 655          *                 counter.
 656          *********************************************************************************************************
 657          */
 658          
 659          #if OS_TASK_STAT_EN
              void OSTaskStat (void *dataptr)reentrant
              {
                  INT32U run;
                  INT8S  usage;
                  #if OS_CRITICAL_METHOD == 2
                      unsigned DTYPE int_ss;
                      #endif 
                  
                  dataptr = dataptr;                               /* Prevent compiler warning for not using 'dataptr'  
             -   */
C51 COMPILER V8.08   OS_CORE                                                               04/13/2009 13:31:21 PAGE 12  

                  while (OSStatRdy == FALSE) {
                      OSTimeDly(2 * OS_TICKS_PER_SEC);             /* Wait until statistic task is ready                
             - */
                  }
                  for (;;) {
                      OS_ENTER_CRITICAL();
                      OSIdleCtrRun = OSIdleCtr;                /* Obtain the of the idle counter for the past second */
                      run          = OSIdleCtr;

⌨️ 快捷键说明

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