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

📄 os_sem.lst

📁 uCos-ii 2.86 在C8051F410单片机上移植成功!!! 其中包括:UART驱动
💻 LST
📖 第 1 页 / 共 3 页
字号:
                               
                          case OS_PEND_OPT_NONE:
                          default:                                  /* No,  ready HPT       waiting on semaphore     */
                               (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM, OS_STAT_PEND_ABORT);
                               nbr_tasks++;
                               break;
                      }
                      OS_EXIT_CRITICAL();
                      OS_Sched();                                   /* Find HPT ready to run                         */
                      *perr = OS_ERR_PEND_ABORT;
C51 COMPILER V8.17   OS_SEM                                                                03/26/2009 14:24:25 PAGE 8   

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

 488          *********************************************************************************************************
 489          *                                          QUERY A SEMAPHORE
 490          *
 491          * Description: This function obtains information about a semaphore
 492          *
 493          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 494          *                            semaphore
 495          *
 496          *              p_sem_data    is a pointer to a structure that will contain information about the
 497          *                            semaphore.
 498          *
 499          * Returns    : OS_ERR_NONE         The call was successful and the message was sent
 500          *              OS_ERR_EVENT_TYPE   If you are attempting to obtain data from a non semaphore.
 501          *              OS_ERR_PEVENT_NULL  If 'pevent'     is a NULL pointer.
 502          *              OS_ERR_PDATA_NULL   If 'p_sem_data' is a NULL pointer
 503          *********************************************************************************************************
 504          */
 505          
 506          #if OS_SEM_QUERY_EN > 0
              INT8U  OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *p_sem_data) reentrant
              {
              #if OS_LOWEST_PRIO <= 63
                  INT8U     *psrc;
                  INT8U     *pdest;
              #else
                  INT16U    *psrc;
                  INT16U    *pdest;
              #endif
                  INT8U      i;
              #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
              
              
              
              #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
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
                      return (OS_ERR_EVENT_TYPE);
                  }
                  OS_ENTER_CRITICAL();
                  p_sem_data->OSEventGrp = pevent->OSEventGrp;           /* Copy message mailbox wait list           */
                  psrc                   = &pevent->OSEventTbl[0];
                  pdest                  = &p_sem_data->OSEventTbl[0];
                  for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
                      *pdest++ = *psrc++;
                  }
                  p_sem_data->OSCnt = pevent->OSEventCnt;                /* Get semaphore count                      */
                  OS_EXIT_CRITICAL();
                  return (OS_ERR_NONE);
              }
              #endif                                                     /* OS_SEM_QUERY_EN                          */
 546          
 547          /*$PAGE*/
 548          /*
 549          *********************************************************************************************************
C51 COMPILER V8.17   OS_SEM                                                                03/26/2009 14:24:25 PAGE 10  

 550          *                                              SET SEMAPHORE
 551          *
 552          * Description: This function sets the semaphore count to the value specified as an argument.  Typically,
 553          *              this value would be 0.
 554          *
 555          *              You would typically use this function when a semaphore is used as a signaling mechanism
 556          *              and, you want to reset the count value.
 557          *
 558          * Arguments  : pevent     is a pointer to the event control block
 559          *
 560          *              cnt        is the new value for the semaphore count.  You would pass 0 to reset the
 561          *                         semaphore count.
 562          *
 563          *              perr       is a pointer to an error code returned by the function as follows:
 564          *
 565          *                            OS_ERR_NONE          The call was successful and the semaphore value was set.
 566          *                            OS_ERR_EVENT_TYPE    If you didn't pass a pointer to a semaphore.
 567          *                            OS_ERR_PEVENT_NULL   If 'pevent' is a NULL pointer.
 568          *                            OS_ERR_TASK_WAITING  If tasks are waiting on the semaphore.
 569          *********************************************************************************************************
 570          */
 571          
 572          #if OS_SEM_SET_EN > 0
              void  OSSemSet (OS_EVENT *pevent, INT16U cnt, INT8U *perr) reentrant
              {
              #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
              
              
              
              #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
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
                      *perr = OS_ERR_EVENT_TYPE;
                      return;
                  }
                  OS_ENTER_CRITICAL();
                  *perr = OS_ERR_NONE;
                  if (pevent->OSEventCnt > 0) {                     /* See if semaphore already has a count          */
                      pevent->OSEventCnt = cnt;                     /* Yes, set it to the new value specified.       */
                  } else {                                          /* No                                            */
                      if (pevent->OSEventGrp == 0) {                /*      See if task(s) waiting?                  */
                          pevent->OSEventCnt = cnt;                 /*      No, OK to set the value                  */
                      } else {
                          *perr              = OS_ERR_TASK_WAITING;
                      }
                  }
                  OS_EXIT_CRITICAL();
              }
              #endif
 608          
 609          #endif                                                /* OS_SEM_EN                                     */


C51 COMPILER V8.17   OS_SEM                                                                03/26/2009 14:24:25 PAGE 11  

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