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

📄 os_core.lst

📁 UCOSII2.85针对8051单片机的移植版本
💻 LST
📖 第 1 页 / 共 5 页
字号:
 224   2              return;
 225   2          }
 226   1          (void)OS_StrCopy(pevent->OSEventName, pname);     /* Yes, copy name to the event control block     */
 227   1          OS_EXIT_CRITICAL();
 228   1          *perr = OS_ERR_NONE;
 229   1      }
 230          #endif
 231          
 232          /*$PAGE*/
 233          /*
 234          *********************************************************************************************************
 235          *                                             INITIALIZATION
 236          *
 237          * Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
 238          *              creating any uC/OS-II object and, prior to calling OSStart().
 239          *
 240          * Arguments  : none
C51 COMPILER V7.50   OS_CORE                                                               12/14/2007 08:25:29 PAGE 5   

 241          *
 242          * Returns    : none
 243          *********************************************************************************************************
 244          */
 245          
 246          void  OSInit (void) reentrant
 247          {
 248   1          OSInitHookBegin();                                           /* Call port specific initialization code
             -   */
 249   1      
 250   1          OS_InitMisc();                                               /* Initialize miscellaneous variables    
             -   */
 251   1      
 252   1          OS_InitRdyList();                                            /* Initialize the Ready List             
             -   */
 253   1      
 254   1          OS_InitTCBList();                                            /* Initialize the free list of OS_TCBs   
             -   */
 255   1      
 256   1          OS_InitEventList();                                          /* Initialize the free list of OS_EVENTs 
             -   */
 257   1      
 258   1      #if (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
                  OS_FlagInit();                                               /* Initialize the event flag structures  
             -   */
              #endif
 261   1      
 262   1      #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
                  OS_MemInit();                                                /* Initialize the memory manager         
             -   */
              #endif
 265   1      
 266   1      #if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
 267   1          OS_QInit();                                                  /* Initialize the message queue structure
             -s  */
 268   1      #endif
 269   1      
 270   1          OS_InitTaskIdle();                                           /* Create the Idle Task                  
             -   */
 271   1      #if OS_TASK_STAT_EN > 0
 272   1          OS_InitTaskStat();                                           /* Create the Statistic Task             
             -   */
 273   1      #endif
 274   1      
 275   1      #if OS_TMR_EN > 0
                  OSTmr_Init();                                                /* Initialize the Timer Manager          
             -   */
              #endif
 278   1      
 279   1          OSInitHookEnd();                                             /* Call port specific init. code         
             -   */
 280   1      
 281   1      #if OS_DEBUG_EN > 0
                  OSDebugInit();
              #endif
 284   1      }
 285          /*$PAGE*/
 286          /*
 287          *********************************************************************************************************
 288          *                                              ENTER ISR
 289          *
 290          * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
C51 COMPILER V7.50   OS_CORE                                                               12/14/2007 08:25:29 PAGE 6   

 291          *              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
 292          *              only perform rescheduling at the last nested ISR.
 293          *
 294          * Arguments  : none
 295          *
 296          * Returns    : none
 297          *
 298          * Notes      : 1) This function should be called ith interrupts already disabled
 299          *              2) Your ISR can directly increment OSIntNesting without calling this function because
 300          *                 OSIntNesting has been declared 'global'.
 301          *              3) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
 302          *              4) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 303          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 304          *                 end of the ISR.
 305          *              5) You are allowed to nest interrupts up to 255 levels deep.
 306          *              6) I removed the OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() around the increment because
 307          *                 OSIntEnter() is always called with interrupts disabled.
 308          *********************************************************************************************************
 309          */
 310          
 311          void  OSIntEnter (void) reentrant
 312          {
 313   1          if (OSRunning == OS_TRUE) {
 314   2              if (OSIntNesting < 255u) {
 315   3                  OSIntNesting++;                      /* Increment ISR nesting level                        */
 316   3              }
 317   2          }
 318   1      }
 319          /*$PAGE*/
 320          /*
 321          *********************************************************************************************************
 322          *                                               EXIT ISR
 323          *
 324          * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When
 325          *              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
 326          *              a new, high-priority task, is ready to run.
 327          *
 328          * Arguments  : none
 329          *
 330          * Returns    : none
 331          *
 332          * Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 333          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 334          *                 end of the ISR.
 335          *              2) Rescheduling is prevented when the scheduler is locked (see OS_SchedLock())
 336          *********************************************************************************************************
 337          */
 338          
 339          void  OSIntExit (void) reentrant
 340          {
 341   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 344   1      
 345   1      
 346   1      
 347   1          if (OSRunning == OS_TRUE) {
 348   2              OS_ENTER_CRITICAL();
 349   2              if (OSIntNesting > 0) {                            /* Prevent OSIntNesting from wrapping       */
 350   3                  OSIntNesting--;
 351   3              }
 352   2              if (OSIntNesting == 0) {                           /* Reschedule only if all ISRs complete ... */
C51 COMPILER V7.50   OS_CORE                                                               12/14/2007 08:25:29 PAGE 7   

 353   3                  if (OSLockNesting == 0) {                      /* ... and not locked.                      */
 354   4                      OS_SchedNew();
 355   4                      if (OSPrioHighRdy != OSPrioCur) {          /* No Ctx Sw if current task is highest rdy */
 356   5                          OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
 357   5      #if OS_TASK_PROFILE_EN > 0
 358   5                          OSTCBHighRdy->OSTCBCtxSwCtr++;         /* Inc. # of context switches to this task  */
 359   5      #endif
 360   5                          OSCtxSwCtr++;                          /* Keep track of the number of ctx switches */
 361   5                          OSIntCtxSw();                          /* Perform interrupt level ctx switch       */
 362   5                      }
 363   4                  }
 364   3              }
 365   2              OS_EXIT_CRITICAL();
 366   2          }
 367   1      }
 368          /*$PAGE*/
 369          /*
 370          *********************************************************************************************************
 371          *                                          PREVENT SCHEDULING
 372          *
 373          * Description: This function is used to prevent rescheduling to take place.  This allows your application
 374          *              to prevent context switches until you are ready to permit context switching.
 375          *
 376          * Arguments  : none
 377          *
 378          * Returns    : none
 379          *
 380          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 381          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 382          *********************************************************************************************************
 383          */
 384          
 385          #if OS_SCHED_LOCK_EN > 0
 386          void  OSSchedLock (void) reentrant
 387          {
 388   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 391   1      
 392   1      
 393   1      
 394   1          if (OSRunning == OS_TRUE) {                  /* Make sure multitasking is running                  */
 395   2              OS_ENTER_CRITICAL();
 396   2              if (OSIntNesting == 0) {                 /* Can't call from an ISR                             */
 397   3                  if (OSLockNesting < 255u) {          /* Prevent OSLockNesting from wrapping back to 0      */
 398   4                      OSLockNesting++;                 /* Increment lock nesting level                       */
 399   4                  }
 400   3              }
 401   2              OS_EXIT_CRITICAL();
 402   2          }
 403   1      }
 404          #endif
 405          
 406          /*$PAGE*/
 407          /*
 408          *********************************************************************************************************
 409          *                                          ENABLE SCHEDULING
 410          *
 411          * Description: This function is used to re-allow rescheduling.
 412          *
 413          * Arguments  : none
 414          *
C51 COMPILER V7.50   OS_CORE                                                               12/14/2007 08:25:29 PAGE 8   

 415          * Returns    : none
 416          *
 417          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 418          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 419          *********************************************************************************************************
 420          */
 421          
 422          #if OS_SCHED_LOCK_EN > 0
 423          void  OSSchedUnlock (void) reentrant
 424          {
 425   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 428   1      
 429   1      
 430   1      
 431   1          if (OSRunning == OS_TRUE) {                            /* Make sure multitasking is running        */
 432   2              OS_ENTER_CRITICAL();
 433   2              if (OSLockNesting > 0) {                           /* Do not decrement if already 0            */
 434   3                  OSLockNesting--;                               /* Decrement lock nesting level             */
 435   3                  if (OSLockNesting == 0) {                      /* See if scheduler is enabled and ...      */
 436   4                      if (OSIntNesting == 0) {                   /* ... not in an ISR                        */
 437   5                          OS_EXIT_CRITICAL();
 438   5                          OS_Sched();                            /* See if a HPT is ready                    */
 439   5                      } else {
 440   5                          OS_EXIT_CRITICAL();
 441   5                      }
 442   4                  } else {

⌨️ 快捷键说明

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