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

📄 os_sem.lst

📁 ARM仿真案例
💻 LST
📖 第 1 页 / 共 4 页
字号:
    117          *
    118          * Description: This function deletes a semaphore and readies all tasks pending on the semaphore.
    119          *
    120          * Arguments  : pevent        is a pointer to the event control block associated with the desired
    121          *                            semaphore.
    122          *
    123          *              opt           determines delete options as follows:
    124          *                            opt == OS_DEL_NO_PEND   Delete semaphore ONLY if no task pending
    125          *                            opt == OS_DEL_ALWAYS    Deletes the semaphore even if tasks are waiting.
    126          *                                                    In this case, all the tasks pending will be readied.
    127          *
    128          *              err           is a pointer to an error code that can contain one of the following values:
    129          *                            OS_NO_ERR               The call was successful and the semaphore was deleted
    130          *                            OS_ERR_DEL_ISR          If you attempted to delete the semaphore from an ISR
    131          *                            OS_ERR_INVALID_OPT      An invalid option was specified
    132          *                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the semaphore
    133          *                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a semaphore
    134          *                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
    135          *
    136          * Returns    : pevent        upon error
    137          *              (OS_EVENT *)0 if the semaphore was successfully deleted.
    138          *
    139          * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
    140          *                 the semaphore MUST check the return code of OSSemPend().
    141          *              2) OSSemAccept() callers will not know that the intended semaphore has been deleted unless
    142          *                 they check 'pevent' to see that it's a NULL pointer.
    143          *              3) This call can potentially disable interrupts for a long time.  The interrupt disable
    144          *                 time is directly proportional to the number of tasks waiting on the semaphore.
    145          *              4) Because ALL tasks pending on the semaphore will be readied, you MUST be careful in
    146          *                 applications where the semaphore is used for mutual exclusion because the resource(s)
    147          *                 will no longer be guarded by the semaphore.
    148          *********************************************************************************************************
    149          */
    150          
    151          #if OS_SEM_DEL_EN > 0

   \                                 In segment CODE, align 4, keep-with-next
    152          OS_EVENT  *OSSemDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
    153          {
   \                     OSSemDel:
   \   00000000   F2B5               PUSH     {R1,R4-R7,LR}
   \   00000002   0400               MOVS     R4,R0
   \   00000004   1500               MOVS     R5,R2
    154          #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    155              OS_CPU_SR  cpu_sr;
    156          #endif    
    157              BOOLEAN    tasks_waiting;
    158          
    159          
    160              if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
   \   00000006   ....               LDR      R0,??DataTable7  ;; OSIntNesting
   \   00000008   0078               LDRB     R0,[R0, #+0]
   \   0000000A   0028               CMP      R0,#+0
   \   0000000C   01D0               BEQ      ??OSSemDel_0
    161                  *err = OS_ERR_DEL_ISR;                             /* ... can't DELETE from an ISR             */
   \   0000000E   8C20               MOVS     R0,#+140
   \   00000010   53E0               B.N      ??OSSemDel_1
    162                  return (pevent);
    163              }
    164          #if OS_ARG_CHK_EN > 0
    165              if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
   \                     ??OSSemDel_0:
   \   00000012   002C               CMP      R4,#+0
   \   00000014   03D1               BNE      ??OSSemDel_2
    166                  *err = OS_ERR_PEVENT_NULL;
   \   00000016   0420               MOVS     R0,#+4
   \   00000018   2870               STRB     R0,[R5, #+0]
    167                  return (pevent);
   \   0000001A   0020               MOVS     R0,#+0
   \   0000001C   4FE0               B        ??OSSemDel_3
    168              }
    169          #endif
    170              if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
   \                     ??OSSemDel_2:
   \   0000001E   2078               LDRB     R0,[R4, #+0]
   \   00000020   0328               CMP      R0,#+3
   \   00000022   01D0               BEQ      ??OSSemDel_4
    171                  *err = OS_ERR_EVENT_TYPE;
   \   00000024   0120               MOVS     R0,#+1
   \   00000026   48E0               B.N      ??OSSemDel_1
    172                  return (pevent);
    173              }
    174              OS_ENTER_CRITICAL();
   \                     ??OSSemDel_4:
   \   00000028   ........           _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
   \   0000002C   0600               MOVS     R6,R0
    175              if (pevent->OSEventGrp != 0x00) {                      /* See if any tasks waiting on semaphore    */
   \   0000002E   6078               LDRB     R0,[R4, #+1]
   \   00000030   0028               CMP      R0,#+0
   \   00000032   01D0               BEQ      ??OSSemDel_5
    176                  tasks_waiting = TRUE;                              /* Yes                                      */
   \   00000034   0127               MOVS     R7,#+1
   \   00000036   00E0               B        ??OSSemDel_6
    177              } else {
    178                  tasks_waiting = FALSE;                             /* No                                       */
   \                     ??OSSemDel_5:
   \   00000038   0027               MOVS     R7,#+0
    179              }
    180              switch (opt) {
   \                     ??OSSemDel_6:
   \   0000003A   6846               MOV      R0,SP
   \   0000003C   0078               LDRB     R0,[R0, #+0]
   \   0000003E   0028               CMP      R0,#+0
   \   00000040   02D0               BEQ      ??OSSemDel_7
   \   00000042   0128               CMP      R0,#+1
   \   00000044   1ED0               BEQ      ??OSSemDel_8
   \   00000046   34E0               B        ??OSSemDel_9
    181                  case OS_DEL_NO_PEND:                               /* Delete semaphore only if no task waiting */
    182                       if (tasks_waiting == FALSE) {
   \                     ??OSSemDel_7:
   \   00000048   002F               CMP      R7,#+0
   \   0000004A   11D1               BNE      ??OSSemDel_10
    183          #if OS_EVENT_NAME_SIZE > 1
    184                           pevent->OSEventName[0] = '?';             /* Unknown name                             */
   \   0000004C   3F20               MOVS     R0,#+63
   \   0000004E   2074               STRB     R0,[R4, #+16]
    185                           pevent->OSEventName[1] = OS_ASCII_NUL;
   \   00000050   0020               MOVS     R0,#+0
   \   00000052   6074               STRB     R0,[R4, #+17]
    186          #endif
    187                           pevent->OSEventType    = OS_EVENT_TYPE_UNUSED;
   \   00000054   2070               STRB     R0,[R4, #+0]
    188                           pevent->OSEventPtr     = OSEventFreeList; /* Return Event Control Block to free list  */
   \   00000056   ....               LDR      R0,??DataTable6  ;; OSEventFreeList
   \   00000058   0068               LDR      R0,[R0, #+0]
   \   0000005A   6060               STR      R0,[R4, #+4]
    189                           pevent->OSEventCnt     = 0;
   \   0000005C   0020               MOVS     R0,#+0
   \   0000005E   6080               STRH     R0,[R4, #+2]
    190                           OSEventFreeList        = pevent;          /* Get next free event control block        */
   \   00000060   ....               LDR      R0,??DataTable6  ;; OSEventFreeList
   \   00000062   0460               STR      R4,[R0, #+0]
    191                           OS_EXIT_CRITICAL();
   \   00000064   3000               MOVS     R0,R6
   \   00000066   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    192                           *err                   = OS_NO_ERR;
   \                     ??OSSemDel_11:
   \   0000006A   0020               MOVS     R0,#+0
   \   0000006C   2870               STRB     R0,[R5, #+0]
    193                           return ((OS_EVENT *)0);                   /* Semaphore has been deleted               */
   \   0000006E   26E0               B        ??OSSemDel_3
    194                       } else {
    195                           OS_EXIT_CRITICAL();
   \                     ??OSSemDel_10:
   \   00000070   3000               MOVS     R0,R6
   \   00000072   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    196                           *err                   = OS_ERR_TASK_WAITING;
   \   00000076   0820               MOVS     R0,#+8
   \   00000078   1FE0               B.N      ??OSSemDel_1
    197                           return (pevent);
    198                       }
    199          
    200                  case OS_DEL_ALWAYS:                                /* Always delete the semaphore              */
    201                       while (pevent->OSEventGrp != 0x00) {          /* Ready ALL tasks waiting for semaphore    */
    202                           OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);
   \                     ??OSSemDel_12:
   \   0000007A   0122               MOVS     R2,#+1
   \   0000007C   0021               MOVS     R1,#+0
   \   0000007E   2000               MOVS     R0,R4
   \   00000080   ........           _BLF     OS_EventTaskRdy,??OS_EventTaskRdy??rT
    203                       }
   \                     ??OSSemDel_8:
   \   00000084   6078               LDRB     R0,[R4, #+1]
   \   00000086   0028               CMP      R0,#+0
   \   00000088   F7D1               BNE      ??OSSemDel_12
    204          #if OS_EVENT_NAME_SIZE > 1
    205                       pevent->OSEventName[0] = '?';                 /* Unknown name                             */
   \   0000008A   3F20               MOVS     R0,#+63
   \   0000008C   2074               STRB     R0,[R4, #+16]
    206                       pevent->OSEventName[1] = OS_ASCII_NUL;
   \   0000008E   0020               MOVS     R0,#+0
   \   00000090   6074               STRB     R0,[R4, #+17]
    207          #endif
    208                       pevent->OSEventType    = OS_EVENT_TYPE_UNUSED;
   \   00000092   2070               STRB     R0,[R4, #+0]
    209                       pevent->OSEventPtr     = OSEventFreeList;     /* Return Event Control Block to free list  */
   \   00000094   ....               LDR      R0,??DataTable6  ;; OSEventFreeList
   \   00000096   0068               LDR      R0,[R0, #+0]
   \   00000098   6060               STR      R0,[R4, #+4]
    210                       pevent->OSEventCnt     = 0;
   \   0000009A   0020               MOVS     R0,#+0
   \   0000009C   6080               STRH     R0,[R4, #+2]
    211                       OSEventFreeList        = pevent;              /* Get next free event control block        */
   \   0000009E   ....               LDR      R0,??DataTable6  ;; OSEventFreeList
   \   000000A0   0460               STR      R4,[R0, #+0]
    212                       OS_EXIT_CRITICAL();
   \   000000A2   3000               MOVS     R0,R6
   \   000000A4   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    213                       if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) were waiting  */
   \   000000A8   012F               CMP      R7,#+1
   \   000000AA   DED1               BNE      ??OSSemDel_11
    214                           OS_Sched();                               /* Find highest priority task ready to run  */
   \   000000AC   ........           _BLF     OS_Sched,??OS_Sched??rT
    215                       }
    216                       *err = OS_NO_ERR;
   \                     ??OSSemDel_13:
   \   000000B0   DBE7               B.N      ??OSSemDel_11
    217                       return ((OS_EVENT *)0);                       /* Semaphore has been deleted               */
    218          
    219                  default:
    220                       OS_EXIT_CRITICAL();
   \                     ??OSSemDel_9:
   \   000000B2   3000               MOVS     R0,R6
   \   000000B4   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    221                       *err = OS_ERR_INVALID_OPT;
   \   000000B8   0720               MOVS     R0,#+7
   \                     ??OSSemDel_1:
   \   000000BA   2870               STRB     R0,[R5, #+0]
    222                       return (pevent);
   \   000000BC   2000               MOVS     R0,R4
   \                     ??OSSemDel_3:
   \   000000BE   01B0               ADD      SP,SP,#+4
   \   000000C0   F0BC               POP      {R4-R7}
   \   000000C2   02BC               POP      {R1}
   \   000000C4   0847               BX       R1               ;; return
    223              }
    224          }

⌨️ 快捷键说明

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