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

📄 os_flag.ls1

📁 UCOS在51上的移植,绝对经典!可以较少开发人员的工作量
💻 LS1
📖 第 1 页 / 共 5 页
字号:
                             set.
                     449     ; *
                     450     ; * Arguments  : pgrp          is a pointer to the desired event flag group.
                     451     ; *
                     452     ; *              flags         Is a bit pattern indicating which bit(s) (i.e. flags) you wi
                             sh to wait for.
                     453     ; *                            The bits you want are specified by setting the corresponding
                              bits in
                     454     ; *                            'flags'.  e.g. if your application wants to wait for bits 0 
                             and 1 then
                     455     ; *                            'flags' would contain 0x03.
                     456     ; *
                     457     ; *              wait_type     specifies whether you want ALL bits to be set or ANY of the 
                             bits to be set.
                     458     ; *                            You can specify the following argument:
                     459     ; *
                     460     ; *                            OS_FLAG_WAIT_CLR_ALL   You will wait for ALL bits in 'mask' 
                             to be clear (0)
                     461     ; *                            OS_FLAG_WAIT_SET_ALL   You will wait for ALL bits in 'mask' 
                             to be set   (1)
                     462     ; *                            OS_FLAG_WAIT_CLR_ANY   You will wait for ANY bit  in 'mask' 
                             to be clear (0)
                     463     ; *                            OS_FLAG_WAIT_SET_ANY   You will wait for ANY bit  in 'mask' 
                             to be set   (1)
                     464     ; *
                     465     ; *                            NOTE: Add OS_FLAG_CONSUME if you want the event flag to be '
                             consumed' by
                     466     ; *                                  the call.  Example, to wait for any flag in a group AN
                             D then clear
                     467     ; *                                  the flags that are present, set 'wait_type' to:
                     468     ; *
                     469     ; *                                  OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME
                     470     ; *
                     471     ; *              timeout       is an optional timeout (in clock ticks) that your task will 
                             wait for the
A51 MACRO ASSEMBLER  OS_FLAG                                                              05/17/2005 11:19:52 PAGE    10

                     472     ; *                            desired bit combination.  If you specify 0, however, your ta
                             sk will wait
                     473     ; *                            forever at the specified event flag group or, until a messag
                             e arrives.
                     474     ; *
                     475     ; *              err           is a pointer to an error code and can be:
                     476     ; *                            OS_NO_ERR              The desired bits have been set within
                              the specified
                     477     ; *                                                   'timeout'.
                     478     ; *                            OS_ERR_PEND_ISR        If you tried to PEND from an ISR
                     479     ; *                            OS_FLAG_INVALID_PGRP   If 'pgrp' is a NULL pointer.
                     480     ; *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag
                              group
                     481     ; *                            OS_TIMEOUT             The bit(s) have not been set in the s
                             pecified
                     482     ; *                                                   'timeout'.
                     483     ; *                            OS_FLAG_ERR_WAIT_TYPE  You didn't specify a proper 'wait_typ
                             e' argument.
                     484     ; *
                     485     ; * Returns    : The new state of the flags in the event flag group when the task is resume
                             d or,
                     486     ; *              0 if a timeout or an error occurred.
                     487     ; *
                     488     ; * Called from: Task ONLY
                     489     ; *****************************************************************************************
                             ****************
                     490     ; */
                     491     ; 
                     492     ; OS_FLAGS  OSFlagPend (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT16U timeout,
                              INT8U *err)LG_REENTRANT
                     493     ; {
                     494     ; #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU st
                             atus register */
                     495     ;     OS_CPU_SR     cpu_sr;
                     496     ; #endif
                     497     ;     OS_FLAG_NODE  node;
                     498     ;     OS_FLAGS      flags_cur;
                     499     ;     OS_FLAGS      flags_rdy;
                     500     ;     BOOLEAN       consume;
                     501     ; 
                     502     ; 
                     503     ;     if (OSIntNesting > 0) {                                /* See if called from ISR ... 
                                           */
                     504     ;         *err = OS_ERR_PEND_ISR;                            /* ... can't PEND from an ISR 
                                           */
                     505     ;         return ((OS_FLAGS)0);
                     506     ;     }
                     507     ; #if OS_ARG_CHK_EN > 0
                     508     ;     if (pgrp == (OS_FLAG_GRP *)0) {                        /* Validate 'pgrp'            
                                           */
                     509     ;         *err = OS_FLAG_INVALID_PGRP;
                     510     ;         return ((OS_FLAGS)0);
                     511     ;     }
                     512     ;     if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {          /* Validate event block type  
                                           */
                     513     ;         *err = OS_ERR_EVENT_TYPE;
                     514     ;         return ((OS_FLAGS)0);
                     515     ;     }
                     516     ; #endif
                     517     ;     if (wait_type & OS_FLAG_CONSUME) {                     /* See if we need to consume t
                             he flags      */
                     518     ;         wait_type &= ~OS_FLAG_CONSUME;
                     519     ;         consume    = TRUE;
                     520     ;     } else {
                     521     ;         consume    = FALSE;
                     522     ;     }
A51 MACRO ASSEMBLER  OS_FLAG                                                              05/17/2005 11:19:52 PAGE    11

                     523     ; /*$PAGE*/
                     524     ;     OS_ENTER_CRITICAL();
                     525     ;     switch (wait_type) {
                     526     ;         case OS_FLAG_WAIT_SET_ALL:                         /* See if all required flags a
                             re set        */
                     527     ;              flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we wa
                             nt            */
                     528     ;              if (flags_rdy == flags) {                     /* Must match ALL the bits tha
                             t we want     */
                     529     ;                  if (consume == TRUE) {                    /* See if we need to consume t
                             he flags      */
                     530     ;                      pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that w
                             e wanted      */
                     531     ;                  }
                     532     ;                  flags_cur = pgrp->OSFlagFlags;            /* Will return the state of th
                             e group       */
                     533     ;                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return 
                             to caller     */
                     534     ;                  *err      = OS_NO_ERR;
                     535     ;                  return (flags_cur);
                     536     ;              } else {                                      /* Block task until events occ
                             ur or timeout */
                     537     ;                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
                     538     ;                  OS_EXIT_CRITICAL();
                     539     ;              }
                     540     ;              break;
                     541     ; 
                     542     ;         case OS_FLAG_WAIT_SET_ANY:
                     543     ;              flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we wa
                             nt            */
                     544     ;              if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag set        
                                           */
                     545     ;                  if (consume == TRUE) {                    /* See if we need to consume t
                             he flags      */
                     546     ;                      pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that w
                             e got         */
                     547     ;                  }
                     548     ;                  flags_cur = pgrp->OSFlagFlags;            /* Will return the state of th
                             e group       */
                     549     ;                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return 
                             to caller     */
                     550     ;                  *err      = OS_NO_ERR;
                     551     ;                  return (flags_cur);
                     552     ;              } else {                                      /* Block task until events occ
                             ur or timeout */
                     553     ;                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
                     554     ;                  OS_EXIT_CRITICAL();
                     555     ;              }
                     556     ;              break;
                     557     ; 
                     558     ; #if OS_FLAG_WAIT_CLR_EN > 0
                     559     ;         case OS_FLAG_WAIT_CLR_ALL:                         /* See if all required flags a
                             re cleared    */
                     560     ;              flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we wa
                             nt            */
                     561     ;              if (flags_rdy == flags) {                     /* Must match ALL the bits tha
                             t we want     */
                     562     ;                  if (consume == TRUE) {                    /* See if we need to consume t
                             he flags      */
                     563     ;                      pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we 
                             wanted        */
                     564     ;                  }
                     565     ;                  flags_cur = pgrp->OSFlagFlags;            /* Will return the state of th
                             e group       */
                     566     ;                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return 
                             to caller     */
A51 MACRO ASSEMBLER  OS_FLAG                                                              05/17/2005 11:19:52 PAGE    12

                     567     ;                  *err      = OS_NO_ERR;
                     568     ;                  return (flags_cur);
                     569     ;              } else {                                      /* Block task until events occ
                             ur or timeout */
                     570     ;                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
                     571     ;                  OS_EXIT_CRITICAL();
                     572     ;              }
                     573     ;              break;
                     574     ; 
                     575     ;         case OS_FLAG_WAIT_CLR_ANY:
                     576     ;              flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we wa
                             nt            */
                     577     ;              if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag cleared    
                                           */
                     578     ;                  if (consume == TRUE) {                    /* See if we need to consume t
                             he flags      */
                     579     ;                      pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we 
                             got           */
                     580     ;                  }

⌨️ 快捷键说明

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