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

📄 os_core.lst

📁 基于51单片机来实现UCOS用一个串口来看到实现阶段
💻 LST
📖 第 1 页 / 共 2 页
字号:
 248   1      
 249   1      
 250   1          OS_ENTER_CRITICAL();
 251   1          if ((OSLockNesting | OSIntNesting) == 0) {   /* Task scheduling must be enabled and not ISR level  */
 252   2              y             = OSUnMapTbl[OSRdyGrp];    /* Get pointer to highest priority task ready to run  */
 253   2              OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
 254   2              if (OSPrioHighRdy != OSPrioCur) {         /* No context switch if current task is highest ready */
 255   3                  OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
 256   3                  OSCtxSwCtr++;                        /* Increment context switch counter                   */
 257   3                  OSCtxSw();                        /* Perform a context switch                           */
 258   3              }
 259   2          }
 260   1          OS_EXIT_CRITICAL();
 261   1      }
 262          
 263          //任务调度锁
 264          #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();
                  }
              }
              
              //任务调度开锁
              void OSSchedUnlock (void)reentrant
              {
                  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
 293          
 294          //系统开始运行
 295          void OSStart (void)
 296          {
 297   1          INT8U y;
 298   1          INT8U x;
 299   1      
 300   1          if (OSRunning == FALSE) {
C51 COMPILER V7.02b   OS_CORE                                                              07/08/2007 20:25:02 PAGE 6   

 301   2              y             = OSUnMapTbl[OSRdyGrp];        /* Find highest priority's task priority number   */
 302   2              x             = OSUnMapTbl[OSRdyTbl[y]];
 303   2              OSPrioHighRdy = (INT8U)((y << 3) + x);
 304   2              OSPrioCur     = OSPrioHighRdy;
 305   2              OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
 306   2              OSTCBCur      = OSTCBHighRdy;
 307   2              OSStartHighRdy();                            /* Execute target specific code to start task     */
 308   2          }
 309   1      }
 310          
 311          //空闲任务例程
 312          void OSTaskIdle (void *dataptr)reentrant
 313          { 
 314   1          dataptr = dataptr; 
 315   1              while(1){
 316   2                  OS_ENTER_CRITICAL();        
 317   2                  OSIdleCtr++;
 318   2                  OS_EXIT_CRITICAL();
 319   2              }
 320   1      }
 321          #if OS_TASK_STAT_EN
 322          //统计任务初始化
 323          void OSStatInit (void)reentrant
 324          {
 325   1          OSTimeDly(2);                                /* Synchronize with clock tick                        */
 326   1          OS_ENTER_CRITICAL();
 327   1          OSIdleCtr    = 0L;                           /* Clear idle counter                                 */
 328   1          OS_EXIT_CRITICAL();
 329   1          OSTimeDly(OS_TICKS_PER_SEC);                 /* Determine MAX. idle counter value for 1 second     */
 330   1          OS_ENTER_CRITICAL();
 331   1          OSIdleCtrMax = OSIdleCtr;                    /* Store maximum idle counter count in 1 second       */
 332   1          OSStatRdy    = TRUE;
 333   1          OS_EXIT_CRITICAL();
 334   1      }
 335          
 336          //统计任务例程
 337          void OSTaskStat(void *dataptr)reentrant
 338          {
 339   1          INT32U run;
 340   1          INT8S  usage;
 341   1      
 342   1              OSStatInit();
 343   1          dataptr = dataptr;                               /* Prevent compiler warning for not using 'dataptr'  
             -   */
 344   1          while (OSStatRdy == FALSE) {
 345   2              OSTimeDly(2 * OS_TICKS_PER_SEC);             /* Wait until statistic task is ready           */
 346   2          }
 347   1          for (;;) {
 348   2              OS_ENTER_CRITICAL();
 349   2              OSIdleCtrRun = OSIdleCtr;                /* Obtain the of the idle counter for the past second */
 350   2              run          = OSIdleCtr;
 351   2              OSIdleCtr    = 0L;                       /* Reset the idle counter for the next second         */
 352   2              OS_EXIT_CRITICAL();
 353   2              if (OSIdleCtrMax > 0L) {
 354   3                  usage = (INT8S)(100L - 100L * run / OSIdleCtrMax);
 355   3                  if (usage > 100) {
 356   4                      OSCPUUsage = 100;
 357   4                  } else if (usage < 0) {
 358   4                      OSCPUUsage =   0;
 359   4                  } else {
 360   4                      OSCPUUsage = usage;
 361   4                  }
C51 COMPILER V7.02b   OS_CORE                                                              07/08/2007 20:25:02 PAGE 7   

 362   3              } else {
 363   3                  OSCPUUsage = 0;
 364   3              }
 365   2              OSTaskStatHook();                        /* Invoke user definable hook                         */
 366   2              OSTimeDly(OS_TICKS_PER_SEC);             /* Accumulate OSIdleCtr for the next second           */
 367   2          }
 368   1      }
 369          #endif
 370          
 371          //任务控制块初始化
 372          static OS_TCB *ptcb11;
 373          INT8U OSTCBInit (INT8U prio, 
 374                                           OS_STKCB *stkcb,
 375                                   INT16U id, 
 376                                   void *pext, 
 377                                   INT16U opt)reentrant
 378          {
 379   1          OS_ENTER_CRITICAL();
 380   1          ptcb11 = OSTCBFreeList;                                 
 381   1          if (ptcb11 != (OS_TCB *)0) {
 382   2              OSTCBFreeList        = ptcb11->OSTCBNext;            
 383   2              OS_EXIT_CRITICAL();
 384   2                      ptcb11->OSTCBStkCb     = stkcb;
 385   2              ptcb11->OSTCBStkPtr    = stkcb->OSTKBtomPtr ;                      
 386   2              ptcb11->OSTCBPrio      = (INT8U)prio;               
 387   2              ptcb11->OSTCBStat      = OS_STAT_RDY;               
 388   2              ptcb11->OSTCBDly       = 0;                        
 389   2      
 390   2      #if OS_TASK_CREATE_EXT_EN        
 391   2              ptcb11->OSTCBExtPtr    = pext;                      
 392   2              ptcb11->OSTCBStkSize   = OS_STK_SIZE;               
 393   2              ptcb11->OSTCBStkBottom = stkcb->OSTKBtomPtr;                       
 394   2              ptcb11->OSTCBOpt       = opt;                    
 395   2              ptcb11->OSTCBId        = id;                         
 396   2      #else
                      pext                 = pext;                      
                      stk_size             = OS_STK_SIZE;
                      opt                  = opt;
                      id                   = id;
              #endif
 402   2      
 403   2      #if OS_TASK_DEL_EN        
 404   2              ptcb11->OSTCBDelReq    = OS_NO_ERR;
 405   2      #endif
 406   2      
 407   2              ptcb11->OSTCBY         = prio >> 3;                  /* Pre-compute X, Y, BitX and BitY          *
             -/
 408   2              ptcb11->OSTCBBitY      = OSMapTbl[ptcb11->OSTCBY];
 409   2              ptcb11->OSTCBX         = prio & 0x07;
 410   2              ptcb11->OSTCBBitX      = OSMapTbl[ptcb11->OSTCBX];
 411   2      
 412   2      #if     OS_MBOX_EN || (OS_Q_EN && (OS_MAX_QS >= 2)) || OS_Sem_EN
 413   2              ptcb11->OSTCBEventPtr  = (OS_EVENT *)0;              /* Task is not pending on an event          *
             -/
 414   2      #endif
 415   2      
 416   2      #if     OS_MBOX_EN || (OS_Q_EN && (OS_MAX_QS >= 2))
                      ptcb11->OSTCBMsg       = (void *)0;                  /* No message received                      *
             -/
              #endif
 419   2      
 420   2              OS_ENTER_CRITICAL();
C51 COMPILER V7.02b   OS_CORE                                                              07/08/2007 20:25:02 PAGE 8   

 421   2              OSTCBPrioTbl[prio]   = ptcb11;
 422   2              ptcb11->OSTCBNext      = OSTCBList;                  /* Link into TCB chain                      *
             -/
 423   2              ptcb11->OSTCBPrev      = (OS_TCB *)0;
 424   2              if (OSTCBList != (OS_TCB *)0) {
 425   3                  OSTCBList->OSTCBPrev = ptcb11;
 426   3              }
 427   2              OSTCBList               = ptcb11;
 428   2              OSRdyGrp               |= ptcb11->OSTCBBitY;         /* Make task ready to run                   *
             -/
 429   2              OSRdyTbl[ptcb11->OSTCBY] |= ptcb11->OSTCBBitX;
 430   2              OS_EXIT_CRITICAL();
 431   2              return (OS_NO_ERR);
 432   2          } else {
 433   2              OS_EXIT_CRITICAL();
 434   2              return (OS_NO_MORE_TCB);
 435   2          }
 436   1      }
 437          
 438          //要求分配堆栈控制块
 439          OS_STKCB *OStkAsk(void)reentrant{
 440   1                          OS_STKCB * stkcb;
 441   1                              if(OSTKCBFreeList==0){
 442   2                                return(OS_NO_MORE_OSTK);
*** WARNING C196 IN LINE 442 OF OS_CORE.C: mspace probably invalid
 443   2                              }else{
 444   2                       stkcb=OSTKCBFreeList;
 445   2                               OSTKCBFreeList=OSTKCBFreeList->OSTKCBNext;
 446   2                              return(stkcb);
 447   2                      }  
 448   1      }
 449          
 450          //时间片中断处理
 451          void OSTimeTick (void)
 452          {
 453   1          OS_TCB *ptcb;
 454   1      
 455   1          OSTimeTickHook();                                      /* Call user definable hook                 */
 456   1          ptcb = OSTCBList;                                      /* Point at first TCB in TCB list           */
 457   1          while (ptcb->OSTCBPrio != OS_IDLE_PRIO) {              /* Go through all TCBs in TCB list          */
 458   2              OS_ENTER_CRITICAL();
 459   2              if (ptcb->OSTCBDly != 0) {                         /* Delayed or waiting for event with TO     */
 460   3                  if (--ptcb->OSTCBDly == 0) {                   /* Decrement nbr of ticks to end of delay   */
 461   4                      if (!(ptcb->OSTCBStat & OS_STAT_SUSPEND)) {    /* Is task suspended?                   */
 462   5                          OSRdyGrp               |= ptcb->OSTCBBitY; /* No,  Make task Rdy to Run (timed out)*/
 463   5                          OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
 464   5                      } else {                                       /* Yes, Leave 1 tick to prevent ...     */
 465   5                          ptcb->OSTCBDly = 1;                        /* ... loosing the task when the ...    */
 466   5                      }                                              /* ... suspension is removed.           */
 467   4                  }
 468   3              }
 469   2              ptcb = ptcb->OSTCBNext;                            /* Point at next TCB in TCB list            */
 470   2              OS_EXIT_CRITICAL();
 471   2          }
 472   1          OS_ENTER_CRITICAL();                                   /* Update the 32-bit tick counter           */
 473   1          OSTime++;
 474   1          OS_EXIT_CRITICAL();
 475   1      }
 476          
 477          //任务版本查询
 478          #if OS_VERSION_CHK_EN
              INT16U OSVersion (void)reentrant
C51 COMPILER V7.02b   OS_CORE                                                              07/08/2007 20:25:02 PAGE 9   

              {
                  return (OS_VERSION);
              }
              #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   3269    ----
   CONSTANT SIZE    =    264    ----
   XDATA SIZE       =    705       4
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     35    ----
   IDATA SIZE       =      9    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  1 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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