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

📄 os_sem.lst

📁 UCOSii for c8051f020
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   OS_SEM                                                                03/05/2008 20:23:55 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE OS_SEM
OBJECT MODULE PLACED IN .\obj\OS_SEM.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE uCosii\OS_SEM.C LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\lst\OS_SEM.lst) OBJ
                    -ECT(.\obj\OS_SEM.obj)

stmt level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/OS-II
   4          *                                          The Real-Time Kernel
   5          *                                          SEMAPHORE MANAGEMENT
   6          *
   7          *                          (c) Copyright 1992-2001, Jean J. Labrosse, Weston, FL
   8          *                                           All Rights Reserved
   9          *
  10          * File : OS_SEM.C
  11          * By   : Jean J. Labrosse
  12          *********************************************************************************************************
  13          */
  14          
  15          #ifndef  OS_MASTER_FILE
  16          #include "source\includes.h"
  17          #endif
  18          
  19          #if OS_SEM_EN > 0
  20          /*
  21          *********************************************************************************************************
  22          *                                           ACCEPT SEMAPHORE
  23          *
  24          * Description: This function checks the semaphore to see if a resource is available or, if an event
  25          *              occurred.  Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the
  26          *              resource is not available or the event did not occur.
  27          *
  28          * Arguments  : pevent     is a pointer to the event control block
  29          *
  30          * Returns    : >  0       if the resource is available or the event did not occur the semaphore is
  31          *                         decremented to obtain the resource.
  32          *              == 0       if the resource is not available or the event did not occur or,
  33          *                         if 'pevent' is a NULL pointer or,
  34          *                         if you didn't pass a pointer to a semaphore
  35          *********************************************************************************************************
  36          */
  37          
  38          #if OS_SEM_ACCEPT_EN > 0
              INT16U  OSSemAccept (OS_EVENT *pevent) reentrant
              {
              #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
                  OS_CPU_SR  cpu_sr;
              #endif    
                  INT16U     cnt;
              
              
              #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
                      return (0);
                  }
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
                      return (0);
                  }
              #endif
C51 COMPILER V7.06   OS_SEM                                                                03/05/2008 20:23:55 PAGE 2   

                  OS_ENTER_CRITICAL();
                  cnt = pevent->OSEventCnt;
                  if (cnt > 0) {                                    /* See if resource is available                  */
                      pevent->OSEventCnt--;                         /* Yes, decrement semaphore and notify caller    */
                  }
                  OS_EXIT_CRITICAL();
                  return (cnt);                                     /* Return semaphore count                        */
              }
              #endif    
  64          
  65          /*$PAGE*/
  66          /*
  67          *********************************************************************************************************
  68          *                                           CREATE A SEMAPHORE
  69          *
  70          * Description: This function creates a semaphore.
  71          *
  72          * Arguments  : cnt           is the initial value for the semaphore.  If the value is 0, no resource is
  73          *                            available (or no event has occurred).  You initialize the semaphore to a
  74          *                            non-zero value to specify how many resources are available (e.g. if you have
  75          *                            10 resources, you would initialize the semaphore to 10).
  76          *
  77          * Returns    : != (void *)0  is a pointer to the event control clock (OS_EVENT) associated with the
  78          *                            created semaphore
  79          *              == (void *)0  if no event control blocks were available
  80          *********************************************************************************************************
  81          */
  82          
  83          OS_EVENT  *OSSemCreate (INT16U cnt) reentrant
  84          {
  85   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;
              #endif    
  88   1          OS_EVENT  *pevent;
  89   1      
  90   1      
  91   1          if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
  92   2              return ((OS_EVENT *)0);                            /* ... can't CREATE from an ISR             */
  93   2          }
  94   1          OS_ENTER_CRITICAL();
  95   1          pevent = OSEventFreeList;                              /* Get next free event control block        */
  96   1          if (OSEventFreeList != (OS_EVENT *)0) {                /* See if pool of free ECB pool was empty   */
  97   2              OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
  98   2          }
  99   1          OS_EXIT_CRITICAL();
 100   1          if (pevent != (OS_EVENT *)0) {                         /* Get an event control block               */
 101   2              pevent->OSEventType = OS_EVENT_TYPE_SEM;
 102   2              pevent->OSEventCnt  = cnt;                         /* Set semaphore value                      */
 103   2              OS_EventWaitListInit(pevent);
 104   2          }
 105   1          return (pevent);
 106   1      }
 107          
 108          /*$PAGE*/
 109          /*
 110          *********************************************************************************************************
 111          *                                         DELETE A SEMAPHORE
 112          *
 113          * Description: This function deletes a semaphore and readies all tasks pending on the semaphore.
 114          *
 115          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 116          *                            semaphore.
C51 COMPILER V7.06   OS_SEM                                                                03/05/2008 20:23:55 PAGE 3   

 117          *
 118          *              opt           determines delete options as follows:
 119          *                            opt == OS_DEL_NO_PEND   Delete semaphore ONLY if no task pending
 120          *                            opt == OS_DEL_ALWAYS    Deletes the semaphore even if tasks are waiting.
 121          *                                                    In this case, all the tasks pending will be readied.
 122          *
 123          *              err           is a pointer to an error code that can contain one of the following values:
 124          *                            OS_NO_ERR               The call was successful and the semaphore was deleted
 125          *                            OS_ERR_DEL_ISR          If you attempted to delete the semaphore from an ISR
 126          *                            OS_ERR_INVALID_OPT      An invalid option was specified
 127          *                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the semaphore
 128          *                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a semaphore
 129          *                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
 130          *
 131          * Returns    : pevent        upon error
 132          *              (OS_EVENT *)0 if the semaphore was successfully deleted.
 133          *
 134          * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
 135          *                 the semaphore MUST check the return code of OSSemPend().
 136          *              2) OSSemAccept() callers will not know that the intended semaphore has been deleted unless
 137          *                 they check 'pevent' to see that it's a NULL pointer.
 138          *              3) This call can potentially disable interrupts for a long time.  The interrupt disable
 139          *                 time is directly proportional to the number of tasks waiting on the semaphore.
 140          *              4) Because ALL tasks pending on the semaphore will be readied, you MUST be careful in
 141          *                 applications where the semaphore is used for mutual exclusion because the resource(s)
 142          *                 will no longer be guarded by the semaphore.
 143          *********************************************************************************************************
 144          */
 145          
 146          #if OS_SEM_DEL_EN > 0
              OS_EVENT  *OSSemDel (OS_EVENT *pevent, INT8U opt, INT8U *err) reentrant
              {
              #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
                  OS_CPU_SR  cpu_sr;
              #endif    
                  BOOLEAN    tasks_waiting;
              
              
                  if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
                      *err = OS_ERR_DEL_ISR;                             /* ... can't DELETE from an ISR             */
                      return (pevent);
                  }
              #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
                      *err = OS_ERR_PEVENT_NULL;
                      return (pevent);
                  }
                  if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
                      *err = OS_ERR_EVENT_TYPE;
                      return (pevent);
                  }
              #endif
                  OS_ENTER_CRITICAL();
                  if (pevent->OSEventGrp != 0x00) {                      /* See if any tasks waiting on semaphore    */
                      tasks_waiting = TRUE;                              /* Yes                                      */
                  } else {
                      tasks_waiting = FALSE;                             /* No                                       */
                  }
                  switch (opt) {
                      case OS_DEL_NO_PEND:                               /* Delete semaphore only if no task waiting */
                           if (tasks_waiting == FALSE) {
                               pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
C51 COMPILER V7.06   OS_SEM                                                                03/05/2008 20:23:55 PAGE 4   

                               pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block to free list  */
                               OSEventFreeList     = pevent;             /* Get next free event control block        */
                               OS_EXIT_CRITICAL();
                               *err = OS_NO_ERR;
                               return ((OS_EVENT *)0);                   /* Semaphore has been deleted               */
                           } else {
                               OS_EXIT_CRITICAL();
                               *err = OS_ERR_TASK_WAITING;
                               return (pevent);
                           }
              
                      case OS_DEL_ALWAYS:                                /* Always delete the semaphore              */
                           while (pevent->OSEventGrp != 0x00) {          /* Ready ALL tasks waiting for semaphore    */
                               OS_EventTaskRdy(pevent, (void *)0, OS_STAT_SEM);
                           }
                           pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
                           pevent->OSEventPtr  = OSEventFreeList;        /* Return Event Control Block to free list  */
                           OSEventFreeList     = pevent;                 /* Get next free event control block        */
                           OS_EXIT_CRITICAL();
                           if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) were waiting  */
                               OS_Sched();                               /* Find highest priority task ready to run  */
                           }
                           *err = OS_NO_ERR;
                           return ((OS_EVENT *)0);                       /* Semaphore has been deleted               */
              
                      default:
                           OS_EXIT_CRITICAL();
                           *err = OS_ERR_INVALID_OPT;
                           return (pevent);
                  }
              }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -