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

📄 os_core.lst

📁 实施操作系统的设计和开发
💻 LST
📖 第 1 页 / 共 5 页
字号:
                                        OS_IDLE_PRIO,                              /* Lowest priority level             
             -   */
                                        OS_TASK_IDLE_ID,
                                        &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], /* Set Bottom-Of-Stack               
             -   */
                                        OS_TASK_IDLE_STK_SIZE,
                                        (void *)0,                                 /* No TCB extension                  
             -   */
                                        OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stac
             -k  */
                  #endif
              #else
 182   1          #if OS_STK_GROWTH == 1
                  (void)OSTaskCreate(OS_TaskIdle,
                                     (void *)0,
                                     &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1],
                                     OS_IDLE_PRIO);
                  #else
 188   1          (void)OSTaskCreate(OS_TaskIdle,
 189   1                             (void *)0,
 190   1                             &OSTaskIdleStk[0],
 191   1                             OS_IDLE_PRIO);
 192   1          #endif
 193   1      #endif
 194   1      
 195   1          /* ------------------------------- CREATION OF 'STATISTIC' TASK ---------------------------------- */
 196   1      #if OS_TASK_STAT_EN > 0
                  #if OS_TASK_CREATE_EXT_EN > 0
                      #if OS_STK_GROWTH == 1
                      (void)OSTaskCreateExt(OS_TaskStat,
                                            (void *)0,                                   /* No args passed to OS_TaskSta
             -t()*/
                                            &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],   /* Set Top-Of-Stack            
             -   */
                                            OS_STAT_PRIO,                                /* One higher than the idle tas
             -k  */
                                            OS_TASK_STAT_ID,
                                            &OSTaskStatStk[0],                           /* Set Bottom-Of-Stack         
             -   */
C51 COMPILER V7.02b   OS_CORE                                                              11/29/2006 14:48:11 PAGE 5   

                                            OS_TASK_STAT_STK_SIZE,
                                            (void *)0,                                   /* No TCB extension            
             -   */
                                            OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);  /* Enable stack checking + clea
             -r  */
                      #else
                      (void)OSTaskCreateExt(OS_TaskStat,
                                            (void *)0,                                   /* No args passed to OS_TaskSta
             -t()*/
                                            &OSTaskStatStk[0],                           /* Set Top-Of-Stack            
             -   */
                                            OS_STAT_PRIO,                                /* One higher than the idle tas
             -k  */
                                            OS_TASK_STAT_ID,
                                            &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],   /* Set Bottom-Of-Stack         
             -   */
                                            OS_TASK_STAT_STK_SIZE,
                                            (void *)0,                                   /* No TCB extension            
             -   */
                                            OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);  /* Enable stack checking + clea
             -r  */
                      #endif
                  #else
                      #if OS_STK_GROWTH == 1
                      (void)OSTaskCreate(OS_TaskStat,
                                         (void *)0,                                      /* No args passed to OS_TaskSta
             -t()*/
                                         &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],      /* Set Top-Of-Stack            
             -   */
                                         OS_STAT_PRIO);                                  /* One higher than the idle tas
             -k  */
                      #else
                      (void)OSTaskCreate(OS_TaskStat,
                                         (void *)0,                                      /* No args passed to OS_TaskSta
             -t()*/
                                         &OSTaskStatStk[0],                              /* Set Top-Of-Stack            
             -   */
                                         OS_STAT_PRIO);                                  /* One higher than the idle tas
             -k  */
                      #endif
                  #endif
              #endif
 233   1      
 234   1      #if OS_VERSION >= 204
 235   1          OSInitHookEnd();                                                       /* Call port specific init. cod
             -e  */
 236   1      #endif
 237   1      }
 238          /*$PAGE*/
 239          /*
 240          *********************************************************************************************************
 241          *                                              ENTER ISR
 242          *
 243          * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
 244          *              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
 245          *              only perform rescheduling at the last nested ISR.
 246          *
 247          * Arguments  : none
 248          *
 249          * Returns    : none
 250          *
 251          * Notes      : 1) Your ISR can directly increment OSIntNesting without calling this function because
C51 COMPILER V7.02b   OS_CORE                                                              11/29/2006 14:48:11 PAGE 6   

 252          *                 OSIntNesting has been declared 'global'.  You MUST, however, be sure that the increment
 253          *                 is performed 'indivisibly' by your processor to ensure proper access to this critical
 254          *                 resource.
 255          *              2) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
 256          *              3) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 257          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 258          *                 end of the ISR.
 259          *********************************************************************************************************
 260          */
 261          
 262          void  OSIntEnter (void) reentrant
 263          {
 264   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif    
 267   1          
 268   1          
 269   1          OS_ENTER_CRITICAL();
 270   1          if (OSIntNesting < 255) {
 271   2              OSIntNesting++;                          /* Increment ISR nesting level                        */
 272   2          }
 273   1          OS_EXIT_CRITICAL();
 274   1      }
 275          /*$PAGE*/
 276          /*
 277          *********************************************************************************************************
 278          *                                               EXIT ISR
 279          *
 280          * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When
 281          *              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
 282          *              a new, high-priority task, is ready to run.
 283          *
 284          * Arguments  : none
 285          *
 286          * Returns    : none
 287          *
 288          * Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 289          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 290          *                 end of the ISR.
 291          *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
 292          *********************************************************************************************************
 293          */
 294          
 295          void  OSIntExit (void) reentrant
 296          {
 297   1      #if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register     */
                  OS_CPU_SR  cpu_sr;
              #endif
 300   1          
 301   1          
 302   1          OS_ENTER_CRITICAL();
 303   1          if (OSIntNesting > 0) {                            /* Prevent OSIntNesting from wrapping           */
 304   2              OSIntNesting--;
 305   2          }
 306   1          if ((OSIntNesting == 0) && (OSLockNesting == 0)) { /* Reschedule only if all ISRs complete ...     */
 307   2              OSIntExitY    = OSUnMapTbl[OSRdyGrp];          /* ... and not locked.                          */
 308   2              OSPrioHighRdy = (INT8U)((OSIntExitY << 3) + OSUnMapTbl[OSRdyTbl[OSIntExitY]]);
 309   2              if (OSPrioHighRdy != OSPrioCur) {              /* No Ctx Sw if current task is highest rdy     */
 310   3                  OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
 311   3                  OSCtxSwCtr++;                              /* Keep track of the number of context switches */
 312   3                  OSIntCtxSw();                              /* Perform interrupt level context switch       */
 313   3              }
C51 COMPILER V7.02b   OS_CORE                                                              11/29/2006 14:48:11 PAGE 7   

 314   2          }
 315   1          OS_EXIT_CRITICAL();
 316   1      }
 317          /*$PAGE*/
 318          /*
 319          *********************************************************************************************************
 320          *                                          PREVENT SCHEDULING
 321          *
 322          * Description: This function is used to prevent rescheduling to take place.  This allows your application
 323          *              to prevent context switches until you are ready to permit context switching.
 324          *
 325          * Arguments  : none
 326          *
 327          * Returns    : none
 328          *
 329          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 330          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
 331          *********************************************************************************************************
 332          */
 333          
 334          #if OS_SCHED_LOCK_EN > 0
              void  OSSchedLock (void) reentrant
              {
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif    
                  
                  
                  if (OSRunning == TRUE) {                     /* Make sure multitasking is running                  */
                      OS_ENTER_CRITICAL();
                      if (OSLockNesting < 255) {               /* Prevent OSLockNesting from wrapping back to 0      */
                          OSLockNesting++;                     /* Increment lock nesting level                       */
                      }
                      OS_EXIT_CRITICAL();
                  }
              }
              #endif    
 351          
 352          /*$PAGE*/
 353          /*
 354          *********************************************************************************************************
 355          *                                          ENABLE SCHEDULING
 356          *
 357          * Description: This function is used to re-allow rescheduling.
 358          *
 359          * Arguments  : none
 360          *
 361          * Returns    : none

⌨️ 快捷键说明

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