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

📄 os_core.lst

📁 该源码是本人经调试通过的UCOS2操作系统在51单片机上移植好的源代码
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V7.20   OS_CORE                                                               09/25/2006 10:08:38 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE OS_CORE
OBJECT MODULE PLACED IN OS_CORE.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE OS_CORE.C LARGE BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/OS-II
   4          *                                          The Real-Time Kernel
   5          *                                             CORE FUNCTIONS
   6          *
   7          *                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
   8          *                                           All Rights Reserved
   9          *
  10          * File : OS_CORE.C
  11          * By   : Jean J. Labrosse
  12          *********************************************************************************************************
  13          */
  14          
  15          #include "includes.h"
  16          
  17          /*
  18          *********************************************************************************************************
  19          *                              MAPPING TABLE TO MAP BIT POSITION TO BIT MASK
  20          *
  21          * Note: Index into table is desired bit position, 0..7
  22          *       Indexed value corresponds to bit mask
  23          *********************************************************************************************************
  24          */
  25          
  26          INT8U  const  OSMapTbl[]   = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
  27          
  28          /*
  29          *********************************************************************************************************
  30          *                                       PRIORITY RESOLUTION TABLE
  31          *
  32          * Note: Index into table is bit pattern to resolve highest priority
  33          *       Indexed value corresponds to highest priority bit position (i.e. 0..7)
  34          *********************************************************************************************************
  35          */
  36          
  37          INT8U  const  OSUnMapTbl[] = {
  38              0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x00 to 0x0F                             */
  39              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x10 to 0x1F                             */
  40              5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x20 to 0x2F                             */
  41              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x30 to 0x3F                             */
  42              6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x40 to 0x4F                             */
  43              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x50 to 0x5F                             */
  44              5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x60 to 0x6F                             */
  45              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x70 to 0x7F                             */
  46              7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x80 to 0x8F                             */
  47              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0x90 to 0x9F                             */
  48              5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xA0 to 0xAF                             */
  49              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xB0 to 0xBF                             */
  50              6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xC0 to 0xCF                             */
  51              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xD0 to 0xDF                             */
  52              5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,       /* 0xE0 to 0xEF                             */
  53              4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0        /* 0xF0 to 0xFF                             */
  54          };
  55          
C51 COMPILER V7.20   OS_CORE                                                               09/25/2006 10:08:38 PAGE 2   

  56          /*
  57          *********************************************************************************************************
  58          *                                       FUNCTION PROTOTYPES
  59          *********************************************************************************************************
  60          */
  61          static  void  OS_InitEventList(void) reentrant;
  62          static  void  OS_InitMisc(void) reentrant;
  63          static  void  OS_InitRdyList(void) reentrant;
  64          static  void  OS_InitTaskIdle(void) reentrant;
  65          static  void  OS_InitTaskStat(void) reentrant;
  66          static  void  OS_InitTCBList(void) reentrant;
  67          
  68          /*$PAGE*/
  69          /*
  70          *********************************************************************************************************
  71          *                                             INITIALIZATION
  72          *
  73          * Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
  74          *              creating any uC/OS-II object and, prior to calling OSStart().
  75          *
  76          * Arguments  : none
  77          *
  78          * Returns    : none
  79          *********************************************************************************************************
  80          */
  81          
  82          void  OSInit (void)  reentrant
  83          {
  84   1      #if OS_VERSION >= 204
  85   1          OSInitHookBegin();                                           /* Call port specific initialization code
             -   */
  86   1      #endif
  87   1      
  88   1          OS_InitMisc();                                               /* Initialize miscellaneous variables    
             -   */
  89   1      
  90   1          OS_InitRdyList();                                            /* Initialize the Ready List             
             -   */
  91   1          OS_InitTCBList();                                            /* Initialize the free list of OS_TCBs   
             -   */
  92   1          OS_InitEventList();                                          /* Initialize the free list of OS_EVENTs 
             -   */
  93   1      
  94   1      #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
                  OS_FlagInit();                                               /* Initialize the event flag structures  
             -   */
              #endif
  97   1      
  98   1      #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
                  OS_MemInit();                                                /* Initialize the memory manager         
             -   */
              #endif
 101   1      
 102   1      #if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
 103   1          OS_QInit();                                                  /* Initialize the message queue structure
             -s  */
 104   1      #endif
 105   1      
 106   1          OS_InitTaskIdle();                                           /* Create the Idle Task                  
             -   */
 107   1      #if OS_TASK_STAT_EN > 0
                  OS_InitTaskStat();                                           /* Create the Statistic Task             
C51 COMPILER V7.20   OS_CORE                                                               09/25/2006 10:08:38 PAGE 3   

             -   */
              #endif
 110   1      
 111   1      #if OS_VERSION >= 204
 112   1          OSInitHookEnd();                                             /* Call port specific init. code         
             -   */
 113   1      #endif
 114   1      }
 115          /*$PAGE*/
 116          /*
 117          *********************************************************************************************************
 118          *                                              ENTER ISR
 119          *
 120          * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
 121          *              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
 122          *              only perform rescheduling at the last nested ISR.
 123          *
 124          * Arguments  : none
 125          *
 126          * Returns    : none
 127          *
 128          * Notes      : 1) This function should be called ith interrupts already disabled
 129          *              2) Your ISR can directly increment OSIntNesting without calling this function because
 130          *                 OSIntNesting has been declared 'global'.  
 131          *              3) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
 132          *              4) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 133          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 134          *                 end of the ISR.
 135          *              5) You are allowed to nest interrupts up to 255 levels deep.
 136          *              6) I removed the OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() around the increment because
 137          *                 OSIntEnter() is always called with interrupts disabled.
 138          *********************************************************************************************************
 139          */
 140          
 141          void  OSIntEnter (void) reentrant
 142          {
 143   1          if (OSRunning == TRUE) {
 144   2              if (OSIntNesting < 255) {
 145   3                  OSIntNesting++;                      /* Increment ISR nesting level                        */
 146   3              }
 147   2          }
 148   1      }
 149          /*$PAGE*/
 150          /*
 151          *********************************************************************************************************
 152          *                                               EXIT ISR
 153          *
 154          * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When
 155          *              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
 156          *              a new, high-priority task, is ready to run.
 157          *
 158          * Arguments  : none
 159          *
 160          * Returns    : none
 161          *
 162          * Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 163          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 164          *                 end of the ISR.
 165          *              2) Rescheduling is prevented when the scheduler is locked (see OS_SchedLock())
 166          *********************************************************************************************************
 167          */
 168          
C51 COMPILER V7.20   OS_CORE                                                               09/25/2006 10:08:38 PAGE 4   

 169          void  OSIntExit (void) reentrant
 170          {
 171   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;
              #endif
 174   1          
 175   1          
 176   1          if (OSRunning == TRUE) {
 177   2              OS_ENTER_CRITICAL();
 178   2              if (OSIntNesting > 0) {                            /* Prevent OSIntNesting from wrapping       */
 179   3                  OSIntNesting--;
 180   3              }
 181   2              if ((OSIntNesting == 0) && (OSLockNesting == 0)) { /* Reschedule only if all ISRs complete ... */
 182   3                  OSIntExitY    = OSUnMapTbl[OSRdyGrp];          /* ... and not locked.                      */
 183   3                  OSPrioHighRdy = (INT8U)((OSIntExitY << 3) + OSUnMapTbl[OSRdyTbl[OSIntExitY]]);
 184   3                  if (OSPrioHighRdy != OSPrioCur) {              /* No Ctx Sw if current task is highest rdy */
 185   4                      OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
 186   4                      OSCtxSwCtr++;                              /* Keep track of the number of ctx switches */
 187   4                      OSIntCtxSw();                              /* Perform interrupt level ctx switch       */
 188   4                  }
 189   3              }
 190   2              OS_EXIT_CRITICAL();
 191   2          }
 192   1      }
 193          /*$PAGE*/
 194          /*
 195          *********************************************************************************************************
 196          *                                          PREVENT SCHEDULING
 197          *
 198          * Description: This function is used to prevent rescheduling to take place.  This allows your application
 199          *              to prevent context switches until you are ready to permit context switching.
 200          *
 201          * Arguments  : none
 202          *
 203          * Returns    : none
 204          *
 205          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 206          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().

⌨️ 快捷键说明

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