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

📄 os_flag.lst

📁 在51上运行的小的OS系统
💻 LST
📖 第 1 页 / 共 5 页
字号:
 536          * Returns    : The flags in the event flag group that made the task ready or, 0 if a timeout or an error
 537          *              occurred.
 538          *
 539          * Called from: Task ONLY
 540          *
 541          * Note(s)    : 1) IMPORTANT, the behavior of this function has changed from PREVIOUS versions.  The
 542          *                 function NOW returns the flags that were ready INSTEAD of the current state of the
 543          *                 event flags.
 544          *********************************************************************************************************
 545          */
 546          
 547          OS_FLAGS  OSFlagPend (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT16U timeout, INT8U *err)
 548          {
 549              OS_FLAG_NODE  node;
 550              OS_FLAGS      flags_rdy;
 551              INT8U         result;
 552              BOOLEAN       consume;
 553          #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR     cpu_sr = 0;
C51 COMPILER V8.08   OS_FLAG                                                               08/04/2008 21:49:51 PAGE 11  

              #endif
 556          
 557          
 558          
 559          #if OS_ARG_CHK_EN > 0
 560              if (err == (INT8U *)0) {                               /* Validate 'err'                           */
 561                  return ((OS_FLAGS)0);
 562              }
 563              if (pgrp == (OS_FLAG_GRP *)0) {                        /* Validate 'pgrp'                          */
 564                  *err = OS_FLAG_INVALID_PGRP;
 565                  return ((OS_FLAGS)0);
 566              }
 567          #endif
 568              if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
 569                  *err = OS_ERR_PEND_ISR;                            /* ... can't PEND from an ISR               */
 570                  return ((OS_FLAGS)0);
 571              }
 572              if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {          /* Validate event block type                */
 573                  *err = OS_ERR_EVENT_TYPE;
 574                  return ((OS_FLAGS)0);
 575              }
 576              result = wait_type & OS_FLAG_CONSUME;
 577              if (result != (INT8U)0) {                             /* See if we need to consume the flags      */
 578                  wait_type &= ~OS_FLAG_CONSUME;
 579                  consume    = TRUE;
 580              } else {
 581                  consume    = FALSE;
 582              }
 583          /*$PAGE*/
 584              OS_ENTER_CRITICAL();
 585              switch (wait_type) {
 586                  case OS_FLAG_WAIT_SET_ALL:                         /* See if all required flags are set        */
 587                       flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
 588                       if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
 589                           if (consume == TRUE) {                    /* See if we need to consume the flags      */
 590                               pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we wanted      */
 591                           }
 592                           OSTCBCur->OSTCBFlagsRdy = flags_rdy;      /* Save flags that were ready               */
 593                           OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
 594                           *err                    = OS_NO_ERR;
 595                           return (flags_rdy);
 596                       } else {                                      /* Block task until events occur or timeout */
 597                           OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
 598                           OS_EXIT_CRITICAL();
 599                       }
 600                       break;
 601          
 602                  case OS_FLAG_WAIT_SET_ANY:
 603                       flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
 604                       if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag set                      */
 605                           if (consume == TRUE) {                    /* See if we need to consume the flags      */
 606                               pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we got         */
 607                           }
 608                           OSTCBCur->OSTCBFlagsRdy = flags_rdy;      /* Save flags that were ready               */
 609                           OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
 610                           *err                    = OS_NO_ERR;
 611                           return (flags_rdy);
 612                       } else {                                      /* Block task until events occur or timeout */
 613                           OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
 614                           OS_EXIT_CRITICAL();
 615                       }
 616                       break;
C51 COMPILER V8.08   OS_FLAG                                                               08/04/2008 21:49:51 PAGE 12  

 617          
 618          #if OS_FLAG_WAIT_CLR_EN > 0
 619                  case OS_FLAG_WAIT_CLR_ALL:                         /* See if all required flags are cleared    */
 620                       flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & flags; /* Extract only the bits we want        */
 621                       if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
 622                           if (consume == TRUE) {                    /* See if we need to consume the flags      */
 623                               pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we wanted        */
 624                           }
 625                           OSTCBCur->OSTCBFlagsRdy = flags_rdy;      /* Save flags that were ready               */
 626                           OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
 627                           *err                    = OS_NO_ERR;
 628                           return (flags_rdy);
 629                       } else {                                      /* Block task until events occur or timeout */
 630                           OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
 631                           OS_EXIT_CRITICAL();
 632                       }
 633                       break;
 634          
 635                  case OS_FLAG_WAIT_CLR_ANY:
 636                       flags_rdy = (OS_FLAGS)~pgrp->OSFlagFlags & flags; /* Extract only the bits we want        */
 637                       if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag cleared                  */
 638                           if (consume == TRUE) {                    /* See if we need to consume the flags      */
 639                               pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we got           */
 640                           }
 641                           OSTCBCur->OSTCBFlagsRdy = flags_rdy;      /* Save flags that were ready               */
 642                           OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
 643                           *err                    = OS_NO_ERR;
 644                           return (flags_rdy);
 645                       } else {                                      /* Block task until events occur or timeout */
 646                           OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
 647                           OS_EXIT_CRITICAL();
 648                       }
 649                       break;
 650          #endif
 651          
 652                  default:
 653                       OS_EXIT_CRITICAL();
 654                       flags_rdy = (OS_FLAGS)0;
 655                       *err      = OS_FLAG_ERR_WAIT_TYPE;
 656                       return (flags_rdy);
 657              }
 658              OS_Sched();                                            /* Find next HPT ready to run               */
 659              OS_ENTER_CRITICAL();
 660              if (OSTCBCur->OSTCBPendTO == TRUE) {                   /* Have we timed-out?                       */
 661                  OSTCBCur->OSTCBPendTO = FALSE;
 662                  OS_FlagUnlink(&node);
 663                  OSTCBCur->OSTCBStat   = OS_STAT_RDY;               /* Yes, make task ready-to-run              */
 664                  OS_EXIT_CRITICAL();
 665                  flags_rdy             = (OS_FLAGS)0;
 666                  *err                  = OS_TIMEOUT;                /* Indicate that we timed-out waiting       */
 667                  return (flags_rdy);
 668              }
 669              flags_rdy = OSTCBCur->OSTCBFlagsRdy;
 670              if (consume == TRUE) {                                 /* See if we need to consume the flags      */
 671                  switch (wait_type) {
 672                      case OS_FLAG_WAIT_SET_ALL:
 673                      case OS_FLAG_WAIT_SET_ANY:                     /* Clear ONLY the flags we got              */
 674                           pgrp->OSFlagFlags &= ~flags_rdy;
 675                           break;
 676          
 677          #if OS_FLAG_WAIT_CLR_EN > 0
 678                      case OS_FLAG_WAIT_CLR_ALL:
C51 COMPILER V8.08   OS_FLAG                                                               08/04/2008 21:49:51 PAGE 13  

 679                      case OS_FLAG_WAIT_CLR_ANY:                     /* Set   ONLY the flags we got              */
 680                           pgrp->OSFlagFlags |=  flags_rdy;
 681                           break;
 682          #endif
 683                      default:
 684                           OS_EXIT_CRITICAL();
 685                           *err = OS_FLAG_ERR_WAIT_TYPE;
 686                           return ((OS_FLAGS)0);
 687                  }
 688              }
 689              OS_EXIT_CRITICAL();
 690              *err = OS_NO_ERR;                                      /* Event(s) must have occurred              */
 691              return (flags_rdy);
 692          }
 693          /*$PAGE*/
 694          /*
 695          *********************************************************************************************************
 696          *                               GET FLAGS WHO CAUSED TASK TO BECOME READY
 697          *
 698          * Description: This function is called to obtain the flags that caused the task to become ready to run.
 699          *              In other words, this function allows you to tell "Who done it!".
 700          *
 701          * Arguments  : None
 702          *
 703          * Returns    : The flags that caused the task to be ready.
 704          *
 705          * Called from: Task ONLY
 706          *********************************************************************************************************
 707          */
 708          
 709          OS_FLAGS  OSFlagPendGetFlagsRdy (void)
 710          {
 711              OS_FLAGS      flags;
 712          #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR     cpu_sr = 0;
              #endif
 715          
 716          
 717          
 718              OS_ENTER_CRITICAL();
 719              flags = OSTCBCur->OSTCBFlagsRdy;
 720              OS_EXIT_CRITICAL();
 721              return (flags);
 722          }
 723          
 724          /*$PAGE*/
 725          /*
 726          *********************************************************************************************************
 727          *                                         POST EVENT FLAG BIT(S)
 728          *
 729          * Description: This function is called to set or clear some bits in an event flag group.  The bits to
 730          *              set or clear are specified by a 'bit mask'.
 731          *
 732          * Arguments  : pgrp          is a pointer to the desired event flag group.
 733          *
 734          *              flags         If 'opt' (see below) is OS_FLAG_SET, each bit that is set in 'flags' will
 735          *                            set the corresponding bit in the event flag group.  e.g. to set bits 0, 4
 736          *                            and 5 you would set 'flags' to:

⌨️ 快捷键说明

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