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

📄 os_sem.lst

📁 文件为uc/os电子书籍
💻 LST
📖 第 1 页 / 共 2 页
字号:
              *********************************************************************************************************
              */
              
              void OSSemPend (OS_EVENT DT_XDATA *pevent, INT16U timeout, INT8U DT_XDATA *err) REENTRANT
              {
                  OS_ENTER_CRITICAL();
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
                      OS_EXIT_CRITICAL();
                      *err = OS_ERR_EVENT_TYPE;
                  }
                  if (pevent->OSEventCnt > 0) {                     /* If sem. is positive, resource available ...   */
                      pevent->OSEventCnt--;                         /* ... decrement semaphore only if positive.     */
                      OS_EXIT_CRITICAL();
                      *err = OS_NO_ERR;
                  } else if (OSIntNesting > 0) {                    /* See if called from ISR ...                    */
                      OS_EXIT_CRITICAL();                           /* ... can't PEND from an ISR                    */
                      *err = OS_ERR_PEND_ISR;
                  } else {                                          /* Otherwise, must wait until event occurs       */
                      OSTCBCur->OSTCBStat    |= OS_STAT_SEM;        /* Resource not available, pend on semaphore     */
                      OSTCBCur->OSTCBDly      = timeout;            /* Store pend timeout in TCB                     */
                      OSEventTaskWait(pevent);                      /* Suspend task until event or timeout occurs    */
                      OS_EXIT_CRITICAL();
                      OSSched();                                    /* Find next highest priority task ready         */
                      OS_ENTER_CRITICAL();
                      if (OSTCBCur->OSTCBStat & OS_STAT_SEM) {      /* Must have timed out if still waiting for event*/
                          OSEventTO(pevent);
                          OS_EXIT_CRITICAL();
                          *err = OS_TIMEOUT;                        /* Indicate that didn't get event within TO      */
                      } else {
                          OSTCBCur->OSTCBEventPtr = (OS_EVENT DT_XDATA *)0;
                          OS_EXIT_CRITICAL();
                          *err = OS_NO_ERR;
                      }
                  }
              }
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                         POST TO A SEMAPHORE
              *
              * Description: This function signals a semaphore
              *
              * Arguments  : pevent        is a pointer to the event control block associated with the desired 
              *                            semaphore.
              *
              * Returns    : OS_NO_ERR          The call was successful and the semaphore was signaled.
              *              OS_SEM_OVF         If the semaphore count exceeded its limit.  In other words, you have 
              *                                 signalled the semaphore more often than you waited on it with either
              *                                 OSSemAccept() or OSSemPend().
              *              OS_ERR_EVENT_TYPE  If you didn't pass a pointer to a semaphore
              *********************************************************************************************************
              */
              
              INT8U OSSemPost (OS_EVENT DT_XDATA *pevent) REENTRANT
              {
                  OS_ENTER_CRITICAL();
C51 COMPILER V7.50   OS_SEM                                                                09/01/2008 22:58:57 PAGE 4   

                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_EVENT_TYPE);
                  }
                  if (pevent->OSEventGrp) {                              /* See if any task waiting for semaphore    */
                      OSEventTaskRdy(pevent, (void DT_XDATA *)0, OS_STAT_SEM);    /* Ready highest prio task waiting on 
             -event */
                      OS_EXIT_CRITICAL();
                      OSSched();                                    /* Find highest priority task ready to run       */
                      return (OS_NO_ERR);
                  } else {
                      if (pevent->OSEventCnt < 65535) {             /* Make sure semaphore will not overflow         */
                          pevent->OSEventCnt++;                     /* Increment semaphore count to register event   */
                          OS_EXIT_CRITICAL();
                          return (OS_NO_ERR);
                      } else {                                      /* Semaphore value has reached its maximum       */
                          OS_EXIT_CRITICAL();
                          return (OS_SEM_OVF);
                      }
                  }
              }
              /*
              *********************************************************************************************************
              *                                          QUERY A SEMAPHORE
              *
              * Description: This function obtains information about a semaphore
              *
              * Arguments  : pevent        is a pointer to the event control block associated with the desired 
              *                            semaphore
              *
              *              ppdata         is a pointer to a structure that will contain information about the 
              *                            semaphore.
              *
              * Returns    : OS_NO_ERR          The call was successful and the message was sent
              *              OS_ERR_EVENT_TYPE  If you are attempting to obtain data from a non semaphore.
              *********************************************************************************************************
              */
              
              INT8U OSSemQuery (OS_EVENT DT_XDATA *pevent, OS_SEM_DATA DT_XDATA *ppdata) REENTRANT
              {
                  INT8U  i;
                  INT8U DT_XDATA *psrc;
                  INT8U DT_XDATA *pdest;
                  
                  
                  OS_ENTER_CRITICAL();
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_EVENT_TYPE);
                  }
                  ppdata->OSEventGrp = pevent->OSEventGrp;                /* Copy message mailbox wait list           */
                  psrc              = &pevent->OSEventTbl[0];
                  pdest             = &ppdata->OSEventTbl[0];
                  for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
                      *pdest++ = *psrc++;   
                  }
                  ppdata->OSCnt      = pevent->OSEventCnt;                /* Get semaphore count                      */
                  OS_EXIT_CRITICAL();
                  return (OS_NO_ERR);
              }
              #endif

C51 COMPILER V7.50   OS_SEM                                                                09/01/2008 22:58:57 PAGE 5   


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   ----    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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