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

📄 os_core.lst

📁 时间触发式单片机最小系统
💻 LST
📖 第 1 页 / 共 4 页
字号:
 208   2          }
 209   1      }
 210          #endif
 211          /*$PAGE*/
 212          /*
 213          *********************************************************************************************************
 214          *                                             INITIALIZATION
 215          *
 216          * Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
 217          *              creating any uC/OS-II object and, prior to calling OSStart().
 218          *
 219          * Arguments  : none
 220          *
 221          * Returns    : none
 222          *********************************************************************************************************
 223          */
 224          
 225          void OSInit (void)
 226          {
 227   1          INT16U i;
 228   1      
 229   1      
 230   1          OSTime        = 0L;                                    /* Clear the 32-bit system clock            */
 231   1          OSIntNesting  = 0;                                     /* Clear the interrupt nesting counter      */
 232   1          OSLockNesting = 0;                                     /* Clear the scheduling lock counter        */
 233   1      #if OS_TASK_CREATE_EN  || OS_TASK_CREATE_EXT_EN || OS_TASK_DEL_EN
 234   1          OSTaskCtr     = 0;                                     /* Clear the number of tasks                */
 235   1      #endif
 236   1          OSRunning     = FALSE;                                 /* Indicate that multitasking not started   */
 237   1          OSIdleCtr     = 0L;                                    /* Clear the 32-bit idle counter            */
 238   1      #if OS_TASK_STAT_EN && OS_TASK_CREATE_EXT_EN
                  OSIdleCtrRun  = 0L;
                  OSIdleCtrMax  = 0L;
C51 COMPILER V7.10   OS_CORE                                                               08/23/2004 01:45:17 PAGE 5   

                  OSStatRdy     = FALSE;                                 /* Statistic task is not ready              */
              #endif
 243   1          OSCtxSwCtr    = 0;                                     /* Clear the context switch counter         */
 244   1          OSRdyGrp      = 0;                                     /* Clear the ready list                     */
 245   1          for (i = 0; i < OS_RDY_TBL_SIZE; i++) {
 246   2              OSRdyTbl[i] = 0;
 247   2          }
 248   1                      
 249   1          OSPrioCur     = 0;
 250   1          OSPrioHighRdy = 0;                                           
 251   1          OSTCBHighRdy  = (OS_TCB *)0;                                 /* TCB Initialization                 */
 252   1          OSTCBCur      = (OS_TCB *)0;
 253   1          OSTCBList     = (OS_TCB *)0;
 254   1          for (i = 0; i < (OS_LOWEST_PRIO + 1); i++) {                 /* Clear the priority table           */
 255   2              OSTCBPrioTbl[i] = (OS_TCB *)0;
 256   2          }
 257   1          for (i = 0; i < (OS_MAX_TASKS + OS_N_SYS_TASKS - 1); i++) {  /* Init. list of free TCBs            */
 258   2              OSTCBTbl[i].OSTCBNext = &OSTCBTbl[i + 1];
 259   2          }
 260   1          OSTCBTbl[OS_MAX_TASKS + OS_N_SYS_TASKS - 1].OSTCBNext = (OS_TCB *)0;    /* Last OS_TCB             */
 261   1          OSTCBFreeList                                         = &OSTCBTbl[0];
 262   1      
 263   1      #if OS_MAX_EVENTS >= 2
 264   1          for (i = 0; i < (OS_MAX_EVENTS - 1); i++) {            /* Init. list of free EVENT control blocks  */
 265   2              OSEventTbl[i].OSEventPtr = (OS_EVENT *)&OSEventTbl[i + 1];
 266   2          }
 267   1          OSEventTbl[OS_MAX_EVENTS - 1].OSEventPtr = (OS_EVENT *)0;
 268   1          OSEventFreeList                          = &OSEventTbl[0];    
 269   1      #endif
 270   1      
 271   1      #if OS_Q_EN && (OS_MAX_QS >= 2)
                  OSQInit();                                             /* Initialize the message queue structures  */
              #endif
 274   1      
 275   1      #if OS_MEM_EN && OS_MAX_MEM_PART >= 2
                  OSMemInit();                                           /* Initialize the memory manager            */
              #endif    
 278   1      
 279   1      #if OS_STK_GROWTH == 1
 280   1          #if OS_TASK_CREATE_EXT_EN
                  OSTaskCreateExt(OSTaskIdle, 
                                  (void *)0,                                 /* No arguments passed to OSTaskIdle()  */
                                  &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], /* Set Top-Of-Stack                     */
                                  OS_IDLE_PRIO,                              /* Lowest priority level                */
                                  OS_TASK_IDLE_ID,
                                  &OSTaskIdleStk[0],                         /* 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 stack  */
                  #else
 291   1          OSTaskCreate(OSTaskIdle, (void *)0, &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], OS_IDLE_PRIO);
 292   1          #endif
 293   1      #else
                  #if OS_TASK_CREATE_EXT_EN
                  OSTaskCreateExt(OSTaskIdle, 
                                  (void *)0,                                 /* No arguments passed to OSTaskIdle()  */
                                  &OSTaskIdleStk[0],                         /* Set Top-Of-Stack                     */
                                  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                     */
C51 COMPILER V7.10   OS_CORE                                                               08/23/2004 01:45:17 PAGE 6   

                                  OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stack  */
                  #else
                  OSTaskCreate(OSTaskIdle, (void *)0, &OSTaskIdleStk[0], OS_IDLE_PRIO);
                  #endif
              #endif
 308   1      
 309   1      #if OS_TASK_STAT_EN 
                  #if OS_TASK_CREATE_EXT_EN
                      #if OS_STK_GROWTH == 1
                      OSTaskCreateExt(OSTaskStat, 
                                      (void *)0,                                /* No args passed to OSTaskStat()    */
                                      &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],/* Set Top-Of-Stack                  */
                                      OS_STAT_PRIO,                             /* One higher than the idle task     */
                                      OS_TASK_STAT_ID,
                                      &OSTaskStatStk[0],                        /* 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 + clear  */
                      #else
                      OSTaskCreateExt(OSTaskStat, 
                                      (void *)0,                                /* No args passed to OSTaskStat()    */
                                      &OSTaskStatStk[0],                        /* Set Top-Of-Stack                  */
                                      OS_STAT_PRIO,                             /* One higher than the idle task     */
                                      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 + clear  */
                      #endif
                  #else
                      #if OS_STK_GROWTH == 1
                      OSTaskCreate(OSTaskStat, 
                                   (void *)0,                                   /* No args passed to OSTaskStat()    */
                                   &OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],   /* Set Top-Of-Stack                  */
                                   OS_STAT_PRIO);                               /* One higher than the idle task     */
                      #else
                      OSTaskCreate(OSTaskStat, 
                                   (void *)0,                                   /* No args passed to OSTaskStat()    */
                                   &OSTaskStatStk[0],                           /* Set Top-Of-Stack                  */
                                   OS_STAT_PRIO);                               /* One higher than the idle task     */
                      #endif
                  #endif
              #endif
 346   1      }
 347          /*$PAGE*/
 348          /*
 349          *********************************************************************************************************
 350          *                                              ENTER ISR
 351          *
 352          * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
 353          *              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
 354          *              only perform rescheduling at the last nested ISR.
 355          *
 356          * Arguments  : none
 357          *
 358          * Returns    : none
 359          *
 360          * Notes      : 1) Your ISR can directly increment OSIntNesting without calling this function because 
 361          *                 OSIntNesting has been declared 'global'.  You MUST, however, be sure that the increment
 362          *                 is performed 'indivisibly' by your processor to ensure proper access to this critical
 363          *                 resource.
 364          *              2) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
C51 COMPILER V7.10   OS_CORE                                                               08/23/2004 01:45:17 PAGE 7   

 365          *              3) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 366          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 367          *                 end of the ISR.
 368          *********************************************************************************************************
 369          */
 370          
 371          void OSIntEnter (void)
 372          {
 373   1          OS_ENTER_CRITICAL();
 374   1          OSIntNesting++;                              /* Increment ISR nesting level                        */
 375   1          OS_EXIT_CRITICAL();
 376   1      }
 377          /*$PAGE*/
 378          /*
 379          *********************************************************************************************************
 380          *                                               EXIT ISR
 381          *
 382          * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When 
 383          *              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
 384          *              a new, high-priority task, is ready to run.
 385          *
 386          * Arguments  : none
 387          *
 388          * Returns    : none
 389          *
 390          * Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 391          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 392          *                 end of the ISR.
 393          *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
 394          *********************************************************************************************************
 395          */
 396          
 397          void OSIntExit (void)
 398          {
 399   1          OS_ENTER_CRITICAL();
 400   1          if ((--OSIntNesting | OSLockNesting) == 0) { /* Reschedule only if all ISRs completed & not locked */
 401   2              OSIntExitY    = OSUnMapTbl[OSRdyGrp];
 402   2              OSPrioHighRdy = (INT8U)((OSIntExitY << 3) + OSUnMapTbl[OSRdyTbl[OSIntExitY]]);
 403   2              if (OSPrioHighRdy != OSPrioCur) {        /* No context switch if current task is highest ready */
 404   3                  OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
 405   3                  OSCtxSwCtr++;                        /* Keep track of the number of context switches       */
 406   3                  OSIntCtxSw();                        /* Perform interrupt level context switch             */
 407   3              }
 408   2          }
 409   1          OS_EXIT_CRITICAL();
 410   1      }
 411          /*$PAGE*/
 412          /*
 413          *********************************************************************************************************
 414          *                                              SCHEDULER
 415          *
 416          * Description: This function is called by other uC/OS-II services to determine whether a new, high
 417          *              priority task has been made ready to run.  This function is invoked by TASK level code
 418          *              and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
 419          *
 420          * Arguments  : none
 421          *
 422          * Returns    : none
 423          *
 424          * Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.

⌨️ 快捷键说明

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