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

📄 os_sem.lst

📁 ARM仿真案例
💻 LST
📖 第 1 页 / 共 4 页
字号:
    225          #endif
    226          
    227          /*$PAGE*/
    228          /*
    229          *********************************************************************************************************
    230          *                                           PEND ON SEMAPHORE
    231          *
    232          * Description: This function waits for a semaphore.
    233          *
    234          * Arguments  : pevent        is a pointer to the event control block associated with the desired
    235          *                            semaphore.
    236          *
    237          *              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
    238          *                            wait for the resource up to the amount of time specified by this argument.
    239          *                            If you specify 0, however, your task will wait forever at the specified
    240          *                            semaphore or, until the resource becomes available (or the event occurs).
    241          *
    242          *              err           is a pointer to where an error message will be deposited.  Possible error
    243          *                            messages are:
    244          *
    245          *                            OS_NO_ERR           The call was successful and your task owns the resource
    246          *                                                or, the event you are waiting for occurred.
    247          *                            OS_TIMEOUT          The semaphore was not received within the specified
    248          *                                                timeout.
    249          *                            OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore.
    250          *                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
    251          *                                                would lead to a suspension.
    252          *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
    253          *
    254          * Returns    : none
    255          *********************************************************************************************************
    256          */
    257          

   \                                 In segment CODE, align 4, keep-with-next
    258          void  OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)
    259          {
   \                     OSSemPend:
   \   00000000   F0B5               PUSH     {R4-R7,LR}
   \   00000002   0400               MOVS     R4,R0
   \   00000004   0D00               MOVS     R5,R1
   \   00000006   1600               MOVS     R6,R2
    260          #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
    261              OS_CPU_SR  cpu_sr;
    262          #endif    
    263          
    264          
    265              if (OSIntNesting > 0) {                           /* See if called from ISR ...                    */
   \   00000008   ....               LDR      R0,??DataTable7  ;; OSIntNesting
   \   0000000A   0078               LDRB     R0,[R0, #+0]
   \   0000000C   0028               CMP      R0,#+0
   \   0000000E   01D0               BEQ      ??OSSemPend_0
    266                  *err = OS_ERR_PEND_ISR;                       /* ... can't PEND from an ISR                    */
   \   00000010   0220               MOVS     R0,#+2
   \   00000012   43E0               B.N      ??OSSemPend_1
    267                  return;
    268              }
    269          #if OS_ARG_CHK_EN > 0
    270              if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
   \                     ??OSSemPend_0:
   \   00000014   002C               CMP      R4,#+0
   \   00000016   01D1               BNE      ??OSSemPend_2
    271                  *err = OS_ERR_PEVENT_NULL;
   \   00000018   0420               MOVS     R0,#+4
   \   0000001A   3FE0               B.N      ??OSSemPend_1
    272                  return;
    273              }
    274          #endif
    275              if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
   \                     ??OSSemPend_2:
   \   0000001C   2078               LDRB     R0,[R4, #+0]
   \   0000001E   0328               CMP      R0,#+3
   \   00000020   01D0               BEQ      ??OSSemPend_3
    276                  *err = OS_ERR_EVENT_TYPE;
   \   00000022   0120               MOVS     R0,#+1
   \   00000024   3AE0               B.N      ??OSSemPend_1
    277                  return;
    278              }
    279              OS_ENTER_CRITICAL();
   \                     ??OSSemPend_3:
   \   00000026   ........           _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
   \   0000002A   0700               MOVS     R7,R0
    280              if (pevent->OSEventCnt > 0) {                     /* If sem. is positive, resource available ...   */
   \   0000002C   6088               LDRH     R0,[R4, #+2]
   \   0000002E   0028               CMP      R0,#+0
   \   00000030   06D0               BEQ      ??OSSemPend_4
    281                  pevent->OSEventCnt--;                         /* ... decrement semaphore only if positive.     */
   \   00000032   401E               SUBS     R0,R0,#+1
   \   00000034   6080               STRH     R0,[R4, #+2]
    282                  OS_EXIT_CRITICAL();
   \   00000036   3800               MOVS     R0,R7
   \   00000038   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    283                  *err = OS_NO_ERR;
   \   0000003C   0020               MOVS     R0,#+0
   \   0000003E   2DE0               B.N      ??OSSemPend_1
    284                  return;
    285              }
    286                                                                /* Otherwise, must wait until event occurs       */
    287              OSTCBCur->OSTCBStat |= OS_STAT_SEM;               /* Resource not available, pend on semaphore     */
   \                     ??OSSemPend_4:
   \   00000040   1848               LDR      R0,??OSSemPend_5  ;; OSTCBCur
   \   00000042   0068               LDR      R0,[R0, #+0]
   \   00000044   2C30               ADDS     R0,R0,#+44
   \   00000046   1749               LDR      R1,??OSSemPend_5  ;; OSTCBCur
   \   00000048   0968               LDR      R1,[R1, #+0]
   \   0000004A   2C31               ADDS     R1,R1,#+44
   \   0000004C   0978               LDRB     R1,[R1, #+0]
   \   0000004E   0122               MOVS     R2,#+1
   \   00000050   0A43               ORRS     R2,R2,R1
   \   00000052   0270               STRB     R2,[R0, #+0]
    288              OSTCBCur->OSTCBDly   = timeout;                   /* Store pend timeout in TCB                     */
   \   00000054   1348               LDR      R0,??OSSemPend_5  ;; OSTCBCur
   \   00000056   0068               LDR      R0,[R0, #+0]
   \   00000058   4585               STRH     R5,[R0, #+42]
    289              OS_EventTaskWait(pevent);                         /* Suspend task until event or timeout occurs    */
   \   0000005A   2000               MOVS     R0,R4
   \   0000005C   ........           _BLF     OS_EventTaskWait,??OS_EventTaskWait??rT
    290              OS_EXIT_CRITICAL();
   \   00000060   3800               MOVS     R0,R7
   \   00000062   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    291              OS_Sched();                                       /* Find next highest priority task ready         */
   \   00000066   ........           _BLF     OS_Sched,??OS_Sched??rT
    292              OS_ENTER_CRITICAL();
   \   0000006A   ........           _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
   \   0000006E   0700               MOVS     R7,R0
    293              if (OSTCBCur->OSTCBStat & OS_STAT_SEM) {          /* Must have timed out if still waiting for event*/
   \   00000070   0C48               LDR      R0,??OSSemPend_5  ;; OSTCBCur
   \   00000072   0068               LDR      R0,[R0, #+0]
   \   00000074   2C30               ADDS     R0,R0,#+44
   \   00000076   0078               LDRB     R0,[R0, #+0]
   \   00000078   C007               LSLS     R0,R0,#+31
   \   0000007A   07D5               BPL      ??OSSemPend_6
    294                  OS_EventTO(pevent);
   \   0000007C   2000               MOVS     R0,R4
   \   0000007E   ........           _BLF     OS_EventTO,??OS_EventTO??rT
    295                  OS_EXIT_CRITICAL();
   \   00000082   3800               MOVS     R0,R7
   \   00000084   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    296                  *err = OS_TIMEOUT;                            /* Indicate that didn't get event within TO      */
   \   00000088   0A20               MOVS     R0,#+10
   \   0000008A   07E0               B.N      ??OSSemPend_1
    297                  return;
    298              }
    299              OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
   \                     ??OSSemPend_6:
   \   0000008C   0548               LDR      R0,??OSSemPend_5  ;; OSTCBCur
   \   0000008E   0068               LDR      R0,[R0, #+0]
   \   00000090   0021               MOVS     R1,#+0
   \   00000092   C161               STR      R1,[R0, #+28]
    300              OS_EXIT_CRITICAL();
   \   00000094   3800               MOVS     R0,R7
   \   00000096   ........           _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
    301              *err = OS_NO_ERR;
   \   0000009A   0020               MOVS     R0,#+0
   \                     ??OSSemPend_1:
   \   0000009C   3070               STRB     R0,[R6, #+0]
    302          }
   \   0000009E   F0BC               POP      {R4-R7}
   \   000000A0   01BC               POP      {R0}
   \   000000A2   0047               BX       R0               ;; return
   \                     ??OSSemPend_5:
   \   000000A4   ........           DC32     OSTCBCur
    303          /*$PAGE*/
    304          /*
    305          *********************************************************************************************************
    306          *                                         POST TO A SEMAPHORE
    307          *
    308          * Description: This function signals a semaphore
    309          *
    310          * Arguments  : pevent        is a pointer to the event control block associated with the desired
    311          *                            semaphore.
    312          *
    313          * Returns    : OS_NO_ERR           The call was successful and the semaphore was signaled.
    314          *              OS_SEM_OVF          If the semaphore count exceeded its limit.  In other words, you have
    315          *                                  signalled the semaphore more often than you waited on it with either
    316          *                                  OSSemAccept() or OSSemPend().
    317          *              OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore
    318          *              OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
    319          *********************************************************************************************************
    320          */
    321          

   \                                 In segment CODE, align 4, keep-with-next
    322          INT8U  OSSemPost (OS_EVENT *pevent)
    323          {
   \                     OSSemPost:
   \   00000000   30B5               PUSH     {R4,R5,LR}
   \   00000002   0400               MOVS     R4,R0
    324          #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    325              OS_CPU_SR  cpu_sr;                               
    326          #endif    
    327          
    328          
    329          #if OS_ARG_CHK_EN > 0
    330              if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
   \   00000004   01D1               BNE      ??OSSemPost_0
    331                  return (OS_ERR_PEVENT_NULL);
   \   00000006   0420               MOVS     R0,#+4
   \   00000008   24E0               B        ??OSSemPost_1
    332              }
    333          #endif
    334              if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
   \                     ??OSSemPost_0:
   \   0000000A   2078               LDRB     R0,[R4, #+0]
   \   0000000C   0328               CMP      R0,#+3
   \   0000000E   01D0               BEQ      ??OSSemPost_2
    335                  return (OS_ERR_EVENT_TYPE);
   \   00000010   0120               MOVS     R0,#+1
   \   00000012   1FE0               B        ??OSSemPost_1
    336              }
    337              OS_ENTER_CRITICAL();
   \                     ??OSSemPost_2:
   \   00000014   ........           _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
   \   00000018   0500               MOVS     R5,R0
    338              if (pevent->OSEventGrp != 0x00) {                      /* See if any task waiting for semaphore    */
   \   0000001A   6078               LDRB     R0,[R4, #+1]
   \   0000001C   0028               CMP      R0,#+0

⌨️ 快捷键说明

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