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

📄 os_flag.lst

📁 一个关于UCOS的KEIL工程
💻 LST
📖 第 1 页 / 共 4 页
字号:
 452   3                       *err      = OS_NO_ERR;
 453   3                       return (flags_cur);
 454   3                   } else {                                      /* Block task until events occur or timeout */
 455   3                       OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
 456   3                       OS_EXIT_CRITICAL();
 457   3                   }
 458   2                   break;
 459   2      
 460   2              case OS_FLAG_WAIT_CLR_ANY:
 461   2                   flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we want            */
 462   2                   if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag cleared                  */
 463   3                       if (consume == TRUE) {                    /* See if we need to consume the flags      */
 464   4                           pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we got           */
 465   4                       }
 466   3                       flags_cur = pgrp->OSFlagFlags;            /* Will return the state of the group       */
 467   3                       OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
 468   3                       *err      = OS_NO_ERR;
 469   3                       return (flags_cur);
 470   3                   } else {                                      /* Block task until events occur or timeout */
 471   3                       OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
 472   3                       OS_EXIT_CRITICAL();
 473   3                   }
 474   2                   break;
 475   2      #endif
 476   2      
 477   2              default:
 478   2                   OS_EXIT_CRITICAL();
 479   2                   flags_cur = (OS_FLAGS)0;
 480   2                   *err      = OS_FLAG_ERR_WAIT_TYPE;
 481   2                   return (flags_cur);
 482   2          }
 483   1          OS_Sched();                                            /* Find next HPT ready to run               */
 484   1          OS_ENTER_CRITICAL();
 485   1          if (OSTCBCur->OSTCBStat & OS_STAT_FLAG) {              /* Have we timed-out?                       */
 486   2              OS_FlagUnlink(&node);
 487   2              OSTCBCur->OSTCBStat = OS_STAT_RDY;                 /* Yes, make task ready-to-run              */
C51 COMPILER V6.23a  OS_FLAG                                                               12/09/2004 16:50:25 PAGE 9   

 488   2              OS_EXIT_CRITICAL();
 489   2              flags_cur           = (OS_FLAGS)0;
 490   2              *err                = OS_TIMEOUT;                  /* Indicate that we timed-out waiting       */
 491   2          } else {
 492   2              if (consume == TRUE) {                             /* See if we need to consume the flags      */
 493   3                  switch (wait_type) {
 494   4                      case OS_FLAG_WAIT_SET_ALL:
 495   4                      case OS_FLAG_WAIT_SET_ANY:                 /* Clear ONLY the flags we got              */
 496   4                           pgrp->OSFlagFlags &= ~OSTCBCur->OSTCBFlagsRdy;
 497   4                           break;
 498   4      
 499   4      #if OS_FLAG_WAIT_CLR_EN > 0
 500   4                      case OS_FLAG_WAIT_CLR_ALL:
 501   4                      case OS_FLAG_WAIT_CLR_ANY:                 /* Set   ONLY the flags we got              */
 502   4                           pgrp->OSFlagFlags |= OSTCBCur->OSTCBFlagsRdy;
 503   4                           break;
 504   4      #endif
 505   4                  }
 506   3              }
 507   2              flags_cur = pgrp->OSFlagFlags;
 508   2              OS_EXIT_CRITICAL();
 509   2              *err      = OS_NO_ERR;                             /* Event(s) must have occurred              */
 510   2          }
 511   1          return (flags_cur);
 512   1      }
 513          /*$PAGE*/
 514          /*
 515          *********************************************************************************************************
 516          *                                         POST EVENT FLAG BIT(S)
 517          *
 518          * Description: This function is called to set or clear some bits in an event flag group.  The bits to
 519          *              set or clear are specified by a 'bit mask'.
 520          *
 521          * Arguments  : pgrp          is a pointer to the desired event flag group.
 522          *
 523          *              flags         If 'opt' (see below) is OS_FLAG_SET, each bit that is set in 'flags' will
 524          *                            set the corresponding bit in the event flag group.  e.g. to set bits 0, 4
 525          *                            and 5 you would set 'flags' to:
 526          *
 527          *                                0x31     (note, bit 0 is least significant bit)
 528          *
 529          *                            If 'opt' (see below) is OS_FLAG_CLR, each bit that is set in 'flags' will
 530          *                            CLEAR the corresponding bit in the event flag group.  e.g. to clear bits 0,
 531          *                            4 and 5 you would specify 'flags' as:
 532          *
 533          *                                0x31     (note, bit 0 is least significant bit)
 534          *
 535          *              opt           indicates whether the flags will be:
 536          *                                set     (OS_FLAG_SET) or
 537          *                                cleared (OS_FLAG_CLR)
 538          *
 539          *              err           is a pointer to an error code and can be:
 540          *                            OS_NO_ERR              The call was successfull
 541          *                            OS_FLAG_INVALID_PGRP   You passed a NULL pointer
 542          *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag group
 543          *                            OS_FLAG_INVALID_OPT    You specified an invalid option
 544          *
 545          * Returns    : the new value of the event flags bits that are still set.
 546          *
 547          * Called From: Task or ISR
 548          *
 549          * WARNING(s) : 1) The execution time of this function depends on the number of tasks waiting on the event
C51 COMPILER V6.23a  OS_FLAG                                                               12/09/2004 16:50:25 PAGE 10  

 550          *                 flag group.
 551          *              2) The amount of time interrupts are DISABLED depends on the number of tasks waiting on
 552          *                 the event flag group.
 553          *********************************************************************************************************
 554          */
 555          OS_FLAGS  OSFlagPost (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U opt, INT8U *err) KCREENTRANT
 556          {
 557   1      #if OS_CRITICAL_METHOD == 3                          /* Allocate storage for CPU status register       */
                  OS_CPU_SR     cpu_sr;
              #endif
 560   1          OS_FLAG_NODE *pnode;
 561   1          BOOLEAN       sched;
 562   1          OS_FLAGS      flags_cur;
 563   1          OS_FLAGS      flags_rdy;
 564   1      
 565   1      
 566   1      #if OS_ARG_CHK_EN > 0
 567   1          if (pgrp == (OS_FLAG_GRP *)0) {                  /* Validate 'pgrp'                                */
 568   2              *err = OS_FLAG_INVALID_PGRP;
 569   2              return ((OS_FLAGS)0);
 570   2          }
 571   1          if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {    /* Make sure we are pointing to an event flag grp */
 572   2              *err = OS_ERR_EVENT_TYPE;
 573   2              return ((OS_FLAGS)0);
 574   2          }
 575   1      #endif
 576   1      /*$PAGE*/
 577   1          OS_ENTER_CRITICAL();
 578   1          switch (opt) {
 579   2              case OS_FLAG_CLR:
 580   2                   pgrp->OSFlagFlags &= ~flags;            /* Clear the flags specified in the group         */
 581   2                   break;
 582   2      
 583   2              case OS_FLAG_SET:
 584   2                   pgrp->OSFlagFlags |=  flags;            /* Set   the flags specified in the group         */
 585   2                   break;
 586   2      
 587   2              default:
 588   2                   OS_EXIT_CRITICAL();                     /* INVALID option                                 */
 589   2                   *err = OS_FLAG_INVALID_OPT;
 590   2                   return ((OS_FLAGS)0);
 591   2          }
 592   1          sched = FALSE;                                   /* Indicate that we don't need rescheduling       */
 593   1          pnode = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;
 594   1          while (pnode != (OS_FLAG_NODE *)0) {             /* Go through all tasks waiting on event flag(s)  */
 595   2              switch (pnode->OSFlagNodeWaitType) {
 596   3                  case OS_FLAG_WAIT_SET_ALL:               /* See if all req. flags are set for current node */
 597   3                       flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
 598   3                       if (flags_rdy == pnode->OSFlagNodeFlags) {
 599   4                           if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd   */
 600   5                               sched = TRUE;                               /* When done we will reschedule   */
 601   5                           }
 602   4                       }
 603   3                       break;
 604   3      
 605   3                  case OS_FLAG_WAIT_SET_ANY:               /* See if any flag set                            */
 606   3                       flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
 607   3                       if (flags_rdy != (OS_FLAGS)0) {
 608   4                           if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd   */
 609   5                               sched = TRUE;                               /* When done we will reschedule   */
 610   5                           }
 611   4                       }
C51 COMPILER V6.23a  OS_FLAG                                                               12/09/2004 16:50:25 PAGE 11  

 612   3                       break;
 613   3      
 614   3      #if OS_FLAG_WAIT_CLR_EN > 0
 615   3                  case OS_FLAG_WAIT_CLR_ALL:               /* See if all req. flags are set for current node */
 616   3                       flags_rdy = ~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
 617   3                       if (flags_rdy == pnode->OSFlagNodeFlags) {
 618   4                           if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd   */
 619   5                               sched = TRUE;                               /* When done we will reschedule   */
 620   5                           }
 621   4                       }
 622   3                       break;
 623   3      
 624   3                  case OS_FLAG_WAIT_CLR_ANY:               /* See if any flag set                            */
 625   3                       flags_rdy = ~pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
 626   3                       if (flags_rdy != (OS_FLAGS)0) {
 627   4                           if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, event(s) Rx'd   */
 628   5                               sched = TRUE;                               /* When done we will reschedule   */
 629   5                           }
 630   4                       }
 631   3                       break;
 632   3      #endif
 633   3              }
 634   2              pnode = (OS_FLAG_NODE *)pnode->OSFlagNodeNext; /* Point to next task waiting for event flag(s) */
 635   2          }
 636   1          OS_EXIT_CRITICAL();
 637   1          if (sched == TRUE) {
 638   2              OS_Sched();
 639   2          }
 640   1          OS_ENTER_CRITICAL();
 641   1          flags_cur = pgrp->OSFlagFlags;
 642   1          OS_EXIT_CRITICAL();
 643   1          *err      = OS_NO_ERR;
 644   1          return (flags_cur);
 645   1      }
 646          /*$PAGE*/
 647          /*
 648          *********************************************************************************************************
 649          *                                           QUERY EVENT FLAG
 650          *
 651          * Description: This function is used to check the value of the event flag group.
 652          *
 653          * Arguments  : pgrp         is a pointer to the desired event flag group.
 654          *
 655          *              err           is a pointer to an error code returned to the called:
 656          *                            OS_NO_ERR              The call was successfull
 657          *                            OS_FLAG_INVALID_PGRP   You passed a NULL pointer
 658          *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag group
 659          *
 660          * Returns    : The current value of the event flag group.
 661          *
 662          * Called From: Task or ISR
 663          *********************************************************************************************************
 664          */
 665          
 666          #if OS_FLAG_QUERY_EN > 0
 667          OS_FLAGS  OSFlagQuery (OS_FLAG_GRP *pgrp, INT8U *err) KCREENTRANT
 668          {
 669   1      #if OS_CRITICAL_METHOD == 3                       /* Allocate storage for CPU status register          */
                  OS_CPU_SR  cpu_sr;
              #endif
 672   1          OS_FLAGS   flags;
 673   1      
C51 COMPILER V6.23a  OS_FLAG                                                               12/09/2004 16:50:25 PAGE 12  

 674   1      
 675   1      #if OS_ARG_CHK_EN > 0
 676   1          if (pgrp == (OS_FLAG_GRP *)0) {               /* Validate 'pgrp'                                   */
 677   2              *err = OS_FLAG_INVALID_PGRP;
 678   2              return ((OS_FLAGS)0);
 679   2          }
 680   1          if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Validate event block type                         */
 681   2              *err = OS_ERR_EVENT_TYPE;

⌨️ 快捷键说明

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