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

📄 os_mutex.lst

📁 ARM仿真案例
💻 LST
📖 第 1 页 / 共 5 页
字号:
    103          *                            other words, when the semaphore is acquired and a higher priority task
    104          *                            attempts to obtain the semaphore then the priority of the task owning the
    105          *                            semaphore is raised to this priority.  It is assumed that you will specify
    106          *                            a priority that is LOWER in value than ANY of the tasks competing for the
    107          *                            mutex.
    108          *
    109          *              err           is a pointer to an error code which will be returned to your application:
    110          *                               OS_NO_ERR           if the call was successful.
    111          *                               OS_ERR_CREATE_ISR   if you attempted to create a MUTEX from an ISR
    112          *                               OS_PRIO_EXIST       if a task at the priority inheritance priority
    113          *                                                   already exist.
    114          *                               OS_ERR_PEVENT_NULL  No more event control blocks available.
    115          *                               OS_PRIO_INVALID     if the priority you specify is higher that the 
    116          *                                                   maximum allowed (i.e. > OS_LOWEST_PRIO)
    117          *
    118          * Returns    : != (void *)0  is a pointer to the event control clock (OS_EVENT) associated with the
    119          *                            created mutex.
    120          *              == (void *)0  if an error is detected.
    121          *
    122          * Note(s)    : 1) The LEAST significant 8 bits of '.OSEventCnt' are used to hold the priority number
    123          *                 of the task owning the mutex or 0xFF if no task owns the mutex.
    124          *              2) The MOST  significant 8 bits of '.OSEventCnt' are used to hold the priority number
    125          *                 to use to reduce priority inversion.
    126          *********************************************************************************************************
    127          */
    128          

   \                                 In segment CODE, align 4, keep-with-next
    129          OS_EVENT  *OSMutexCreate (INT8U prio, INT8U *err)
    130          {
   \                     OSMutexCreate:
   \   00000000   70B5               PUSH     {R4-R6,LR}
   \   00000002   0400               MOVS     R4,R0
   \   00000004   0D00               MOVS     R5,R1
    131          #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    132              OS_CPU_SR  cpu_sr;
    133          #endif    
    134              OS_EVENT  *pevent;
    135          
    136          
    137              if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
   \   00000006   ....               LDR      R0,??DataTable10  ;; OSIntNesting
   \   00000008   0078               LDRB     R0,[R0, #+0]
   \   0000000A   0128               CMP      R0,#+1
   \   0000000C   03D3               BCC      ??OSMutexCreate_0
    138                  *err = OS_ERR_CREATE_ISR;                          /* ... can't CREATE mutex from an ISR       */
   \   0000000E   8D20               MOVS     R0,#+141
   \   00000010   2870               STRB     R0,[R5, #+0]
    139                  return ((OS_EVENT *)0);
   \   00000012   0020               MOVS     R0,#+0
   \   00000014   44E0               B        ??OSMutexCreate_1
    140              }
    141          #if OS_ARG_CHK_EN > 0
    142              if (prio >= OS_LOWEST_PRIO) {                          /* Validate PIP                             */
   \                     ??OSMutexCreate_0:
   \   00000016   3F2C               CMP      R4,#+63
   \   00000018   03D3               BCC      ??OSMutexCreate_2
    143                  *err = OS_PRIO_INVALID;
   \   0000001A   2A20               MOVS     R0,#+42
   \   0000001C   2870               STRB     R0,[R5, #+0]
    144                  return ((OS_EVENT *)0);
   \   0000001E   0020               MOVS     R0,#+0
   \   00000020   3EE0               B        ??OSMutexCreate_1
    145              }
    146          #endif
    147              OS_ENTER_CRITICAL();
   \                     ??OSMutexCreate_2:
   \   00000022   ........           _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
    148              if (OSTCBPrioTbl[prio] != (OS_TCB *)0) {               /* Mutex priority must not already exist    */
   \   00000026   2406               LSLS     R4,R4,#+24       ;; ZeroExtS R4,R4,#+24,#+24
   \   00000028   240E               LSRS     R4,R4,#+24
   \   0000002A   0421               MOVS     R1,#+4
   \   0000002C   6143               MULS     R1,R4,R1
   \   0000002E   ....               LDR      R2,??DataTable14  ;; OSTCBPrioTbl
   \   00000030   5158               LDR      R1,[R2, R1]
   \   00000032   0029               CMP      R1,#+0
   \   00000034   05D0               BEQ      ??OSMutexCreate_3
    149                  OS_EXIT_CRITICAL();                                /* Task already exist at priority ...       */
   \   00000036   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    150                  *err = OS_PRIO_EXIST;                              /* ... inheritance priority                 */
   \   0000003A   2820               MOVS     R0,#+40
   \   0000003C   2870               STRB     R0,[R5, #+0]
    151                  return ((OS_EVENT *)0);                            
   \   0000003E   0020               MOVS     R0,#+0
   \   00000040   2EE0               B        ??OSMutexCreate_1
    152              }
    153              OSTCBPrioTbl[prio] = (OS_TCB *)1;                      /* Reserve the table entry                  */
   \                     ??OSMutexCreate_3:
   \   00000042   2406               LSLS     R4,R4,#+24       ;; ZeroExtS R4,R4,#+24,#+24
   \   00000044   240E               LSRS     R4,R4,#+24
   \   00000046   0421               MOVS     R1,#+4
   \   00000048   6143               MULS     R1,R4,R1
   \   0000004A   ....               LDR      R2,??DataTable14  ;; OSTCBPrioTbl
   \   0000004C   0123               MOVS     R3,#+1
   \   0000004E   5350               STR      R3,[R2, R1]
    154              pevent             = OSEventFreeList;                  /* Get next free event control block        */
   \   00000050   ....               LDR      R1,??DataTable16  ;; OSEventFreeList
   \   00000052   0E68               LDR      R6,[R1, #+0]
    155              if (pevent == (OS_EVENT *)0) {                         /* See if an ECB was available              */
   \   00000054   002E               CMP      R6,#+0
   \   00000056   0AD1               BNE      ??OSMutexCreate_4
    156                  OSTCBPrioTbl[prio] = (OS_TCB *)0;                  /* No, Release the table entry              */
   \   00000058   0421               MOVS     R1,#+4
   \   0000005A   4C43               MULS     R4,R1,R4
   \   0000005C   ....               LDR      R1,??DataTable14  ;; OSTCBPrioTbl
   \   0000005E   0022               MOVS     R2,#+0
   \   00000060   0A51               STR      R2,[R1, R4]
    157                  OS_EXIT_CRITICAL();
   \   00000062   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    158                  *err               = OS_ERR_PEVENT_NULL;           /* No more event control blocks             */
   \   00000066   0420               MOVS     R0,#+4
   \   00000068   2870               STRB     R0,[R5, #+0]
    159                  return (pevent);
   \   0000006A   3000               MOVS     R0,R6
   \   0000006C   18E0               B        ??OSMutexCreate_1
    160              }
    161              OSEventFreeList        = (OS_EVENT *)OSEventFreeList->OSEventPtr;   /* Adjust the free list        */
   \                     ??OSMutexCreate_4:
   \   0000006E   ....               LDR      R1,??DataTable16  ;; OSEventFreeList
   \   00000070   ....               LDR      R2,??DataTable16  ;; OSEventFreeList
   \   00000072   1268               LDR      R2,[R2, #+0]
   \   00000074   5268               LDR      R2,[R2, #+4]
   \   00000076   0A60               STR      R2,[R1, #+0]
    162              OS_EXIT_CRITICAL();
   \   00000078   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    163              pevent->OSEventType    = OS_EVENT_TYPE_MUTEX;
   \   0000007C   0420               MOVS     R0,#+4
   \   0000007E   3070               STRB     R0,[R6, #+0]
    164              pevent->OSEventCnt     = ((INT16U)prio << 8) | OS_MUTEX_AVAILABLE;  /* Resource is available       */
   \   00000080   2002               LSLS     R0,R4,#+8
   \   00000082   FF21               MOVS     R1,#+255
   \   00000084   0143               ORRS     R1,R1,R0
   \   00000086   7180               STRH     R1,[R6, #+2]
    165              pevent->OSEventPtr     = (void *)0;                                 /* No task owning the mutex    */
   \   00000088   0020               MOVS     R0,#+0
   \   0000008A   7060               STR      R0,[R6, #+4]
    166          #if OS_EVENT_NAME_SIZE > 1
    167              pevent->OSEventName[0] = '?';
   \   0000008C   3F20               MOVS     R0,#+63
   \   0000008E   3074               STRB     R0,[R6, #+16]
    168              pevent->OSEventName[1] = OS_ASCII_NUL;
   \   00000090   0020               MOVS     R0,#+0
   \   00000092   7074               STRB     R0,[R6, #+17]
    169          #endif
    170              OS_EventWaitListInit(pevent);
   \   00000094   3000               MOVS     R0,R6
   \   00000096   ........           _BLF     OS_EventWaitListInit,??OS_EventWaitListInit??rT
    171              *err                   = OS_NO_ERR;
   \   0000009A   0020               MOVS     R0,#+0
   \   0000009C   2870               STRB     R0,[R5, #+0]
    172              return (pevent);
   \   0000009E   3000               MOVS     R0,R6
   \                     ??OSMutexCreate_1:
   \   000000A0   70BC               POP      {R4-R6}
   \   000000A2   02BC               POP      {R1}
   \   000000A4   0847               BX       R1               ;; return
    173          }
    174          
    175          /*$PAGE*/
    176          /*
    177          *********************************************************************************************************
    178          *                                          DELETE A MUTEX
    179          *
    180          * Description: This function deletes a mutual exclusion semaphore and readies all tasks pending on the it.
    181          *
    182          * Arguments  : pevent        is a pointer to the event control block associated with the desired mutex.
    183          *
    184          *              opt           determines delete options as follows:
    185          *                            opt == OS_DEL_NO_PEND   Delete mutex ONLY if no task pending
    186          *                            opt == OS_DEL_ALWAYS    Deletes the mutex even if tasks are waiting.
    187          *                                                    In this case, all the tasks pending will be readied.
    188          *
    189          *              err           is a pointer to an error code that can contain one of the following values:
    190          *                            OS_NO_ERR               The call was successful and the mutex was deleted
    191          *                            OS_ERR_DEL_ISR          If you attempted to delete the MUTEX from an ISR
    192          *                            OS_ERR_INVALID_OPT      An invalid option was specified
    193          *                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the mutex
    194          *                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a mutex
    195          *                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
    196          *
    197          * Returns    : pevent        upon error
    198          *              (OS_EVENT *)0 if the mutex was successfully deleted.
    199          *
    200          * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
    201          *                 the mutex MUST check the return code of OSMutexPend().
    202          *              2) This call can potentially disable interrupts for a long time.  The interrupt disable
    203          *                 time is directly proportional to the number of tasks waiting on the mutex.
    204          *              3) Because ALL tasks pending on the mutex will be readied, you MUST be careful because the
    205          *                 resource(s) will no longer be guarded by the mutex.
    206          *********************************************************************************************************
    207          */
    208          
    209          #if OS_MUTEX_DEL_EN

   \                                 In segment CODE, align 4, keep-with-next
    210          OS_EVENT  *OSMutexDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
    211          {
   \                     OSMutexDel:
   \   00000000   F2B5               PUSH     {R1,R4-R7,LR}
   \   00000002   0400               MOVS     R4,R0
   \   00000004   1500               MOVS     R5,R2
    212          #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */

⌨️ 快捷键说明

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