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

📄 os_core.lst

📁 在51上运行的小的OS系统
💻 LST
📖 第 1 页 / 共 5 页
字号:
 162          #if OS_EVENT_EN && (OS_EVENT_NAME_SIZE > 1)
 163          void  OSEventNameSet (OS_EVENT *pevent, INT8U *pname, INT8U *err)
 164          {
 165              INT8U      len;
 166          #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 169          
 170          
 171          
 172          #if OS_ARG_CHK_EN > 0
 173              if (err == (INT8U *)0) {                     /* Validate 'err'                                     */
 174                  return;
 175              }
 176              if (pevent == (OS_EVENT *)0) {               /* Is 'pevent' a NULL pointer?                        */
 177                  *err = OS_ERR_PEVENT_NULL;
 178                  return;
 179              }
 180              if (pname == (INT8U *)0) {                    /* Is 'pname' a NULL pointer?                         */
 181                  *err = OS_ERR_PNAME_NULL;
 182                  return;
 183              }
C51 COMPILER V8.08   OS_CORE                                                               08/04/2008 21:49:51 PAGE 5   

 184          #endif
 185              switch (pevent->OSEventType) {
 186                  case OS_EVENT_TYPE_SEM:
 187                  case OS_EVENT_TYPE_MUTEX:
 188                  case OS_EVENT_TYPE_MBOX:
 189                  case OS_EVENT_TYPE_Q:
 190                       break;
 191          
 192                  default:
 193                       *err = OS_ERR_EVENT_TYPE;
 194                       return;
 195              }
 196              OS_ENTER_CRITICAL();
 197              len = OS_StrLen(pname);                           /* Can we fit the string in the storage area?    */
 198              if (len > (OS_EVENT_NAME_SIZE - 1)) {             /* No                                            */
 199                  OS_EXIT_CRITICAL();
 200                  *err = OS_ERR_EVENT_NAME_TOO_LONG;
 201                  return;
 202              }
 203              (void)OS_StrCopy(pevent->OSEventName, pname);     /* Yes, copy name to the event control block     */
 204              OS_EXIT_CRITICAL();
 205              *err = OS_NO_ERR;
 206          }
 207          #endif
 208          
 209          /*$PAGE*/
 210          /*
 211          *********************************************************************************************************
 212          *                                             INITIALIZATION
 213          *
 214          * Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
 215          *              creating any uC/OS-II object and, prior to calling OSStart().
 216          *
 217          * Arguments  : none
 218          *
 219          * Returns    : none
 220          *********************************************************************************************************
 221          */
 222          
 223          void  OSInit (void)
 224          {
 225          #if OS_VERSION >= 204
 226              OSInitHookBegin();                                           /* Call port specific initialization code
             -   */
 227          #endif
 228          
 229              OS_InitMisc();                                               /* Initialize miscellaneous variables    
             -   */
 230          
 231              OS_InitRdyList();                                            /* Initialize the Ready List             
             -   */
 232          
 233              OS_InitTCBList();                                            /* Initialize the free list of OS_TCBs   
             -   */
 234          
 235              OS_InitEventList();                                          /* Initialize the free list of OS_EVENTs 
             -   */
 236          
 237          #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
 238              OS_FlagInit();                                               /* Initialize the event flag structures  
             -   */
 239          #endif
C51 COMPILER V8.08   OS_CORE                                                               08/04/2008 21:49:51 PAGE 6   

 240          
 241          #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
 242              OS_MemInit();                                                /* Initialize the memory manager         
             -   */
 243          #endif
 244          
 245          #if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
 246              OS_QInit();                                                  /* Initialize the message queue structure
             -s  */
 247          #endif
 248          
 249              OS_InitTaskIdle();                                           /* Create the Idle Task                  
             -   */
 250          #if OS_TASK_STAT_EN > 0
 251              OS_InitTaskStat();                                           /* Create the Statistic Task             
             -   */
 252          #endif
 253          
 254          #if OS_VERSION >= 204
 255              OSInitHookEnd();                                             /* Call port specific init. code         
             -   */
 256          #endif
 257          
 258          #if OS_VERSION >= 270 && OS_DEBUG_EN > 0
                  OSDebugInit();
              #endif
 261          }
 262          /*$PAGE*/
 263          /*
 264          *********************************************************************************************************
 265          *                                              ENTER ISR
 266          *
 267          * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
 268          *              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
 269          *              only perform rescheduling at the last nested ISR.
 270          *
 271          * Arguments  : none
 272          *
 273          * Returns    : none
 274          *
 275          * Notes      : 1) This function should be called ith interrupts already disabled
 276          *              2) Your ISR can directly increment OSIntNesting without calling this function because
 277          *                 OSIntNesting has been declared 'global'.
 278          *              3) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
 279          *              4) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 280          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 281          *                 end of the ISR.
 282          *              5) You are allowed to nest interrupts up to 255 levels deep.
 283          *              6) I removed the OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() around the increment because
 284          *                 OSIntEnter() is always called with interrupts disabled.
 285          *********************************************************************************************************
 286          */
 287          
 288          void  OSIntEnter (void)
 289          {
 290              if (OSRunning == TRUE) {
 291                  if (OSIntNesting < 255u) {
 292                      OSIntNesting++;                      /* Increment ISR nesting level                        */
 293                  }
 294              }
 295          }
 296          /*$PAGE*/
C51 COMPILER V8.08   OS_CORE                                                               08/04/2008 21:49:51 PAGE 7   

 297          /*
 298          *********************************************************************************************************
 299          *                                               EXIT ISR
 300          *
 301          * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When
 302          *              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
 303          *              a new, high-priority task, is ready to run.
 304          *
 305          * Arguments  : none
 306          *
 307          * Returns    : none
 308          *
 309          * Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
 310          *                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
 311          *                 end of the ISR.
 312          *              2) Rescheduling is prevented when the scheduler is locked (see OS_SchedLock())
 313          *********************************************************************************************************
 314          */
 315          
 316          void  OSIntExit (void)
 317          {
 318          #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 321          
 322          
 323          
 324              if (OSRunning == TRUE) {
 325                  OS_ENTER_CRITICAL();
 326                  if (OSIntNesting > 0) {                            /* Prevent OSIntNesting from wrapping       */
 327                      OSIntNesting--;
 328                  }
 329                  if (OSIntNesting == 0) {                           /* Reschedule only if all ISRs complete ... */
 330                      if (OSLockNesting == 0) {                      /* ... and not locked.                      */
 331                          OS_SchedNew();
 332                          if (OSPrioHighRdy != OSPrioCur) {          /* No Ctx Sw if current task is highest rdy */
 333                              OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
 334          #if OS_TASK_PROFILE_EN > 0
 335                              OSTCBHighRdy->OSTCBCtxSwCtr++;         /* Inc. # of context switches to this task  */
 336          #endif
 337                              OSCtxSwCtr++;                          /* Keep track of the number of ctx switches */
 338                              OSIntCtxSw();                          /* Perform interrupt level ctx switch       */
 339                          }
 340                      }
 341                  }
 342                  OS_EXIT_CRITICAL();
 343              }
 344          }
 345          /*$PAGE*/
 346          /*
 347          *********************************************************************************************************
 348          *                                          PREVENT SCHEDULING
 349          *
 350          * Description: This function is used to prevent rescheduling to take place.  This allows your application
 351          *              to prevent context switches until you are ready to permit context switching.
 352          *
 353          * Arguments  : none
 354          *
 355          * Returns    : none
 356          *
 357          * Notes      : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair.  In other words, for every
 358          *                 call to OSSchedLock() you MUST have a call to OSSchedUnlock().
C51 COMPILER V8.08   OS_CORE                                                               08/04/2008 21:49:51 PAGE 8   

 359          *********************************************************************************************************
 360          */
 361          
 362          #if OS_SCHED_LOCK_EN > 0
 363          void  OSSchedLock (void)
 364          {
 365          #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 368          
 369          
 370          
 371              if (OSRunning == TRUE) {                     /* Make sure multitasking is running                  */
 372                  OS_ENTER_CRITICAL();
 373                  if (OSLockNesting < 255u) {              /* Prevent OSLockNesting from wrapping back to 0      */
 374                      OSLockNesting++;                     /* Increment lock nesting level                       */
 375                  }
 376                  OS_EXIT_CRITICAL();

⌨️ 快捷键说明

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