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

📄 os_sem.lst

📁 IAR project for MSP430 and uC/OS. All configured to start filling with tasks.
💻 LST
📖 第 1 页 / 共 5 页
字号:
    227          *
    228          *              err           is a pointer to where an error message will be deposited.  Possible error
    229          *                            messages are:
    230          *
    231          *                            OS_NO_ERR           The call was successful and your task owns the resource
    232          *                                                or, the event you are waiting for occurred.
    233          *                            OS_TIMEOUT          The semaphore was not received within the specified
    234          *                                                timeout.
    235          *                            OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore.
    236          *                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
    237          *                                                would lead to a suspension.
    238          *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
    239          *
    240          * Returns    : none
    241          *********************************************************************************************************
    242          */
    243          
    244          void  OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)
    245          {
   \   0124  0A12              PUSH    R10     
   \   0126  0B12              PUSH    R11     
   \   0128  0A4C              MOV     R12,R10 
   \   012A  1B410600          MOV     6(SP),R11       
    246          #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
    247              OS_CPU_SR  cpu_sr;
    248          #endif    
    249          
    250          
    251              if (OSIntNesting > 0) {                           /* See if called from ISR ...                    */
   \   012E  C2930000          CMP.B   #0,&OSIntNesting        
   \   0132  0324              JEQ     (?0092) 
    252                  *err = OS_ERR_PEND_ISR;                       /* ... can't PEND from an ISR                    */
   \   0134  EB430000          MOV.B   #2,0(R11)       
    253                  return;
    254              }
   \   0138  393C              JMP     (?0101) 
   \   013A            ?0092:
    255          #if OS_ARG_CHK_EN > 0
    256              if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
   \   013A  0A93              CMP     #0,R10  
   \   013C  0320              JNE     (?0094) 
    257                  *err = OS_ERR_PEVENT_NULL;
   \   013E  EB420000          MOV.B   #4,0(R11)       
    258                  return;
    259              }
   \   0142  343C              JMP     (?0101) 
   \   0144            ?0094:
    260              if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
   \   0144  7C400300          MOV.B   #3,R12  
   \   0148  6C9A              CMP.B   @R10,R12        
   \   014A  0324              JEQ     (?0096) 
    261                  *err = OS_ERR_EVENT_TYPE;
   \   014C  DB430000          MOV.B   #1,0(R11)       
    262                  return;
    263              }
   \   0150  2D3C              JMP     (?0101) 
   \   0152            ?0096:
    264          #endif
    265              OS_ENTER_CRITICAL();
   \   0152  32C2              DINT            
    266              if (pevent->OSEventCnt > 0) {                     /* If sem. is positive, resource available ...   */
   \   0154  8A930200          CMP     #0,2(R10)       
   \   0158  0624              JEQ     (?0098) 
    267                  pevent->OSEventCnt--;                         /* ... decrement semaphore only if positive.     */
   \   015A  BA530200          ADD     #-1,2(R10)      
    268                  OS_EXIT_CRITICAL();
   \   015E  32D2              EINT            
    269                  *err = OS_NO_ERR;
   \   0160  CB430000          MOV.B   #0,0(R11)       
    270                  return;
    271              }
   \   0164  233C              JMP     (?0101) 
   \   0166            ?0098:
    272                                                                /* Otherwise, must wait until event occurs       */
    273              OSTCBCur->OSTCBStat |= OS_STAT_SEM;               /* Resource not available, pend on semaphore     */
   \   0166  1C420000          MOV     &OSTCBCur,R12   
   \   016A  DCD31C00          BIS.B   #1,28(R12)      
    274              OSTCBCur->OSTCBDly   = timeout;                   /* Store pend timeout in TCB                     */
   \   016E  1C420000          MOV     &OSTCBCur,R12   
   \   0172  8C4E1A00          MOV     R14,26(R12)     
    275              OS_EventTaskWait(pevent);                         /* Suspend task until event or timeout occurs    */
   \   0176  0C4A              MOV     R10,R12 
   \   0178  B0120000          CALL    #OS_EventTaskWait       
    276              OS_EXIT_CRITICAL();
   \   017C  32D2              EINT            
    277              OS_Sched();                                       /* Find next highest priority task ready         */
   \   017E  B0120000          CALL    #OS_Sched       
    278              OS_ENTER_CRITICAL();
   \   0182  32C2              DINT            
    279              if (OSTCBCur->OSTCBStat & OS_STAT_SEM) {          /* Must have timed out if still waiting for event*/
   \   0184  1C420000          MOV     &OSTCBCur,R12   
   \   0188  DCB31C00          BIT.B   #1,28(R12)      
   \   018C  0824              JEQ     (?0100) 
    280                  OS_EventTO(pevent);
   \   018E  0C4A              MOV     R10,R12 
   \   0190  B0120000          CALL    #OS_EventTO     
    281                  OS_EXIT_CRITICAL();
   \   0194  32D2              EINT            
    282                  *err = OS_TIMEOUT;                            /* Indicate that didn't get event within TO      */
   \   0196  FB400A00          MOV.B   #10,0(R11)      
   \   019A  0000
    283                  return;
    284              }
   \   019C  073C              JMP     (?0101) 
   \   019E            ?0100:
    285              OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
   \   019E  1C420000          MOV     &OSTCBCur,R12   
   \   01A2  8C431200          MOV     #0,18(R12)      
    286              OS_EXIT_CRITICAL();
   \   01A6  32D2              EINT            
    287              *err = OS_NO_ERR;
   \   01A8  CB430000          MOV.B   #0,0(R11)       
    288          }
   \   01AC            ?0101:
   \   01AC  3B41              POP     R11     
   \   01AE  3A41              POP     R10     
   \   01B0  3041              RET             
   \   01B2            OSSemPost:
    289          /*$PAGE*/
    290          /*
    291          *********************************************************************************************************
    292          *                                         POST TO A SEMAPHORE
    293          *
    294          * Description: This function signals a semaphore
    295          *
    296          * Arguments  : pevent        is a pointer to the event control block associated with the desired
    297          *                            semaphore.
    298          *
    299          * Returns    : OS_NO_ERR           The call was successful and the semaphore was signaled.
    300          *              OS_SEM_OVF          If the semaphore count exceeded its limit.  In other words, you have
    301          *                                  signalled the semaphore more often than you waited on it with either
    302          *                                  OSSemAccept() or OSSemPend().
    303          *              OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore
    304          *              OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
    305          *********************************************************************************************************
    306          */
    307          
    308          INT8U  OSSemPost (OS_EVENT *pevent)
    309          {
    310          #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    311              OS_CPU_SR  cpu_sr;                               
    312          #endif    
    313          
    314          
    315          #if OS_ARG_CHK_EN > 0
    316              if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
   \   01B2  0C93              CMP     #0,R12  
   \   01B4  0220              JNE     (?0103) 
    317                  return (OS_ERR_PEVENT_NULL);
   \   01B6  6C42              MOV.B   #4,R12  
    318              }
   \   01B8  3041              RET             
   \   01BA            ?0103:
    319              if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
   \   01BA  7D400300          MOV.B   #3,R13  
   \   01BE  6D9C              CMP.B   @R12,R13        
   \   01C0  0224              JEQ     (?0105) 
    320                  return (OS_ERR_EVENT_TYPE);
   \   01C2  5C43              MOV.B   #1,R12  
    321              }
   \   01C4  3041              RET             
   \   01C6            ?0105:
    322          #endif
    323              OS_ENTER_CRITICAL();
   \   01C6  32C2              DINT            
    324              if (pevent->OSEventGrp != 0x00) {                      /* See if any task waiting for semaphore    */
   \   01C8  CC930100          CMP.B   #0,1(R12)       
   \   01CC  0A24              JEQ     (?0107) 
    325                  OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);   /* Ready highest prio task waiting on event */
   \   01CE  5312              PUSH.B  #1      
   \   01D0  0E43              MOV     #0,R14  
   \   01D2  B0120000          CALL    #OS_EventTaskRdy        
   \   01D6  2153              ADD     #2,SP   
    326                  OS_EXIT_CRITICAL();
   \   01D8  32D2              EINT            
    327                  OS_Sched();                                        /* Find highest priority task ready to run  */
   \   01DA  B0120000          CALL    #OS_Sched       
    328                  return (OS_NO_ERR);
   \   01DE  4C43              MOV.B   #0,R12  
    329              }
   \   01E0  3041              RET             
   \   01E2            ?0107:
    330              if (pevent->OSEventCnt < 65535) {                 /* Make sure semaphore will not overflow         */
   \   01E2  BC930200          CMP     #65535,2(R12)   
   \   01E6  052C              JC      (?0109) 
    331                  pevent->OSEventCnt++;                         /* Increment semaphore count to register event   */
   \   01E8  9C530200          ADD     #1,2(R12)       
    332                  OS_EXIT_CRITICAL();
   \   01EC  32D2              EINT            
    333                  return (OS_NO_ERR);
   \   01EE  4C43              MOV.B   #0,R12  
    334              }
   \   01F0  3041              RET             
   \   01F2            ?0109:
    335              OS_EXIT_CRITICAL();                               /* Semaphore value has reached its maximum       */
   \   01F2  32D2              EINT            
    336              return (OS_SEM_OVF);
   \   01F4  7C403200          MOV.B   #50,R12 
    337          }
   \   01F8  3041              RET             
   \   01FA            OSSemQuery:
    338          /*$PAGE*/
    339          /*
    340          *********************************************************************************************************
    341          *                                          QUERY A SEMAPHORE
    342          *
    343          * Description: This function obtains information about a semaphore
    344          *

⌨️ 快捷键说明

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