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

📄 os_core.lst

📁 ucos v2.62 安装程序 附带已移植到C8051F020的UCOS源码
💻 LST
📖 第 1 页 / 共 5 页
字号:
 223          *
 224          * Arguments  : none
 225          *
 226          * Returns    : none
 227          *********************************************************************************************************
 228          */
 229          
 230          void  OSInit (void)     KCREENTRANT     
 231          {
 232   1      #if OS_VERSION >= 204
 233   1          OSInitHookBegin();                                           /* Call port specific initialization code
             -   */
 234   1      #endif
 235   1      
 236   1          OS_InitMisc();                                               /* Initialize miscellaneous variables    
             -   */
 237   1      
 238   1          OS_InitRdyList();                                            /* Initialize the Ready List             
C51 COMPILER V8.05a   OS_CORE                                                              04/11/2007 16:19:49 PAGE 5   

             -   */
 239   1      
 240   1          OS_InitTCBList();                                            /* Initialize the free list of OS_TCBs   
             -   */
 241   1      
 242   1          OS_InitEventList();                                          /* Initialize the free list of OS_EVENTs 
             -   */
 243   1      
 244   1      #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
                  OS_FlagInit();                                               /* Initialize the event flag structures  
             -   */
              #endif
 247   1      
 248   1      #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
                  OS_MemInit();                                                /* Initialize the memory manager         
             -   */
              #endif
 251   1      
 252   1      #if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
                  OS_QInit();                                                  /* Initialize the message queue structure
             -s  */
              #endif
 255   1      
 256   1          OS_InitTaskIdle();                                           /* Create the Idle Task                  
             -   */
 257   1      #if OS_TASK_STAT_EN > 0
                  OS_InitTaskStat();                                           /* Create the Statistic Task             
             -   */
              #endif
 260   1      
 261   1      #if OS_VERSION >= 204
 262   1          OSInitHookEnd();                                             /* Call port specific init. code         
             -   */
 263   1      #endif
 264   1      }
 265          /*$PAGE*/
 266          /*
 267          *********************************************************************************************************
 268          *                                              ENTER ISR
 269          *
 270          * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
 271          *              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
 272          *              only perform rescheduling at the last nested ISR.
 273          *
 274          * Arguments  : none
 275          *
 276          * Returns    : none
 277          *
 278          * Notes      : 1) This function should be called ith interrupts already disabled
 279          *              2) Your ISR can directly increment OSIntNesting without calling this function because
 280          *                 OSIntNesting has been declared 'global'.  
 281          *              3) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
 282          *              4) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 283          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 284          *                 end of the ISR.
 285          *              5) You are allowed to nest interrupts up to 255 levels deep.
 286          *              6) I removed the OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() around the increment because
 287          *                 OSIntEnter() is always called with interrupts disabled.
 288          *********************************************************************************************************
 289          */
 290          
 291          void  OSIntEnter (void) KCREENTRANT
C51 COMPILER V8.05a   OS_CORE                                                              04/11/2007 16:19:49 PAGE 6   

 292          {
 293   1          if (OSRunning == TRUE) {
 294   2              if (OSIntNesting < 255u) {
 295   3                  OSIntNesting++;                      /* Increment ISR nesting level                        */
 296   3              }
 297   2          }
 298   1      }
 299          /*$PAGE*/
 300          /*
 301          *********************************************************************************************************
 302          *                                               EXIT ISR
 303          *
 304          * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When
 305          *              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
 306          *              a new, high-priority task, is ready to run.
 307          *
 308          * Arguments  : none
 309          *
 310          * Returns    : none
 311          *
 312          * Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 313          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 314          *                 end of the ISR.
 315          *              2) Rescheduling is prevented when the scheduler is locked (see OS_SchedLock())
 316          *********************************************************************************************************
 317          */
 318          
 319          void  OSIntExit (void) KCREENTRANT
 320          {
 321   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;
              #endif
 324   1          
 325   1          
 326   1          if (OSRunning == TRUE) {
 327   2              OS_ENTER_CRITICAL();
 328   2              if (OSIntNesting > 0) {                            /* Prevent OSIntNesting from wrapping       */
 329   3                  OSIntNesting--;
 330   3              }
 331   2              if (OSIntNesting == 0) {                           /* Reschedule only if all ISRs complete ... */
 332   3                  if (OSLockNesting == 0) {                      /* ... and not locked.                      */
 333   4                      OSIntExitY    = OSUnMapTbl[OSRdyGrp];          
 334   4                      OSPrioHighRdy = (INT8U)((OSIntExitY << 3) + OSUnMapTbl[OSRdyTbl[OSIntExitY]]);
 335   4                      if (OSPrioHighRdy != OSPrioCur) {          /* No Ctx Sw if current task is highest rdy */
 336   5                          OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
 337   5      #if OS_TASK_PROFILE_EN > 0
 338   5                          OSTCBHighRdy->OSTCBCtxSwCtr++;         /* Inc. # of context switches to this task  */
 339   5      #endif
 340   5                          OSCtxSwCtr++;                          /* Keep track of the number of ctx switches */
 341   5                          OSIntCtxSw();                          /* Perform interrupt level ctx switch       */
 342   5                      }
 343   4                  }
 344   3              }
 345   2              OS_EXIT_CRITICAL();
 346   2          }
 347   1      }
 348          /*$PAGE*/
 349          /*
 350          *********************************************************************************************************
 351          *                                          PREVENT SCHEDULING
 352          *
 353          * Description: This function is used to prevent rescheduling to take place.  This allows your application
C51 COMPILER V8.05a   OS_CORE                                                              04/11/2007 16:19:49 PAGE 7   

 354          *              to prevent context switches until you are ready to permit context switching.
 355          *
 356          * Arguments  : none
 357          *
 358          * Returns    : none
 359          *
 360          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 361          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 362          *********************************************************************************************************
 363          */
 364          
 365          #if OS_SCHED_LOCK_EN > 0
 366          void  OSSchedLock (void) KCREENTRANT    
 367          {
 368   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif    
 371   1          
 372   1          
 373   1          if (OSRunning == TRUE) {                     /* Make sure multitasking is running                  */
 374   2              OS_ENTER_CRITICAL();
 375   2              if (OSLockNesting < 255u) {              /* Prevent OSLockNesting from wrapping back to 0      */
 376   3                  OSLockNesting++;                     /* Increment lock nesting level                       */
 377   3              }
 378   2              OS_EXIT_CRITICAL();
 379   2          }
 380   1      }
 381          #endif    
 382          
 383          /*$PAGE*/
 384          /*
 385          *********************************************************************************************************
 386          *                                          ENABLE SCHEDULING
 387          *
 388          * Description: This function is used to re-allow rescheduling.
 389          *
 390          * Arguments  : none
 391          *
 392          * Returns    : none
 393          *
 394          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 395          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 396          *********************************************************************************************************
 397          */
 398          
 399          #if OS_SCHED_LOCK_EN > 0
 400          void  OSSchedUnlock (void) KCREENTRANT  
 401          {
 402   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;
              #endif    
 405   1          
 406   1          
 407   1          if (OSRunning == TRUE) {                                   /* Make sure multitasking is running    */
 408   2              OS_ENTER_CRITICAL();
 409   2              if (OSLockNesting > 0) {                               /* Do not decrement if already 0        */
 410   3                  OSLockNesting--;                                   /* Decrement lock nesting level         */
 411   3                  if (OSLockNesting == 0) {                          /* See if scheduler is enabled and ...  */
 412   4                      if (OSIntNesting == 0) {                       /* ... not in an ISR                    */
 413   5                          OS_EXIT_CRITICAL();
 414   5                          OS_Sched();                                /* See if a HPT is ready                */
 415   5                      } else {
C51 COMPILER V8.05a   OS_CORE                                                              04/11/2007 16:19:49 PAGE 8   

 416   5                          OS_EXIT_CRITICAL();
 417   5                      }
 418   4                  } else {
 419   4                      OS_EXIT_CRITICAL();
 420   4                  }
 421   3              } else {
 422   3                  OS_EXIT_CRITICAL();
 423   3              }
 424   2          }
 425   1      }
 426          #endif    
 427          
 428          /*$PAGE*/
 429          /*
 430          *********************************************************************************************************
 431          *                                          START MULTITASKING
 432          *
 433          * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
 434          *              task that you have created.  Before you can call OSStart(), you MUST have called OSInit()
 435          *              and you MUST have created at least one task.
 436          *
 437          * Arguments  : none
 438          *
 439          * Returns    : none
 440          *
 441          * Note       : OSStartHighRdy() MUST:

⌨️ 快捷键说明

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