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

📄 os_sem.lst

📁 UCOSii for c8051f020
💻 LST
📖 第 1 页 / 共 2 页
字号:
              #endif
 211          
 212          /*$PAGE*/
 213          /*
 214          *********************************************************************************************************
 215          *                                           PEND ON SEMAPHORE
 216          *
 217          * Description: This function waits for a semaphore.
 218          *
 219          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 220          *                            semaphore.
 221          *
 222          *              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
 223          *                            wait for the resource up to the amount of time specified by this argument.
 224          *                            If you specify 0, however, your task will wait forever at the specified
 225          *                            semaphore or, until the resource becomes available (or the event occurs).
 226          *
 227          *              err           is a pointer to where an error message will be deposited.  Possible error
 228          *                            messages are:
 229          *
 230          *                            OS_NO_ERR           The call was successful and your task owns the resource
 231          *                                                or, the event you are waiting for occurred.
 232          *                            OS_TIMEOUT          The semaphore was not received within the specified
 233          *                                                timeout.
 234          *                            OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore.
 235          *                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
 236          *                                                would lead to a suspension.
 237          *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
 238          *
 239          * Returns    : none
 240          *********************************************************************************************************
C51 COMPILER V7.06   OS_SEM                                                                03/05/2008 20:23:55 PAGE 5   

 241          */
 242          
 243          void  OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) reentrant
 244          {
 245   1      #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr;
              #endif    
 248   1      
 249   1      
 250   1          if (OSIntNesting > 0) {                           /* See if called from ISR ...                    */
 251   2              *err = OS_ERR_PEND_ISR;                       /* ... can't PEND from an ISR                    */
 252   2              return;
 253   2          }
 254   1      #if OS_ARG_CHK_EN > 0
 255   1          if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 256   2              *err = OS_ERR_PEVENT_NULL;
 257   2              return;
 258   2          }
 259   1          if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
 260   2              *err = OS_ERR_EVENT_TYPE;
 261   2              return;
 262   2          }
 263   1      #endif
 264   1          OS_ENTER_CRITICAL();
 265   1          if (pevent->OSEventCnt > 0) {                     /* If sem. is positive, resource available ...   */
 266   2              pevent->OSEventCnt--;                         /* ... decrement semaphore only if positive.     */
 267   2              OS_EXIT_CRITICAL();
 268   2              *err = OS_NO_ERR;
 269   2              return;
 270   2          }
 271   1                                                            /* Otherwise, must wait until event occurs       */
 272   1          OSTCBCur->OSTCBStat |= OS_STAT_SEM;               /* Resource not available, pend on semaphore     */
 273   1          OSTCBCur->OSTCBDly   = timeout;                   /* Store pend timeout in TCB                     */
 274   1          OS_EventTaskWait(pevent);                         /* Suspend task until event or timeout occurs    */
 275   1          OS_EXIT_CRITICAL();
 276   1          OS_Sched();                                       /* Find next highest priority task ready         */
 277   1          OS_ENTER_CRITICAL();
 278   1          if (OSTCBCur->OSTCBStat & OS_STAT_SEM) {          /* Must have timed out if still waiting for event*/
 279   2              OS_EventTO(pevent);
 280   2              OS_EXIT_CRITICAL();
 281   2              *err = OS_TIMEOUT;                            /* Indicate that didn't get event within TO      */
 282   2              return;
 283   2          }
 284   1          OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
 285   1          OS_EXIT_CRITICAL();
 286   1          *err = OS_NO_ERR;
 287   1      }
 288          /*$PAGE*/
 289          /*
 290          *********************************************************************************************************
 291          *                                         POST TO A SEMAPHORE
 292          *
 293          * Description: This function signals a semaphore
 294          *
 295          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 296          *                            semaphore.
 297          *
 298          * Returns    : OS_NO_ERR           The call was successful and the semaphore was signaled.
 299          *              OS_SEM_OVF          If the semaphore count exceeded its limit.  In other words, you have
 300          *                                  signalled the semaphore more often than you waited on it with either
 301          *                                  OSSemAccept() or OSSemPend().
 302          *              OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore
C51 COMPILER V7.06   OS_SEM                                                                03/05/2008 20:23:55 PAGE 6   

 303          *              OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
 304          *********************************************************************************************************
 305          */
 306          
 307          INT8U  OSSemPost (OS_EVENT *pevent) reentrant
 308          {
 309   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;                               
              #endif    
 312   1      
 313   1      
 314   1      #if OS_ARG_CHK_EN > 0
 315   1          if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
 316   2              return (OS_ERR_PEVENT_NULL);
 317   2          }
 318   1          if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
 319   2              return (OS_ERR_EVENT_TYPE);
 320   2          }
 321   1      #endif
 322   1          OS_ENTER_CRITICAL();
 323   1          if (pevent->OSEventGrp != 0x00) {                      /* See if any task waiting for semaphore    */
 324   2              OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);   /* Ready highest prio task waiting on event */
 325   2              OS_EXIT_CRITICAL();
 326   2              OS_Sched();                                   /* Find highest priority task ready to run       */
 327   2              return (OS_NO_ERR);
 328   2          }
 329   1          if (pevent->OSEventCnt < 65535) {                 /* Make sure semaphore will not overflow         */
 330   2              pevent->OSEventCnt++;                         /* Increment semaphore count to register event   */
 331   2              OS_EXIT_CRITICAL();
 332   2              return (OS_NO_ERR);
 333   2          }
 334   1          OS_EXIT_CRITICAL();                               /* Semaphore value has reached its maximum       */
 335   1          return (OS_SEM_OVF);
 336   1      }
 337          /*
 338          *********************************************************************************************************
 339          *                                          QUERY A SEMAPHORE
 340          *
 341          * Description: This function obtains information about a semaphore
 342          *
 343          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 344          *                            semaphore
 345          *
 346          *              ppdata         is a pointer to a structure that will contain information about the
 347          *                            semaphore.
 348          *
 349          * Returns    : OS_NO_ERR           The call was successful and the message was sent
 350          *              OS_ERR_EVENT_TYPE   If you are attempting to obtain data from a non semaphore.
 351          *              OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
 352          *********************************************************************************************************
 353          */
 354          
 355          #if OS_SEM_QUERY_EN > 0
              INT8U  OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *ppdata) reentrant
              {
              #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;
              #endif    
                  INT8U     *psrc;
                  INT8U     *pdest;
              
              
C51 COMPILER V7.06   OS_SEM                                                                03/05/2008 20:23:55 PAGE 7   

              #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
                      return (OS_ERR_PEVENT_NULL);
                  }
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
                      return (OS_ERR_EVENT_TYPE);
                  }
              #endif
                  OS_ENTER_CRITICAL();
                  ppdata->OSEventGrp = pevent->OSEventGrp;                /* Copy message mailbox wait list           */
                  psrc              = &pevent->OSEventTbl[0];
                  pdest             = &ppdata->OSEventTbl[0];
              #if OS_EVENT_TBL_SIZE > 0
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 1
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 2
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 3
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 4
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 5
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 6
                  *pdest++          = *psrc++;
              #endif
              
              #if OS_EVENT_TBL_SIZE > 7
                  *pdest            = *psrc;
              #endif
                  ppdata->OSCnt      = pevent->OSEventCnt;                /* Get semaphore count                      */
                  OS_EXIT_CRITICAL();
                  return (OS_NO_ERR);
              }
              #endif                                                     /* OS_SEM_QUERY_EN                          */
 413          #endif                                                     /* OS_SEM_EN                                */


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