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

📄 os_core.lst

📁 《增强型8051单片机实用开发技术》例程代码
💻 LST
📖 第 1 页 / 共 5 页
字号:
 571          *
 572          * Returns    : none
 573          *
 574          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
 575          *********************************************************************************************************
 576          */
 577          #if OS_EVENT_EN > 0
 578          INT8U  OS_EventTaskRdy (OS_EVENT *pevent, void *msg, INT8U msk) reentrant
 579          {
 580   1          OS_TCB *ptcb;
 581   1          INT8U   x;
 582   1          INT8U   y;
 583   1          INT8U   bitx;
 584   1          INT8U   bity;
 585   1          INT8U   prio;
 586   1      
 587   1      
 588   1          y    = OSUnMapTbl[pevent->OSEventGrp];            /* Find highest prio. task waiting for message   */
 589   1          bity = OSMapTbl[y];
 590   1          x    = OSUnMapTbl[pevent->OSEventTbl[y]];
 591   1          bitx = OSMapTbl[x];
 592   1          prio = (INT8U)((y << 3) + x);                     /* Find priority of task getting the msg         */
 593   1          if ((pevent->OSEventTbl[y] &= ~bitx) == 0x00) {   /* Remove this task from the waiting list        */
 594   2              pevent->OSEventGrp &= ~bity;                  /* Clr group bit if this was only task pending   */
 595   2          }
 596   1          ptcb                 =  OSTCBPrioTbl[prio];       /* Point to this task's OS_TCB                   */
 597   1          ptcb->OSTCBDly       =  0;                        /* Prevent OSTimeTick() from readying task       */
 598   1          ptcb->OSTCBEventPtr  = (OS_EVENT *)0;             /* Unlink ECB from this task                     */
 599   1      #if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0)
                  ptcb->OSTCBMsg       = msg;                       /* Send message directly to waiting task         */
              #else
 602   1          msg                  = msg;                       /* Prevent compiler warning if not used          */
 603   1      #endif
 604   1          ptcb->OSTCBStat     &= ~msk;                      /* Clear bit associated with event type          */
 605   1          if (ptcb->OSTCBStat == OS_STAT_RDY) {             /* See if task is ready (could be susp'd)        */
 606   2              OSRdyGrp        |=  bity;                     /* Put task in the ready to run list             */
 607   2              OSRdyTbl[y]     |=  bitx;
 608   2          }
 609   1          return (prio);
 610   1      }
 611          #endif
 612          /*$PAGE*/
 613          /*
 614          *********************************************************************************************************
 615          *                                   MAKE TASK WAIT FOR EVENT TO OCCUR
 616          *
 617          * Description: This function is called by other uC/OS-II services to suspend a task because an event has
 618          *              not occurred.
 619          *
 620          * Arguments  : pevent   is a pointer to the event control block for which the task will be waiting for.
 621          *
 622          * Returns    : none
 623          *
C51 COMPILER V8.18   OS_CORE                                                               11/30/2009 13:25:39 PAGE 12  

 624          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
 625          *********************************************************************************************************
 626          */
 627          #if OS_EVENT_EN > 0
 628          void  OS_EventTaskWait (OS_EVENT *pevent) reentrant
 629          {
 630   1          OSTCBCur->OSTCBEventPtr = pevent;            /* Store pointer to event control block in TCB        */
 631   1          if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0x00) {   /* Task no longer ready      */
 632   2              OSRdyGrp &= ~OSTCBCur->OSTCBBitY;        /* Clear event grp bit if this was only task pending  */
 633   2          }
 634   1          pevent->OSEventTbl[OSTCBCur->OSTCBY] |= OSTCBCur->OSTCBBitX;          /* Put task in waiting list  */
 635   1          pevent->OSEventGrp                   |= OSTCBCur->OSTCBBitY;
 636   1      }
 637          #endif
 638          /*$PAGE*/
 639          /*
 640          *********************************************************************************************************
 641          *                              MAKE TASK READY TO RUN BASED ON EVENT TIMEOUT
 642          *
 643          * Description: This function is called by other uC/OS-II services to make a task ready to run because a
 644          *              timeout occurred.
 645          *
 646          * Arguments  : pevent   is a pointer to the event control block which is readying a task.
 647          *
 648          * Returns    : none
 649          *
 650          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
 651          *********************************************************************************************************
 652          */
 653          #if OS_EVENT_EN > 0
 654          void  OS_EventTO (OS_EVENT *pevent) reentrant
 655          {
 656   1          if ((pevent->OSEventTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0x00) {
 657   2              pevent->OSEventGrp &= ~OSTCBCur->OSTCBBitY;
 658   2          }
 659   1          OSTCBCur->OSTCBStat     = OS_STAT_RDY;       /* Set status to ready                                */
 660   1          OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;     /* No longer waiting for event                        */
 661   1      }
 662          #endif
 663          /*$PAGE*/
 664          /*
 665          *********************************************************************************************************
 666          *                                 INITIALIZE EVENT CONTROL BLOCK'S WAIT LIST
 667          *
 668          * Description: This function is called by other uC/OS-II services to initialize the event wait list.
 669          *
 670          * Arguments  : pevent    is a pointer to the event control block allocated to the event.
 671          *
 672          * Returns    : none
 673          *
 674          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
 675          *********************************************************************************************************
 676          */
 677          #if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0) || (OS_SEM_EN > 0) || (OS_MUTEX_EN > 0)
 678          void  OS_EventWaitListInit (OS_EVENT *pevent) reentrant
 679          {
 680   1          INT8U  *ptbl;
 681   1      
 682   1      
 683   1          pevent->OSEventGrp = 0x00;                   /* No task waiting on event                           */
 684   1          ptbl               = &pevent->OSEventTbl[0];
 685   1      
C51 COMPILER V8.18   OS_CORE                                                               11/30/2009 13:25:39 PAGE 13  

 686   1      #if OS_EVENT_TBL_SIZE > 0
 687   1          *ptbl++            = 0x00;
 688   1      #endif
 689   1      
 690   1      #if OS_EVENT_TBL_SIZE > 1
                  *ptbl++            = 0x00;
              #endif
 693   1      
 694   1      #if OS_EVENT_TBL_SIZE > 2
                  *ptbl++            = 0x00;
              #endif
 697   1      
 698   1      #if OS_EVENT_TBL_SIZE > 3
                  *ptbl++            = 0x00;
              #endif
 701   1      
 702   1      #if OS_EVENT_TBL_SIZE > 4
                  *ptbl++            = 0x00;
              #endif
 705   1      
 706   1      #if OS_EVENT_TBL_SIZE > 5
                  *ptbl++            = 0x00;
              #endif
 709   1      
 710   1      #if OS_EVENT_TBL_SIZE > 6
                  *ptbl++            = 0x00;
              #endif
 713   1      
 714   1      #if OS_EVENT_TBL_SIZE > 7
                  *ptbl              = 0x00;
              #endif
 717   1      }
 718          #endif
 719          /*$PAGE*/
 720          /*
 721          *********************************************************************************************************
 722          *                                              SCHEDULER
 723          *
 724          * Description: This function is called by other uC/OS-II services to determine whether a new, high
 725          *              priority task has been made ready to run.  This function is invoked by TASK level code
 726          *              and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
 727          *
 728          * Arguments  : none
 729          *
 730          * Returns    : none
 731          *
 732          * Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
 733          *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
 734          *********************************************************************************************************
 735          */
 736          
 737          void  OS_Sched (void) reentrant
 738          {
 739   1      #if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register     */
                  OS_CPU_SR  cpu_sr;
              #endif    
 742   1          INT8U      y;
 743   1      
 744   1      
 745   1          OS_ENTER_CRITICAL();
 746   1          if ((OSIntNesting == 0) && (OSLockNesting == 0)) { /* Sched. only if all ISRs done & not locked    */
 747   2              y             = OSUnMapTbl[OSRdyGrp];          /* Get pointer to HPT ready to run              */
C51 COMPILER V8.18   OS_CORE                                                               11/30/2009 13:25:39 PAGE 14  

 748   2              OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
 749   2              if (OSPrioHighRdy != OSPrioCur) {              /* No Ctx Sw if current task is highest rdy     */
 750   3                  OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
 751   3                  OSCtxSwCtr++;                              /* Increment context switch counter             */
 752   3                  OS_TASK_SW();                              /* Perform a context switch                     */
 753   3              }
 754   2          }
 755   1          OS_EXIT_CRITICAL();
 756   1      }
 757          /*$PAGE*/
 758          /*
 759          *********************************************************************************************************
 760          *                                              IDLE TASK
 761          *
 762          * Description: This task is internal to uC/OS-II and executes whenever no other higher priority tasks
 763          *              executes because they are ALL waiting for event(s) to occur.
 764          *
 765          * Arguments  : none
 766          *
 767          * Returns    : none
 768          *
 769          * Note(s)    : 1) OSTaskIdleHook() is called after the critical section to ensure that interrupts will be
 770          *                 enabled for at least a few instructions.  On some processors (ex. Philips XA), enabling
 771          *                 and then disabling interrupts didn't allow the processor enough time to have interrupts
 772          *                 enabled before they were disabled again.  uC/OS-II would thus never recognize
 773          *                 interrupts.
 774          *              2) This hook has been added to allow you to do such things as STOP the CPU to conserve 
 775          *                 power.
 776          *********************************************************************************************************
 777          */
 778          
 779          void  OS_TaskIdle (void *ppdata) reentrant
 780          {
 781   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */

⌨️ 快捷键说明

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