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

📄 os_core.lst

📁 1. UC/OS 8051中完全应用。 2. 显示各个任务的执行时间, 执行时间占总时间百分比, tick计数器 3.任务中信号量,消息以及消息队列的使用。 我自己仔细测试过了
💻 LST
📖 第 1 页 / 共 5 页
字号:
 574          */
 575          #if OS_EVENT_EN > 0
 576          INT8U  OS_EventTaskRdy (OS_EVENT *pevent, void *msg, INT8U msk) reentrant
 577          {
 578   1          OS_TCB *ptcb;
 579   1          INT8U   x;
 580   1          INT8U   y;
 581   1          INT8U   bitx;
 582   1          INT8U   bity;
 583   1          INT8U   prio;
 584   1      
 585   1      
 586   1          y    = OSUnMapTbl[pevent->OSEventGrp];            /* Find highest prio. task waiting for message   */
 587   1          bity = OSMapTbl[y];
 588   1          x    = OSUnMapTbl[pevent->OSEventTbl[y]];
 589   1          bitx = OSMapTbl[x];
 590   1          prio = (INT8U)((y << 3) + x);                     /* Find priority of task getting the msg         */
 591   1          if ((pevent->OSEventTbl[y] &= ~bitx) == 0x00) {   /* Remove this task from the waiting list        */
 592   2              pevent->OSEventGrp &= ~bity;                  /* Clr group bit if this was only task pending   */
 593   2          }
 594   1          ptcb                 =  OSTCBPrioTbl[prio];       /* Point to this task's OS_TCB                   */
 595   1          ptcb->OSTCBDly       =  0;                        /* Prevent OSTimeTick() from readying task       */
 596   1          ptcb->OSTCBEventPtr  = (OS_EVENT *)0;             /* Unlink ECB from this task                     */
 597   1      #if ((OS_Q_EN > 0) && (OS_MAX_QS > 0)) || (OS_MBOX_EN > 0)
 598   1          ptcb->OSTCBMsg       = msg;                       /* Send message directly to waiting task         */
 599   1      #else
                  msg                  = msg;                       /* Prevent compiler warning if not used          */
              #endif
 602   1          ptcb->OSTCBStat     &= ~msk;                      /* Clear bit associated with event type          */
 603   1          if (ptcb->OSTCBStat == OS_STAT_RDY) {             /* See if task is ready (could be susp'd)        */
 604   2              OSRdyGrp        |=  bity;                     /* Put task in the ready to run list             */
 605   2              OSRdyTbl[y]     |=  bitx;
 606   2          }
 607   1          return (prio);
 608   1      }
 609          #endif
 610          /*$PAGE*/
 611          /*
 612          *********************************************************************************************************
 613          *                                   MAKE TASK WAIT FOR EVENT TO OCCUR
 614          *
 615          * Description: This function is called by other uC/OS-II services to suspend a task because an event has
 616          *              not occurred.
 617          *
 618          * Arguments  : pevent   is a pointer to the event control block for which the task will be waiting for.
 619          *
 620          * Returns    : none
 621          *
 622          * Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
 623          *********************************************************************************************************
C51 COMPILER V8.08   OS_CORE                                                               08/19/2008 10:59:08 PAGE 12  

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

 686   1      #endif
 687   1      
 688   1      #if OS_EVENT_TBL_SIZE > 1
 689   1          *ptbl++            = 0x00;
 690   1      #endif
 691   1      
 692   1      #if OS_EVENT_TBL_SIZE > 2
 693   1          *ptbl++            = 0x00;
 694   1      #endif
 695   1      
 696   1      #if OS_EVENT_TBL_SIZE > 3
 697   1          *ptbl++            = 0x00;
 698   1      #endif
 699   1      
 700   1      #if OS_EVENT_TBL_SIZE > 4
                  *ptbl++            = 0x00;
              #endif
 703   1      
 704   1      #if OS_EVENT_TBL_SIZE > 5
                  *ptbl++            = 0x00;
              #endif
 707   1      
 708   1      #if OS_EVENT_TBL_SIZE > 6
                  *ptbl++            = 0x00;
              #endif
 711   1      
 712   1      #if OS_EVENT_TBL_SIZE > 7
                  *ptbl              = 0x00;
              #endif
 715   1      }
 716          #endif
 717          /*$PAGE*/
 718          /*
 719          *********************************************************************************************************
 720          *                                              SCHEDULER
 721          *
 722          * Description: This function is called by other uC/OS-II services to determine whether a new, high
 723          *              priority task has been made ready to run.  This function is invoked by TASK level code
 724          *              and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
 725          *
 726          * Arguments  : none
 727          *
 728          * Returns    : none
 729          *
 730          * Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
 731          *              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
 732          *********************************************************************************************************
 733          */
 734          
 735          void  OS_Sched (void) reentrant
 736          {
 737   1      #if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register     */
                  OS_CPU_SR  cpu_sr;
              #endif    
 740   1          INT8U      y;
 741   1      
 742   1      
 743   1          OS_ENTER_CRITICAL();
 744   1          if ((OSIntNesting == 0) && (OSLockNesting == 0)) { /* Sched. only if all ISRs done & not locked    */
 745   2              y             = OSUnMapTbl[OSRdyGrp];          /* Get pointer to HPT ready to run              */
 746   2              OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
 747   2              if (OSPrioHighRdy != OSPrioCur) {              /* No Ctx Sw if current task is highest rdy     */
C51 COMPILER V8.08   OS_CORE                                                               08/19/2008 10:59:08 PAGE 14  

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

⌨️ 快捷键说明

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