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

📄 os_sem.lst

📁 uCOS 嵌入式操作系统的改进版,增加了网络通讯.
💻 LST
📖 第 1 页 / 共 2 页
字号:
 218   2                   OS_EXIT_CRITICAL();
 219   2                   *err = OS_ERR_INVALID_OPT;
 220   2                   return (pevent);
 221   2          }
 222   1      }
 223          #endif
 224          
 225          /*$PAGE*/
 226          /*
 227          *********************************************************************************************************
 228          *                                           PEND ON SEMAPHORE
 229          *
 230          * Description: This function waits for a semaphore.
 231          *
 232          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 233          *                            semaphore.
 234          *
 235          *              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
 236          *                            wait for the resource up to the amount of time specified by this argument.
 237          *                            If you specify 0, however, your task will wait forever at the specified
 238          *                            semaphore or, until the resource becomes available (or the event occurs).
 239          *
 240          *              err           is a pointer to where an error message will be deposited.  Possible error
C51 COMPILER V7.06   OS_SEM                                                                07/18/2003 11:06:03 PAGE 5   

 241          *                            messages are:
 242          *
 243          *                            OS_NO_ERR           The call was successful and your task owns the resource
 244          *                                                or, the event you are waiting for occurred.
 245          *                            OS_TIMEOUT          The semaphore was not received within the specified
 246          *                                                timeout.
 247          *                            OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore.
 248          *                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
 249          *                                                would lead to a suspension.
 250          *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
 251          *
 252          * Returns    : none
 253          *********************************************************************************************************
 254          */
 255          
 256          void  OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) reentrant //using 0
 257          {
 258   1      #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
 259   1          OS_CPU_SR  cpu_sr;
 260   1      #endif    
 261   1      
 262   1      
 263   1          if (OSIntNesting > 0) {                           /* See if called from ISR ...                    */
 264   2              *err = OS_ERR_PEND_ISR;                       /* ... can't PEND from an ISR                    */
 265   2              return;
 266   2          }
 267   1      #if OS_ARG_CHK_EN > 0
 268   1          if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 269   2              *err = OS_ERR_PEVENT_NULL;
 270   2              return;
 271   2          }
 272   1      #endif
 273   1          if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
 274   2              *err = OS_ERR_EVENT_TYPE;
 275   2              return;
 276   2          }
 277   1          OS_ENTER_CRITICAL();
 278   1          if (pevent->OSEventCnt > 0) {                     /* If sem. is positive, resource available ...   */
 279   2              pevent->OSEventCnt--;                         /* ... decrement semaphore only if positive.     */
 280   2              OS_EXIT_CRITICAL();
 281   2              *err = OS_NO_ERR;
 282   2              return;
 283   2          }
 284   1                                                            /* Otherwise, must wait until event occurs       */
 285   1          OSTCBCur->OSTCBStat |= OS_STAT_SEM;               /* Resource not available, pend on semaphore     */
 286   1          OSTCBCur->OSTCBDly   = timeout;                   /* Store pend timeout in TCB                     */
 287   1          OS_EventTaskWait(pevent);                         /* Suspend task until event or timeout occurs    */
 288   1          OS_EXIT_CRITICAL();
 289   1          OS_Sched();                                       /* Find next highest priority task ready         */
 290   1          OS_ENTER_CRITICAL();
 291   1          if (OSTCBCur->OSTCBStat & OS_STAT_SEM) {          /* Must have timed out if still waiting for event*/
 292   2              OS_EventTO(pevent);
 293   2              OS_EXIT_CRITICAL();
 294   2              *err = OS_TIMEOUT;                            /* Indicate that didn't get event within TO      */
 295   2              return;
 296   2          }
 297   1          OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
 298   1          OS_EXIT_CRITICAL();
 299   1          *err = OS_NO_ERR;
 300   1      }
 301          /*$PAGE*/
 302          /*
C51 COMPILER V7.06   OS_SEM                                                                07/18/2003 11:06:03 PAGE 6   

 303          *********************************************************************************************************
 304          *                                         POST TO A SEMAPHORE
 305          *
 306          * Description: This function signals a semaphore
 307          *
 308          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 309          *                            semaphore.
 310          *
 311          * Returns    : OS_NO_ERR           The call was successful and the semaphore was signaled.
 312          *              OS_SEM_OVF          If the semaphore count exceeded its limit.  In other words, you have
 313          *                                  signalled the semaphore more often than you waited on it with either
 314          *                                  OSSemAccept() or OSSemPend().
 315          *              OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore
 316          *              OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
 317          *********************************************************************************************************
 318          */
 319          
 320          INT8U  OSSemPost (OS_EVENT *pevent) reentrant //using 0
 321          {
 322   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
 323   1          OS_CPU_SR  cpu_sr;                               
 324   1      #endif    
 325   1      
 326   1      
 327   1      #if OS_ARG_CHK_EN > 0
 328   1          if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
 329   2              return (OS_ERR_PEVENT_NULL);
 330   2          }
 331   1      #endif
 332   1          if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
 333   2              return (OS_ERR_EVENT_TYPE);
 334   2          }
 335   1          OS_ENTER_CRITICAL();
 336   1          if (pevent->OSEventGrp != 0x00) {                      /* See if any task waiting for semaphore    */
 337   2              OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);   /* Ready highest prio task waiting on event */
 338   2              OS_EXIT_CRITICAL();
 339   2              OS_Sched();                                        /* Find highest priority task ready to run  */
 340   2              return (OS_NO_ERR);
 341   2          }
 342   1          if (pevent->OSEventCnt < 65535u) {                /* Make sure semaphore will not overflow         */
 343   2              pevent->OSEventCnt++;                         /* Increment semaphore count to register event   */
 344   2              OS_EXIT_CRITICAL();
 345   2              return (OS_NO_ERR);
 346   2          }
 347   1          OS_EXIT_CRITICAL();                               /* Semaphore value has reached its maximum       */
 348   1          return (OS_SEM_OVF);
 349   1      }
 350          /*$PAGE*/
 351          /*
 352          *********************************************************************************************************
 353          *                                          QUERY A SEMAPHORE
 354          *
 355          * Description: This function obtains information about a semaphore
 356          *
 357          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 358          *                            semaphore
 359          *
 360          *              pdata         is a pointer to a structure that will contain information about the
 361          *                            semaphore.
 362          *
 363          * Returns    : OS_NO_ERR           The call was successful and the message was sent
 364          *              OS_ERR_EVENT_TYPE   If you are attempting to obtain data from a non semaphore.
C51 COMPILER V7.06   OS_SEM                                                                07/18/2003 11:06:03 PAGE 7   

 365          *              OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
 366          *********************************************************************************************************
 367          */
 368          
 369          #if OS_SEM_QUERY_EN > 0
 370          INT8U  OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *pndata) reentrant //using 0
 371          {
 372   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
 373   1          OS_CPU_SR  cpu_sr;
 374   1      #endif    
 375   1          INT8U     *psrc;
 376   1          INT8U     *pdest;
 377   1      
 378   1      
 379   1      #if OS_ARG_CHK_EN > 0
 380   1          if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
 381   2              return (OS_ERR_PEVENT_NULL);
 382   2          }
 383   1      #endif
 384   1          if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
 385   2              return (OS_ERR_EVENT_TYPE);
 386   2          }
 387   1          OS_ENTER_CRITICAL();
 388   1          pndata->OSEventGrp = pevent->OSEventGrp;                /* Copy message mailbox wait list           */
 389   1          psrc              = &pevent->OSEventTbl[0];
 390   1          pdest             = &pndata->OSEventTbl[0];
 391   1      #if OS_EVENT_TBL_SIZE > 0
 392   1          *pdest++          = *psrc++;
 393   1      #endif
 394   1      
 395   1      #if OS_EVENT_TBL_SIZE > 1
 396   1          *pdest++          = *psrc++;
 397   1      #endif
 398   1      
 399   1      #if OS_EVENT_TBL_SIZE > 2
 400   1          *pdest++          = *psrc++;
 401   1      #endif
 402   1      
 403   1      #if OS_EVENT_TBL_SIZE > 3
 404   1          *pdest++          = *psrc++;
 405   1      #endif
 406   1      
 407   1      #if OS_EVENT_TBL_SIZE > 4
 408   1          *pdest++          = *psrc++;
 409   1      #endif
 410   1      
 411   1      #if OS_EVENT_TBL_SIZE > 5
 412   1          *pdest++          = *psrc++;
 413   1      #endif
 414   1      
 415   1      #if OS_EVENT_TBL_SIZE > 6
 416   1          *pdest++          = *psrc++;
 417   1      #endif
 418   1      
 419   1      #if OS_EVENT_TBL_SIZE > 7
 420   1          *pdest            = *psrc;
 421   1      #endif
 422   1          pndata->OSCnt      = pevent->OSEventCnt;                /* Get semaphore count                      */
 423   1          OS_EXIT_CRITICAL();
 424   1          return (OS_NO_ERR);
 425   1      }
 426          #endif                                                     /* OS_SEM_QUERY_EN                          */
C51 COMPILER V7.06   OS_SEM                                                                07/18/2003 11:06:03 PAGE 8   

 427          #endif                                                     /* OS_SEM_EN                                */


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