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

📄 os_flag.s79

📁 ARM仿真案例
💻 S79
📖 第 1 页 / 共 5 页
字号:
//  455     OS_EXIT_CRITICAL();
        MOVS     R0,R7
        _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
//  456     *err = OS_NO_ERR;
        MOVS     R0,#+0
        STRB     R0,[R4, #+0]
//  457     return;
??OSFlagNameSet_1:
        POP      {R4-R7}
        POP      {R0}
        BX       R0               ;; return
        CFI EndBlock cfiBlock9
//  458 }

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock10 Using cfiCommon0
        CFI NoFunction
        ARM
??OSFlagPend??rA:
        ADD      R12,PC,#+1
        BX       R12
        CFI EndBlock cfiBlock10
        REQUIRE OSFlagPend
//  459 #endif
//  460 
//  461 /*$PAGE*/
//  462 /*
//  463 *********************************************************************************************************
//  464 *                                        WAIT ON AN EVENT FLAG GROUP
//  465 *
//  466 * Description: This function is called to wait for a combination of bits to be set in an event flag
//  467 *              group.  Your application can wait for ANY bit to be set or ALL bits to be set.
//  468 *
//  469 * Arguments  : pgrp          is a pointer to the desired event flag group.
//  470 *
//  471 *              flags         Is a bit pattern indicating which bit(s) (i.e. flags) you wish to wait for.
//  472 *                            The bits you want are specified by setting the corresponding bits in
//  473 *                            'flags'.  e.g. if your application wants to wait for bits 0 and 1 then
//  474 *                            'flags' would contain 0x03.
//  475 *
//  476 *              wait_type     specifies whether you want ALL bits to be set or ANY of the bits to be set.
//  477 *                            You can specify the following argument:
//  478 *
//  479 *                            OS_FLAG_WAIT_CLR_ALL   You will wait for ALL bits in 'mask' to be clear (0)
//  480 *                            OS_FLAG_WAIT_SET_ALL   You will wait for ALL bits in 'mask' to be set   (1)
//  481 *                            OS_FLAG_WAIT_CLR_ANY   You will wait for ANY bit  in 'mask' to be clear (0)
//  482 *                            OS_FLAG_WAIT_SET_ANY   You will wait for ANY bit  in 'mask' to be set   (1)
//  483 *
//  484 *                            NOTE: Add OS_FLAG_CONSUME if you want the event flag to be 'consumed' by
//  485 *                                  the call.  Example, to wait for any flag in a group AND then clear
//  486 *                                  the flags that are present, set 'wait_type' to:
//  487 *
//  488 *                                  OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME
//  489 *
//  490 *              timeout       is an optional timeout (in clock ticks) that your task will wait for the
//  491 *                            desired bit combination.  If you specify 0, however, your task will wait
//  492 *                            forever at the specified event flag group or, until a message arrives.
//  493 *
//  494 *              err           is a pointer to an error code and can be:
//  495 *                            OS_NO_ERR              The desired bits have been set within the specified
//  496 *                                                   'timeout'.
//  497 *                            OS_ERR_PEND_ISR        If you tried to PEND from an ISR
//  498 *                            OS_FLAG_INVALID_PGRP   If 'pgrp' is a NULL pointer.
//  499 *                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag group
//  500 *                            OS_TIMEOUT             The bit(s) have not been set in the specified
//  501 *                                                   'timeout'.
//  502 *                            OS_FLAG_ERR_WAIT_TYPE  You didn't specify a proper 'wait_type' argument.
//  503 *
//  504 * Returns    : The flags in the event flag group that made the task ready or, 0 if a timeout or an error 
//  505 *              occurred.
//  506 *
//  507 * Called from: Task ONLY
//  508 *
//  509 * Note(s)    : 1) IMPORTANT, the behavior of this function has changed from PREVIOUS versions.  The
//  510 *                 function NOW returns the flags that were ready INSTEAD of the current state of the 
//  511 *                 event flags.
//  512 *********************************************************************************************************
//  513 */
//  514 

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock11 Using cfiCommon1
        CFI Function OSFlagPend
        THUMB
//  515 OS_FLAGS  OSFlagPend (OS_FLAG_GRP *pgrp, OS_FLAGS flags, INT8U wait_type, INT16U timeout, INT8U *err)
//  516 {
OSFlagPend:
        PUSH     {R0-R7,LR}
        CFI ?RET Frame(CFA, -4)
        CFI R7 Frame(CFA, -8)
        CFI R6 Frame(CFA, -12)
        CFI R5 Frame(CFA, -16)
        CFI R4 Frame(CFA, -20)
        CFI CFA R13+36
        SUB      SP,SP,#+20
        CFI CFA R13+56
        LDR      R4,[SP, #+56]
//  517 #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
//  518     OS_CPU_SR     cpu_sr;
//  519 #endif
//  520     OS_FLAG_NODE  node;
//  521     OS_FLAGS      flags_rdy;
//  522     BOOLEAN       consume;
//  523 
//  524 
//  525     if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
        LDR      R0,??DataTable9  ;; OSIntNesting
        LDRB     R0,[R0, #+0]
        CMP      R0,#+1
        BCC      ??OSFlagPend_0
//  526         *err = OS_ERR_PEND_ISR;                            /* ... can't PEND from an ISR               */
        MOVS     R0,#+2
        STRB     R0,[R4, #+0]
//  527         return ((OS_FLAGS)0);
        MOVS     R0,#+0
        B        ??OSFlagPend_1
//  528     }
//  529 #if OS_ARG_CHK_EN > 0
//  530     if (pgrp == (OS_FLAG_GRP *)0) {                        /* Validate 'pgrp'                          */
??OSFlagPend_0:
        LDR      R0,[SP, #+20]
        CMP      R0,#+0
        BNE      ??OSFlagPend_2
//  531         *err = OS_FLAG_INVALID_PGRP;
        MOVS     R0,#+150
        STRB     R0,[R4, #+0]
//  532         return ((OS_FLAGS)0);
        MOVS     R0,#+0
        B        ??OSFlagPend_1
//  533     }
//  534 #endif
//  535     if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) {          /* Validate event block type                */
??OSFlagPend_2:
        LDR      R0,[SP, #+20]
        LDRB     R0,[R0, #+0]
        CMP      R0,#+5
        BEQ      ??OSFlagPend_3
//  536         *err = OS_ERR_EVENT_TYPE;
        MOVS     R0,#+1
        STRB     R0,[R4, #+0]
//  537         return ((OS_FLAGS)0);
        MOVS     R0,#+0
        B        ??OSFlagPend_1
//  538     }
//  539     if (wait_type & OS_FLAG_CONSUME) {                     /* See if we need to consume the flags      */
??OSFlagPend_3:
        MOV      R0,SP
        LDRB     R0,[R0, #+28]
        LSLS     R0,R0,#+24
        BPL      ??OSFlagPend_4
//  540         wait_type &= ~OS_FLAG_CONSUME;
        MOV      R0,SP
        MOV      R1,SP
        LDRB     R1,[R1, #+28]
        LSLS     R1,R1,#+25       ;; ZeroExtS R1,R1,#+25,#+25
        LSRS     R1,R1,#+25
        STRB     R1,[R0, #+28]
//  541         consume    = TRUE;
        MOVS     R7,#+1
        B        ??OSFlagPend_5
//  542     } else {
//  543         consume    = FALSE;
??OSFlagPend_4:
        MOVS     R7,#+0
//  544     }
//  545 /*$PAGE*/
//  546     OS_ENTER_CRITICAL();
??OSFlagPend_5:
        _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
        MOVS     R5,R0
//  547     switch (wait_type) {
        MOV      R0,SP
        LDRB     R0,[R0, #+28]
        CMP      R0,#+0
        BEQ      ??OSFlagPend_6
        CMP      R0,#+1
        BNE      .+5
        B        ??OSFlagPend_7
        CMP      R0,#+2
        BEQ      ??OSFlagPend_8
        CMP      R0,#+3
        BEQ      ??OSFlagPend_9
        B        ??OSFlagPend_10
//  548         case OS_FLAG_WAIT_SET_ALL:                         /* See if all required flags are set        */
//  549              flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
??OSFlagPend_8:
        LDR      R0,[SP, #+20]
        LDRH     R0,[R0, #+8]
        MOV      R1,SP
        LDRH     R6,[R1, #+24]
        ANDS     R6,R6,R0
//  550              if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
        MOV      R0,SP
        LDRH     R0,[R0, #+24]
        LSLS     R6,R6,#+16       ;; ZeroExtS R6,R6,#+16,#+16
        LSRS     R6,R6,#+16
        CMP      R6,R0
        BNE      ??OSFlagPend_11
//  551                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
        CMP      R7,#+1
        BNE      ??OSFlagPend_12
//  552                      pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we wanted      */
        LDR      R0,[SP, #+20]
        LDR      R1,[SP, #+20]
        LDRH     R1,[R1, #+8]
        BICS     R1,R1,R6
        STRH     R1,[R0, #+8]
//  553                  }
//  554                  OSTCBCur->OSTCBFlagsRdy = flags_rdy;          /* Save flags that were ready           */
??OSFlagPend_12:
        LDR      R0,??DataTable20  ;; OSTCBCur
        LDR      R0,[R0, #+0]
        STRH     R6,[R0, #+40]
//  555                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
        MOVS     R0,R5
        _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
//  556                  *err                    = OS_NO_ERR;
        MOVS     R0,#+0
        STRB     R0,[R4, #+0]
//  557                  return (flags_rdy);
        MOVS     R0,R6
        LSLS     R0,R0,#+16       ;; ZeroExtS R0,R0,#+16,#+16
        LSRS     R0,R0,#+16
        B        ??OSFlagPend_1
//  558              } else {                                      /* Block task until events occur or timeout */
//  559                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
??OSFlagPend_11:
        MOV      R0,SP
        LDRH     R0,[R0, #+32]
        PUSH     {R0}
        CFI CFA R13+60
        ADD      R0,SP,#+4
        LDRB     R3,[R0, #+28]
        ADD      R0,SP,#+4
        LDRH     R2,[R0, #+24]
        ADD      R1,SP,#+4
        LDR      R0,[SP, #+24]
        BL       OS_FlagBlock
        ADD      SP,SP,#+4
        CFI CFA R13+56
//  560                  OS_EXIT_CRITICAL();
        MOVS     R0,R5
        _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
//  561              }
//  562              break;
//  563 
//  564         case OS_FLAG_WAIT_SET_ANY:
//  565              flags_rdy = pgrp->OSFlagFlags & flags;        /* Extract only the bits we want            */
//  566              if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag set                      */
//  567                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
//  568                      pgrp->OSFlagFlags &= ~flags_rdy;      /* Clear ONLY the flags that we got         */
//  569                  }
//  570                  OSTCBCur->OSTCBFlagsRdy = flags_rdy;          /* Save flags that were ready           */
//  571                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
//  572                  *err                    = OS_NO_ERR;
//  573                  return (flags_rdy);
//  574              } else {                                      /* Block task until events occur or timeout */
//  575                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
//  576                  OS_EXIT_CRITICAL();
//  577              }
//  578              break;
//  579 
//  580 #if OS_FLAG_WAIT_CLR_EN > 0
//  581         case OS_FLAG_WAIT_CLR_ALL:                         /* See if all required flags are cleared    */
//  582              flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we want            */
//  583              if (flags_rdy == flags) {                     /* Must match ALL the bits that we want     */
//  584                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
//  585                      pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we wanted        */
//  586                  }
//  587                  OSTCBCur->OSTCBFlagsRdy = flags_rdy;          /* Save flags that were ready           */
//  588                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
//  589                  *err                    = OS_NO_ERR;
//  590                  return (flags_rdy);
//  591              } else {                                      /* Block task until events occur or timeout */
//  592                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
//  593                  OS_EXIT_CRITICAL();
//  594              }
//  595              break;
//  596 
//  597         case OS_FLAG_WAIT_CLR_ANY:
//  598              flags_rdy = ~pgrp->OSFlagFlags & flags;       /* Extract only the bits we want            */
//  599              if (flags_rdy != (OS_FLAGS)0) {               /* See if any flag cleared                  */
//  600                  if (consume == TRUE) {                    /* See if we need to consume the flags      */
//  601                      pgrp->OSFlagFlags |= flags_rdy;       /* Set ONLY the flags that we got           */
//  602                  }
//  603                  OSTCBCur->OSTCBFlagsRdy = flags_rdy;          /* Save flags that were ready           */
//  604                  OS_EXIT_CRITICAL();                       /* Yes, condition met, return to caller     */
//  605                  *err                    = OS_NO_ERR;
//  606                  return (flags_rdy);
//  607              } else {                                      /* Block task until events occur or timeout */
//  608                  OS_FlagBlock(pgrp, &node, flags, wait_type, timeout);
//  609                  OS_EXIT_CRITICAL();
//  610              }
//  611              break;
//  612 #endif
//  613 
//  614         default:
//  615              OS_EXIT_CRITICAL();
//  616              flags_rdy = (OS_FLAGS)0;
//  617              *err      = OS_FLAG_ERR_WAIT_TYPE;
//  618              return (flags_rdy);
//  619     }
//  620     OS_Sched();                                            /* Fi

⌨️ 快捷键说明

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