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

📄 os_sem.lst

📁 UCOSII2.85针对8051单片机的移植版本
💻 LST
📖 第 1 页 / 共 3 页
字号:
 415   3                  case OS_PEND_OPT_NONE:                    /* No,  ready HPT       waiting on semaphore     */
 416   3                  default:
 417   3                       (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM, OS_STAT_PEND_ABORT);
 418   3                       nbr_tasks++;
 419   3                       break;
 420   3              }
 421   2              OS_EXIT_CRITICAL();
 422   2              OS_Sched();                                   /* Find HPT ready to run                         */
 423   2              *perr = OS_ERR_PEND_ABORT;
 424   2              return (nbr_tasks);
 425   2          }
 426   1          OS_EXIT_CRITICAL();
C51 COMPILER V7.50   OS_SEM                                                                12/14/2007 08:25:43 PAGE 8   

 427   1          *perr = OS_ERR_NONE;
 428   1          return (0);                                       /* No tasks waiting on semaphore                 */
 429   1      }
 430          #endif
 431          
 432          /*$PAGE*/
 433          /*
 434          *********************************************************************************************************
 435          *                                         POST TO A SEMAPHORE
 436          *
 437          * Description: This function signals a semaphore
 438          *
 439          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 440          *                            semaphore.
 441          *
 442          * Returns    : OS_ERR_NONE         The call was successful and the semaphore was signaled.
 443          *              OS_ERR_SEM_OVF      If the semaphore count exceeded its limit.  In other words, you have
 444          *                                  signalled the semaphore more often than you waited on it with either
 445          *                                  OSSemAccept() or OSSemPend().
 446          *              OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore
 447          *              OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
 448          *********************************************************************************************************
 449          */
 450          
 451          INT8U  OSSemPost (OS_EVENT *pevent) reentrant
 452          {
 453   1      #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 456   1      
 457   1      
 458   1      
 459   1      #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
                      return (OS_ERR_PEVENT_NULL);
                  }
              #endif
 464   1          if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
 465   2              return (OS_ERR_EVENT_TYPE);
 466   2          }
 467   1          OS_ENTER_CRITICAL();
 468   1          if (pevent->OSEventGrp != 0) {                    /* See if any task waiting for semaphore         */
 469   2                                                            /* Ready HPT waiting on event                    */
 470   2              (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM, OS_STAT_PEND_OK);
 471   2              OS_EXIT_CRITICAL();
 472   2              OS_Sched();                                   /* Find HPT ready to run                         */
 473   2              return (OS_ERR_NONE);
 474   2          }
 475   1          if (pevent->OSEventCnt < 65535u) {                /* Make sure semaphore will not overflow         */
 476   2              pevent->OSEventCnt++;                         /* Increment semaphore count to register event   */
 477   2              OS_EXIT_CRITICAL();
 478   2              return (OS_ERR_NONE);
 479   2          }
 480   1          OS_EXIT_CRITICAL();                               /* Semaphore value has reached its maximum       */
 481   1          return (OS_ERR_SEM_OVF);
 482   1      }
 483          
 484          /*$PAGE*/
 485          /*
 486          *********************************************************************************************************
 487          *                                          QUERY A SEMAPHORE
 488          *
C51 COMPILER V7.50   OS_SEM                                                                12/14/2007 08:25:43 PAGE 9   

 489          * Description: This function obtains information about a semaphore
 490          *
 491          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 492          *                            semaphore
 493          *
 494          *              p_sem_data    is a pointer to a structure that will contain information about the
 495          *                            semaphore.
 496          *
 497          * Returns    : OS_ERR_NONE         The call was successful and the message was sent
 498          *              OS_ERR_EVENT_TYPE   If you are attempting to obtain data from a non semaphore.
 499          *              OS_ERR_PEVENT_NULL  If 'pevent'     is a NULL pointer.
 500          *              OS_ERR_PDATA_NULL   If 'p_sem_data' is a NULL pointer
 501          *********************************************************************************************************
 502          */
 503          
 504          #if OS_SEM_QUERY_EN > 0
 505          INT8U  OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *p_sem_data) reentrant
 506          {
 507   1      #if OS_LOWEST_PRIO <= 63
 508   1          INT8U     *psrc;
 509   1          INT8U     *pdest;
 510   1      #else
                  INT16U    *psrc;
                  INT16U    *pdest;
              #endif
 514   1          INT8U      i;
 515   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 518   1      
 519   1      
 520   1      
 521   1      #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
                      return (OS_ERR_PEVENT_NULL);
                  }
                  if (p_sem_data == (OS_SEM_DATA *)0) {                  /* Validate 'p_sem_data'                    */
                      return (OS_ERR_PDATA_NULL);
                  }
              #endif
 529   1          if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
 530   2              return (OS_ERR_EVENT_TYPE);
 531   2          }
 532   1          OS_ENTER_CRITICAL();
 533   1          p_sem_data->OSEventGrp = pevent->OSEventGrp;           /* Copy message mailbox wait list           */
 534   1          psrc                   = &pevent->OSEventTbl[0];
 535   1          pdest                  = &p_sem_data->OSEventTbl[0];
 536   1          for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
 537   2              *pdest++ = *psrc++;
 538   2          }
 539   1          p_sem_data->OSCnt = pevent->OSEventCnt;                /* Get semaphore count                      */
 540   1          OS_EXIT_CRITICAL();
 541   1          return (OS_ERR_NONE);
 542   1      }
 543          #endif                                                     /* OS_SEM_QUERY_EN                          */
 544          
 545          /*$PAGE*/
 546          /*
 547          *********************************************************************************************************
 548          *                                              SET SEMAPHORE
 549          *
 550          * Description: This function sets the semaphore count to the value specified as an argument.  Typically,
C51 COMPILER V7.50   OS_SEM                                                                12/14/2007 08:25:43 PAGE 10  

 551          *              this value would be 0.
 552          *
 553          *              You would typically use this function when a semaphore is used as a signaling mechanism
 554          *              and, you want to reset the count value.
 555          *
 556          * Arguments  : pevent     is a pointer to the event control block
 557          *
 558          *              cnt        is the new value for the semaphore count.  You would pass 0 to reset the
 559          *                         semaphore count.
 560          *
 561          *              perr       is a pointer to an error code returned by the function as follows:
 562          *
 563          *                            OS_ERR_NONE          The call was successful and the semaphore value was set.
 564          *                            OS_ERR_EVENT_TYPE    If you didn't pass a pointer to a semaphore.
 565          *                            OS_ERR_PEVENT_NULL   If 'pevent' is a NULL pointer.
 566          *                            OS_ERR_TASK_WAITING  If tasks are waiting on the semaphore.
 567          *********************************************************************************************************
 568          */
 569          
 570          #if OS_SEM_SET_EN > 0
 571          void  OSSemSet (OS_EVENT *pevent, INT16U cnt, INT8U *perr) reentrant
 572          {
 573   1      #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 576   1      
 577   1      
 578   1      
 579   1      #if OS_ARG_CHK_EN > 0
                  if (perr == (INT8U *)0) {                         /* Validate 'perr'                               */
                      return;
                  }
                  if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
                      *perr = OS_ERR_PEVENT_NULL;
                      return;
                  }
              #endif
 588   1          if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
 589   2              *perr = OS_ERR_EVENT_TYPE;
 590   2              return;
 591   2          }
 592   1          OS_ENTER_CRITICAL();
 593   1          *perr = OS_ERR_NONE;
 594   1          if (pevent->OSEventCnt > 0) {                     /* See if semaphore already has a count          */
 595   2              pevent->OSEventCnt = cnt;                     /* Yes, set it to the new value specified.       */
 596   2          } else {                                          /* No                                            */
 597   2              if (pevent->OSEventGrp == 0) {                /*      See if task(s) waiting?                  */
 598   3                  pevent->OSEventCnt = cnt;                 /*      No, OK to set the value                  */
 599   3              } else {
 600   3                  *perr              = OS_ERR_TASK_WAITING;
 601   3              }
 602   2          }
 603   1          OS_EXIT_CRITICAL();
 604   1      }
 605          #endif
 606          
 607          #endif                                                /* OS_SEM_EN                                     */


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2406    ----
   CONSTANT SIZE    =   ----    ----
C51 COMPILER V7.50   OS_SEM                                                                12/14/2007 08:25:43 PAGE 11  

   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 + -