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

📄 os_core.lst

📁 在51上运行的小的OS系统
💻 LST
📖 第 1 页 / 共 4 页
字号:
 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) REENTRANT
 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      
C51 COMPILER V8.08   OS_CORE                                                               11/08/2008 14:01:47 PAGE 5   

 234   1              /* counters */
 235   1      #if OS_TASK_CREATE_EN  || OS_TASK_CREATE_EXT_EN || OS_TASK_DEL_EN
 236   1          OSTaskCtr     = 0;                                     /* Clear the number of tasks                */
 237   1      #endif
 238   1          OSRunning     = FALSE;                                 /* Indicate that multitasking not started   */
 239   1          OSIdleCtr     = 0L;                                    /* Clear the 32-bit idle counter            */
 240   1      #if OS_TASK_STAT_EN && OS_TASK_CREATE_EXT_EN                            
                  OSIdleCtrRun  = 0L;                                                                         /* current counter used for static */
                  OSIdleCtrMax  = 0L;                                                                         /* Max currrent used for statice */
                  OSStatRdy     = FALSE;                                 /* Statistic task is not ready              */
              #endif
 245   1          OSCtxSwCtr    = 0;                                     /* Clear the context switch counter         */
 246   1      
 247   1              /* read list, OS_RDY_TBL_SIZE = ((OS_LOWEST_PRIO) / 8 + 1) */
 248   1          OSRdyGrp      = 0;                                     /* Clear the ready list                     */
 249   1          for (i = 0; i < OS_RDY_TBL_SIZE; i++) {
 250   2              OSRdyTbl[i] = 0;
 251   2          }
 252   1          
 253   1          /* tcbs */
 254   1          OSPrioCur     = 0;
 255   1          OSPrioHighRdy = 0;                                           
 256   1          OSTCBHighRdy  = (OS_TCB DT_XDATA *)0;                                 /* TCB Initialization           
             -      */
 257   1          OSTCBCur      = (OS_TCB DT_XDATA *)0;
 258   1          OSTCBList     = (OS_TCB DT_XDATA *)0;                                                       /* TCB list. Note it isn't free tcb list */
 259   1      
 260   1              /* clear OSTCBPrioTbl */
 261   1          for (i = 0; i < (OS_LOWEST_PRIO + 1); i++) {                 /* Clear the priority table           */
 262   2              OSTCBPrioTbl[i] = (OS_TCB DT_XDATA *)0;
 263   2          }
 264   1      
 265   1              /* Init. list of free TCBs. OSTCBTbl is TCB list defined in OS_Core.c. OS_N_SYS_TASKS is system task nmbe
             -r.*/
 266   1          for (i = 0; i < (OS_MAX_TASKS + OS_N_SYS_TASKS - 1); i++) {  /* Init. list of free TCBs            */
 267   2              OSTCBTbl[i].OSTCBNext = &OSTCBTbl[i + 1];
 268   2          }
 269   1          OSTCBTbl[OS_MAX_TASKS + OS_N_SYS_TASKS - 1].OSTCBNext = (OS_TCB DT_XDATA *)0;    /* Last OS_TCB       
             -      */
 270   1          OSTCBFreeList                                         = &OSTCBTbl[0];
 271   1      
 272   1              /* Init. list of free EVENT control blocks  */
 273   1      #if OS_MAX_EVENTS >= 2
 274   1          for (i = 0; i < (OS_MAX_EVENTS - 1); i++) {            
 275   2              OSEventTbl[i].OSEventPtr = (OS_EVENT DT_XDATA *)&OSEventTbl[i + 1];
 276   2          }
 277   1          OSEventTbl[OS_MAX_EVENTS - 1].OSEventPtr = (OS_EVENT DT_XDATA *)0;
 278   1          OSEventFreeList                          = &OSEventTbl[0];    
 279   1      #endif
 280   1      
 281   1              /* Initialize the message queue structures  */
 282   1      #if OS_Q_EN && (OS_MAX_QS >= 2)
                  OSQInit();                                             
              #endif
 285   1      
 286   1              /* Initialize the memory manager            */
 287   1      #if OS_MEM_EN && OS_MAX_MEM_PART >= 2
                  OSMemInit();                                           
              #endif    
 290   1      
 291   1              /* creat OSTaskIdle task */
 292   1      #if OS_STK_GROWTH == 1
C51 COMPILER V8.08   OS_CORE                                                               11/08/2008 14:01:47 PAGE 6   

                  #if OS_TASK_CREATE_EXT_EN
                  OSTaskCreateExt(OSTaskIdle, 
                                  (void DT_XDATA *)0,                                 /* No arguments passed to OSTaskId
             -le()  */
                                  &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 DT_XDATA *)0,                                 /* No TCB extension               
             -      */
                                  OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stack  */
                  #else
                  OSTaskCreate(OSTaskIdle, (void DT_XDATA *)0, &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], OS_IDLE_PRIO);
             -        /* OS_IDLE _PROIO == OS_LOWEST_PROIO */
                  #endif
              #else
 307   1          #if OS_TASK_CREATE_EXT_EN
                  OSTaskCreateExt(OSTaskIdle, 
                                  (void DT_XDATA *)0,                                 /* No arguments passed to OSTaskId
             -le()  */
                                  &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 DT_XDATA *)0,                                 /* No TCB extension               
             -      */
                                  OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stack  */
                  #else
 318   1          OSTaskCreate(OSTaskIdle, (void DT_XDATA *)0, &OSTaskIdleStk[0], OS_IDLE_PRIO);
 319   1          #endif
 320   1      #endif
 321   1      
 322   1      #if OS_TASK_STAT_EN 
                  #if OS_TASK_CREATE_EXT_EN
                      #if OS_STK_GROWTH == 1
                      OSTaskCreateExt(OSTaskStat, 
                                      (void DT_XDATA *)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 DT_XDATA *)0,                                /* No TCB extension            
             -      */
                                      OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);  /* Enable stack checking + clear  */
                      #else
                      OSTaskCreateExt(OSTaskStat, 
                                      (void DT_XDATA *)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 DT_XDATA *)0,                                /* No TCB extension            
             -      */
                                      OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);  /* Enable stack checking + clear  */
                      #endif
                  #else
C51 COMPILER V8.08   OS_CORE                                                               11/08/2008 14:01:47 PAGE 7   

                      #if OS_STK_GROWTH == 1
                      OSTaskCreate(OSTaskStat, 
                                   (void DT_XDATA *)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 DT_XDATA *)0,                                   /* No args passed to OSTaskStat
             -()    */
                                   &OSTaskStatStk[0],                           /* Set Top-Of-Stack                  */
                                   OS_STAT_PRIO);                               /* One higher than the idle task     */
                      #endif
                  #endif
              #endif
 359   1      }
 360          /*$PAGE*/
 361          /*
 362          *********************************************************************************************************
 363          *                                              ENTER ISR
 364          *
 365          * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
 366          *              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
 367          *              only perform rescheduling at the last nested ISR.
 368          *
 369          * Arguments  : none
 370          *
 371          * Returns    : none
 372          *
 373          * Notes      : 1) Your ISR can directly increment OSIntNesting without calling this function because 
 374          *                 OSIntNesting has been declared 'global'.  You MUST, however, be sure that the increment
 375          *                 is performed 'indivisibly' by your processor to ensure proper access to this critical
 376          *                 resource.
 377          *              2) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
 378          *              3) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 379          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 380          *                 end of the ISR.
 381          *********************************************************************************************************
 382          */
 383          
 384          void OSIntEnter (void) REENTRANT
 385          {
 386   1          OS_ENTER_CRITICAL();
 387   1          OSIntNesting++;                              /* Increment ISR nesting level                        */
 388   1          OS_EXIT_CRITICAL();
 389   1      }
 390          /*$PAGE*/
 391          /*
 392          *********************************************************************************************************
 393          *                                               EXIT ISR
 394          *
 395          * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When 
 396          *              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
 397          *              a new, high-priority task, is ready to run.
 398          *
 399          * Arguments  : none
 400          *
 401          * Returns    : none
 402          *
 403          * Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 404          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 405          *                 end of the ISR.
C51 COMPILER V8.08   OS_CORE                                                               11/08/2008 14:01:47 PAGE 8   

 406          *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
 407          *********************************************************************************************************
 408          */
 409          
 410          void OSIntExit (void) REENTRANT
 411          {
 412   1          OS_ENTER_CRITICAL();
 413   1          if ((--OSIntNesting | OSLockNesting) == 0) { /* Reschedule only if all ISRs completed & not locked */
 414   2              OSIntExitY    = OSUnMapTbl[OSRdyGrp];
 415   2              OSPrioHighRdy = (INT8U)((OSIntExitY << 3) + OSUnMapTbl[OSRdyTbl[OSIntExitY]]);
 416   2              if (OSPrioHighRdy != OSPrioCur) {        /* No context switch if current task is highest ready */
 417   3                  OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
 418   3                  OSCtxSwCtr++;                        /* Keep track of the number of context switches       */
 419   3                  OSIntCtxSw();                        /* Perform interrupt level context switch             */
 420   3              }
 421   2          }

⌨️ 快捷键说明

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