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

📄 os_sem.lst

📁 在C8051F120内移植uCOS-II
💻 LST
📖 第 1 页 / 共 2 页
字号:
 138   1      
 139   1          OS_ENTER_CRITICAL();
 140   1          if (pevent->OSEventType != OS_EVENT_TYPE_SEM)  /* Validate event block type                     */
 141   1          {  
 142   2              OS_EXIT_CRITICAL();
 143   2              *err = OS_ERR_EVENT_TYPE;
 144   2          }
 145   1          if (pevent->OSEventCnt > 0)  /* If sem. is positive, resource available ...   */
 146   1          {                    
 147   2              pevent->OSEventCnt--;                         /* ... decrement semaphore only if positive.     */
 148   2              OS_EXIT_CRITICAL();
 149   2              *err = OS_NO_ERR;
 150   2          } 
 151   1          else if (OSIntNesting > 0)  /* See if called from ISR ...                    */
 152   1          {                   
 153   2              OS_EXIT_CRITICAL();                           /* ... can't PEND from an ISR                    */
 154   2              *err = OS_ERR_PEND_ISR;
 155   2          } 
 156   1          else 
 157   1          {                                          /* Otherwise, must wait until event occurs       */
 158   2              OSTCBCur->OSTCBStat    |= OS_STAT_SEM;        /* Resource not available, pend on semaphore     */
 159   2              OSTCBCur->OSTCBDly      = timeout;            /* Store pend timeout in TCB                     */
 160   2              OSEventTaskWait(pevent);                      /* Suspend task until event or timeout occurs    */
 161   2              OS_EXIT_CRITICAL();
 162   2              OSSched();                                    /* Find next highest priority task ready         */
 163   2              OS_ENTER_CRITICAL();
 164   2              if (OSTCBCur->OSTCBStat & OS_STAT_SEM) 
 165   2              {      /* Must have timed out if still waiting for event*/
 166   3                  OSEventTO(pevent);
 167   3                  OS_EXIT_CRITICAL();
 168   3                  *err = OS_TIMEOUT;                        /* Indicate that didn't get event within TO      */
 169   3              } 
 170   2              else 
 171   2              {
 172   3                  OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
 173   3                  OS_EXIT_CRITICAL();
 174   3                  *err = OS_NO_ERR;
 175   3              }
 176   2          }
 177   1      }
 178          #endif
 179          /*$PAGE*/
C51 COMPILER V8.08   OS_SEM                                                                04/13/2009 13:31:22 PAGE 4   

 180          /*
 181          *********************************************************************************************************
 182          *                                         POST TO A SEMAPHORE
 183          *
 184          * Description: This function signals a semaphore
 185          *
 186          * Arguments  : pevent        is a pointer to the event control block associated with the desired 
 187          *                            semaphore.
 188          *
 189          * Returns    : OS_NO_ERR          The call was successful and the semaphore was signaled.
 190          *              OS_SEM_OVF         If the semaphore count exceeded its limit.  In other words, you have 
 191          *                                 signalled the semaphore more often than you waited on it with either
 192          *                                 OSSemAccept() or OSSemPend().
 193          *              OS_ERR_EVENT_TYPE  If you didn't pass a pointer to a semaphore
 194          *********************************************************************************************************
 195          */
 196          #if OS_Sem_Post_EN
 197          INT8U OSSemPost (OS_EVENT *pevent)reentrant
 198          {
 199   1          #if OS_CRITICAL_METHOD == 2
 200   1              unsigned DTYPE int_ss;
 201   1              #endif
 202   1               
 203   1              OS_ENTER_CRITICAL();
 204   1          if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
 205   2              OS_EXIT_CRITICAL();
 206   2              return (OS_ERR_EVENT_TYPE);
 207   2          }
 208   1          if (pevent->OSEventGrp) {                              /* See if any task waiting for semaphore    */
 209   2              OSEventTaskRdy(pevent, (void *)0, OS_STAT_SEM);    /* Ready highest prio task waiting on event */
 210   2              OS_EXIT_CRITICAL();
 211   2              OSSched();                                    /* Find highest priority task ready to run       */
 212   2              return (OS_NO_ERR);
 213   2          } else {
 214   2              if (pevent->OSEventCnt < 65535) {             /* Make sure semaphore will not overflow         */
 215   3                  pevent->OSEventCnt++;                     /* Increment semaphore count to register event   */
 216   3                  OS_EXIT_CRITICAL();
 217   3                  return (OS_NO_ERR);
 218   3              } else {                                      /* Semaphore value has reached its maximum       */
 219   3                  OS_EXIT_CRITICAL();
 220   3                  return (OS_SEM_OVF);
 221   3              }
 222   2          }
 223   1      }
 224          #endif
 225          /*
 226          *********************************************************************************************************
 227          *                                          QUERY A SEMAPHORE
 228          *
 229          * Description: This function obtains information about a semaphore
 230          *
 231          * Arguments  : pevent        is a pointer to the event control block associated with the desired 
 232          *                            semaphore
 233          *
 234          *              dataptr         is a pointer to a structure that will contain information about the 
 235          *                            semaphore.
 236          *
 237          * Returns    : OS_NO_ERR          The call was successful and the message was sent
 238          *              OS_ERR_EVENT_TYPE  If you are attempting to obtain data from a non semaphore.
 239          *********************************************************************************************************
 240          */
 241          #if   OS_Sem_Query_EN
C51 COMPILER V8.08   OS_SEM                                                                04/13/2009 13:31:22 PAGE 5   

              INT8U OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *dataptr)reentrant
              {
                  INT8U  i;
                  INT8U *psrc;
                  INT8U *pdest;
                  
                  
                  OS_ENTER_CRITICAL();
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_EVENT_TYPE);
                  }
                  dataptr->OSEventGrp = pevent->OSEventGrp;                /* Copy message mailbox wait list           *
             -/
                  psrc              = &pevent->OSEventTbl[0];
                  pdest             = &dataptr->OSEventTbl[0];
                  for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
                      *pdest++ = *psrc++;   
                  }
                  dataptr->OSCnt      = pevent->OSEventCnt;                /* Get semaphore count                      *
             -/
                  OS_EXIT_CRITICAL();
                  return (OS_NO_ERR);
              }
              #endif
 265          #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    673    ----
   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 + -