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

📄 os_flag.ls1

📁 UCOS在51上的移植,绝对经典!可以较少开发人员的工作量
💻 LS1
📖 第 1 页 / 共 5 页
字号:
                     581     ;                  flags_cur = pgrp->OSFlagFlags;            /* Will return the state of th
                             e group       */
                     582     ;                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return 
                             to caller     */
                     583     ;                  *err      = OS_NO_ERR;
                     584     ;                  return (flags_cur);
                     585     ;              } else {                                      /* Block task until events occ
                             ur or timeout */
                     586     ;                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
                     587     ;                  OS_EXIT_CRITICAL();
                     588     ;              }
                     589     ;              break;
                     590     ; #endif
                     591     ; 
                     592     ;         default:
                     593     ;              OS_EXIT_CRITICAL();
                     594     ;              flags_cur = (OS_FLAGS)0;
                     595     ;              *err      = OS_FLAG_ERR_WAIT_TYPE;
                     596     ;              return (flags_cur);
                     597     ;     }
                     598     ;     OS_Sched();                                            /* Find next HPT ready to run 
                                           */
                     599     ;     OS_ENTER_CRITICAL();
                     600     ;     if (OSTCBCur->OSTCBStat & OS_STAT_FLAG) {              /* Have we timed-out?         
                                           */
                     601     ;         OS_FlagUnlink(&node);
                     602     ;         OSTCBCur->OSTCBStat = OS_STAT_RDY;                 /* Yes, make task ready-to-run
                                           */
                     603     ;         OS_EXIT_CRITICAL();
                     604     ;         flags_cur           = (OS_FLAGS)0;
                     605     ;         *err                = OS_TIMEOUT;                  /* Indicate that we timed-out 
                             waiting       */
                     606     ;     } else {
                     607     ;         if (consume == TRUE) {                             /* See if we need to consume t
                             he flags      */
                     608     ;             switch (wait_type) {
                     609     ;                 case OS_FLAG_WAIT_SET_ALL:
                     610     ;                 case OS_FLAG_WAIT_SET_ANY:                 /* Clear ONLY the flags we got
                                           */
                     611     ;                      pgrp->OSFlagFlags &= ~OSTCBCur->OSTCBFlagsRdy;
                     612     ;                      break;
                     613     ; 
                     614     ; #if OS_FLAG_WAIT_CLR_EN > 0
                     615     ;                 case OS_FLAG_WAIT_CLR_ALL:
                     616     ;                 case OS_FLAG_WAIT_CLR_ANY:                 /* Set   ONLY the flags we got
                                           */
                     617     ;                      pgrp->OSFlagFlags |= OSTCBCur->OSTCBFlagsRdy;
A51 MACRO ASSEMBLER  OS_FLAG                                                              05/17/2005 11:19:52 PAGE    13

                     618     ;                      break;
                     619     ; #endif
                     620     ;             }
                     621     ;         }
                     622     ;         flags_cur = pgrp->OSFlagFlags;
                     623     ;         OS_EXIT_CRITICAL();
                     624     ;         *err      = OS_NO_ERR;                             /* Event(s) must have occurred
                                           */
                     625     ;     }
                     626     ;     return (flags_cur);
                     627     ; }
                     628     ; /*$PAGE*/
                     629     ; /*
                     630     ; *****************************************************************************************
                             ****************
                     631     ; *                                         POST EVENT FLAG BIT(S)
                     632     ; *
                     633     ; * Description: This function is called to set or clear some bits in an event flag group. 
                              The bits to
                     634     ; *              set or clear are specified by a 'bit mask'.
                     635     ; *
                     636     ; * Arguments  : pgrp          is a pointer to the desired event flag group.
                     637     ; *
                     638     ; *              flags         If 'opt' (see below) is OS_FLAG_SET, each bit that is set in
                              'flags' will
                     639     ; *                            set the corresponding bit in the event flag group.  e.g. to 
                             set bits 0, 4
                     640     ; *                            and 5 you would set 'flags' to:
                     641     ; *
                     642     ; *                                0x31     (note, bit 0 is least significant bit)
                     643     ; *
                     644     ; *                            If 'opt' (see below) is OS_FLAG_CLR, each bit that is set in
                              'flags' will
                     645     ; *                            CLEAR the corresponding bit in the event flag group.  e.g. t
                             o clear bits 0,
                     646     ; *                            4 and 5 you would specify 'flags' as:
                     647     ; *
                     648     ; *                                0x31     (note, bit 0 is least significant bit)
                     649     ; *
                     650     ; *              opt           indicates whether the flags will be:
                     651     ; *                                set     (OS_FLAG_SET) or
                     652     ; *                                cleared (OS_FLAG_CLR)
                     653     ; *
                     654     ; *              err           is a pointer to an error code and can be:
                     655     ; *                            OS_NO_ERR              The call was successfull
                     656     ; *                            OS_FLAG_INVALID_PGRP   You passed a NULL pointer
                     657     ; *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag
                              group
                     658     ; *                            OS_FLAG_INVALID_OPT    You specified an invalid option
                     659     ; *
                     660     ; * Returns    : the new value of the event flags bits that are still set.
                     661     ; *
                     662     ; * Called From: Task or ISR
                     663     ; *
                     664     ; * WARNING(s) : 1) The execution time of this function depends on the number of tasks wait
                             ing on the event
                     665     ; *                 flag group.
                     666     ; *              2) The amount of time interrupts are DISABLED depends on the number of tas
                             ks waiting on
                     667     ; *                 the event flag group.
                     668     ; *****************************************************************************************
                             ****************
                     669     ; */
                     670     ; OS_FLAGS  OSFlagPost (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U opt, INT8U *err)LG_REENTRA
                             NT
                     671     ; {
A51 MACRO ASSEMBLER  OS_FLAG                                                              05/17/2005 11:19:52 PAGE    14

                     672     ; #if OS_CRITICAL_METHOD == 3                          /* Allocate storage for CPU status r
                             egister       */
                     673     ;     OS_CPU_SR     cpu_sr;
                     674     ; #endif
                     675     ;     OS_FLAG_NODE *pnode;
                     676     ;     BOOLEAN       sched;
                     677     ;     OS_FLAGS      flags_cur;
                     678     ;     OS_FLAGS      flags_rdy;
                     679     ; 
                     680     ; 
                     681     ; #if OS_ARG_CHK_EN > 0
                     682     ;     if (pgrp == (OS_FLAG_GRP *)0) {                  /* Validate 'pgrp'                  
                                           */
                     683     ;         *err = OS_FLAG_INVALID_PGRP;
                     684     ;         return ((OS_FLAGS)0);
                     685     ;     }
                     686     ;     if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {    /* Make sure we are pointing to an e
                             vent flag grp */
                     687     ;         *err = OS_ERR_EVENT_TYPE;
                     688     ;         return ((OS_FLAGS)0);
                     689     ;     }
                     690     ; #endif
                     691     ; /*$PAGE*/
                     692     ;     OS_ENTER_CRITICAL();
                     693     ;     switch (opt) {
                     694     ;         case OS_FLAG_CLR:
                     695     ;              pgrp->OSFlagFlags &= ~flags;            /* Clear the flags specified in the 
                             group         */
                     696     ;              break;
                     697     ; 
                     698     ;         case OS_FLAG_SET:
                     699     ;              pgrp->OSFlagFlags |=  flags;            /* Set   the flags specified in the 
                             group         */
                     700     ;              break;
                     701     ; 
                     702     ;         default:
                     703     ;              OS_EXIT_CRITICAL();                     /* INVALID option                   
                                           */
                     704     ;              *err = OS_FLAG_INVALID_OPT;
                     705     ;              return ((OS_FLAGS)0);
                     706     ;     }
                     707     ;     sched = FALSE;                                   /* Indicate that we don't need resch
                             eduling       */
                     708     ;     pnode = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;
                     709     ;     while (pnode != (OS_FLAG_NODE *)0) {             /* Go through all tasks waiting on e
                             vent flag(s)  */
                     710     ;         switch (pnode->OSFlagNodeWaitType) {
                     711     ;             case OS_FLAG_WAIT_SET_ALL:               /* See if all req. flags are set for
                              current node */
                     712     ;                  flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
                     713     ;                  if (flags_rdy == pnode->OSFlagNodeFlags) {
                     714     ;                      if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, ev
                             ent(s) Rx'd   */
                     715     ;                          sched = TRUE;                               /* When done we will
                              reschedule   */
                     716     ;                      }
                     717     ;                  }
                     718     ;                  break;
                     719     ; 
                     720     ;             case OS_FLAG_WAIT_SET_ANY:               /* See if any flag set              
                                           */
                     721     ;                  flags_rdy = pgrp->OSFlagFlags & pnode->OSFlagNodeFlags;
                     722     ;                  if (flags_rdy != (OS_FLAGS)0) {
                     723     ;                      if (OS_FlagTaskRdy(pnode, flags_rdy) == TRUE) { /* Make task RTR, ev
                             ent(s) Rx'd   */
                     724     ;                          sched = TRUE;                               /* When done we will
A51 MACRO ASSEMBLER  OS_FLAG                                                              05/17/2005 11:19:52 PAGE    15

                              reschedule   */
                     725     ;                      }
                     726     ;                  }
                     727     ;                  break;
                     728     ; 
                     729     ; #if OS_FLAG_WA

⌨️ 快捷键说明

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