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

📄 os_mutex.lst

📁 uCOS 嵌入式操作系统的改进版,增加了网络通讯.
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.06   OS_MUTEX                                                              07/18/2003 11:06:01 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE OS_MUTEX
OBJECT MODULE PLACED IN .\os_mutex.obj
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE ..\keilc51\os_mutex.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\os_mutex.lst)
                    - OBJECT(.\os_mutex.obj)

stmt level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/OS-II
   4          *                                          The Real-Time Kernel
   5          *                                  MUTUAL EXCLUSION SEMAPHORE MANAGEMENT
   6          *
   7          *                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
   8          *                                           All Rights Reserved
   9          *
  10          * File : OS_MUTEX.C
  11          * By   : Jean J. Labrosse
  12          *********************************************************************************************************
  13          */
  14          
  15          #ifndef  OS_MASTER_FILE
  16          #include "includes.h"
  17          #endif
  18          
  19          /*
  20          *********************************************************************************************************
  21          *                                            LOCAL CONSTANTS
  22          *********************************************************************************************************
  23          */
  24          
  25          #define  OS_MUTEX_KEEP_LOWER_8   0x00FF
  26          #define  OS_MUTEX_KEEP_UPPER_8   0xFF00
  27          
  28          #define  OS_MUTEX_AVAILABLE      0x00FF
  29          
  30          
  31          #if OS_MUTEX_EN > 0
  32          /*
  33          *********************************************************************************************************
  34          *                                   ACCEPT MUTUAL EXCLUSION SEMAPHORE
  35          *
  36          * Description: This  function checks the mutual exclusion semaphore to see if a resource is available.
  37          *              Unlike OSMutexPend(), OSMutexAccept() does not suspend the calling task if the resource is
  38          *              not available or the event did not occur.
  39          *
  40          * Arguments  : pevent     is a pointer to the event control block
  41          *
  42          *              err        is a pointer to an error code which will be returned to your application:
  43          *                            OS_NO_ERR          if the call was successful.
  44          *                            OS_ERR_EVENT_TYPE  if 'pevent' is not a pointer to a mutex
  45          *                            OS_ERR_PEVENT_NULL 'pevent' is a NULL pointer
  46          *                            OS_ERR_PEND_ISR     if you called this function from an ISR
  47          *
  48          * Returns    : == 1       if the resource is available, the mutual exclusion semaphore is acquired
  49          *              == 0       a) if the resource is not available
  50          *                         b) you didn't pass a pointer to a mutual exclusion semaphore
  51          *                         c) you called this function from an ISR
  52          *
  53          * Warning(s) : This function CANNOT be called from an ISR because mutual exclusion semaphores are
  54          *              intended to be used by tasks only.
C51 COMPILER V7.06   OS_MUTEX                                                              07/18/2003 11:06:01 PAGE 2   

  55          *********************************************************************************************************
  56          */
  57          
  58          #if OS_MUTEX_ACCEPT_EN > 0
  59          INT8U  OSMutexAccept (OS_EVENT *pevent, INT8U *err) reentrant //using 0
  60          {
  61   1      #if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register     */
  62   1          OS_CPU_SR  cpu_sr;
  63   1      #endif    
  64   1          
  65   1          
  66   1          if (OSIntNesting > 0) {                            /* Make sure it's not called from an ISR        */
  67   2              *err = OS_ERR_PEND_ISR;
  68   2              return (0);
  69   2          }
  70   1      #if OS_ARG_CHK_EN > 0
  71   1          if (pevent == (OS_EVENT *)0) {                     /* Validate 'pevent'                            */
  72   2              *err = OS_ERR_PEVENT_NULL;
  73   2              return (0);
  74   2          }
  75   1      #endif                                                     
  76   1          if (pevent->OSEventType != OS_EVENT_TYPE_MUTEX) {  /* Validate event block type                    */
  77   2              *err = OS_ERR_EVENT_TYPE;
  78   2              return (0);
  79   2          }
  80   1          OS_ENTER_CRITICAL();                                                           /* Get value (0 or 1) of Mutex                  */
  81   1          if ((pevent->OSEventCnt & OS_MUTEX_KEEP_LOWER_8) == OS_MUTEX_AVAILABLE) {     
  82   2              pevent->OSEventCnt &= OS_MUTEX_KEEP_UPPER_8;   /*      Mask off LSByte (Acquire Mutex)         */
  83   2              pevent->OSEventCnt |= OSTCBCur->OSTCBPrio;     /*      Save current task priority in LSByte    */
  84   2              pevent->OSEventPtr  = (void *)OSTCBCur;        /*      Link TCB of task owning Mutex           */
  85   2              OS_EXIT_CRITICAL();
  86   2              *err = OS_NO_ERR;
  87   2              return (1);
  88   2          }
  89   1          OS_EXIT_CRITICAL();
  90   1          *err = OS_NO_ERR;
  91   1          return (0);
  92   1      }
  93          #endif                                                     
  94          
  95          /*$PAGE*/
  96          /*
  97          *********************************************************************************************************
  98          *                                  CREATE A MUTUAL EXCLUSION SEMAPHORE
  99          *
 100          * Description: This function creates a mutual exclusion semaphore.
 101          *
 102          * Arguments  : prio          is the priority to use when accessing the mutual exclusion semaphore.  In
 103          *                            other words, when the semaphore is acquired and a higher priority task
 104          *                            attempts to obtain the semaphore then the priority of the task owning the
 105          *                            semaphore is raised to this priority.  It is assumed that you will specify
 106          *                            a priority that is LOWER in value than ANY of the tasks competing for the
 107          *                            mutex.
 108          *
 109          *              err           is a pointer to an error code which will be returned to your application:
 110          *                               OS_NO_ERR           if the call was successful.
 111          *                               OS_ERR_CREATE_ISR   if you attempted to create a MUTEX from an ISR
 112          *                               OS_PRIO_EXIST       if a task at the priority inheritance priority
 113          *                                                   already exist.
 114          *                               OS_ERR_PEVENT_NULL  No more event control blocks available.
 115          *                               OS_PRIO_INVALID     if the priority you specify is higher that the 
 116          *                                                   maximum allowed (i.e. > OS_LOWEST_PRIO)
C51 COMPILER V7.06   OS_MUTEX                                                              07/18/2003 11:06:01 PAGE 3   

 117          *
 118          * Returns    : != (void *)0  is a pointer to the event control clock (OS_EVENT) associated with the
 119          *                            created mutex.
 120          *              == (void *)0  if an error is detected.
 121          *
 122          * Note(s)    : 1) The LEAST significant 8 bits of '.OSEventCnt' are used to hold the priority number
 123          *                 of the task owning the mutex or 0xFF if no task owns the mutex.
 124          *              2) The MOST  significant 8 bits of '.OSEventCnt' are used to hold the priority number
 125          *                 to use to reduce priority inversion.
 126          *********************************************************************************************************
 127          */
 128          
 129          OS_EVENT  *OSMutexCreate (INT8U prio, INT8U *err) reentrant //using 0
 130          {
 131   1      #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
 132   1          OS_CPU_SR  cpu_sr;
 133   1      #endif    
 134   1          OS_EVENT  *pevent;
 135   1      
 136   1      
 137   1          if (OSIntNesting > 0) {                                /* See if called from ISR ...               */
 138   2              *err = OS_ERR_CREATE_ISR;                          /* ... can't CREATE mutex from an ISR       */
 139   2              return ((OS_EVENT *)0);
 140   2          }
 141   1      #if OS_ARG_CHK_EN > 0
 142   1          if (prio >= OS_LOWEST_PRIO) {                          /* Validate PIP                             */
 143   2              *err = OS_PRIO_INVALID;
 144   2              return ((OS_EVENT *)0);
 145   2          }
 146   1      #endif
 147   1          OS_ENTER_CRITICAL();
 148   1          if (OSTCBPrioTbl[prio] != (OS_TCB *)0) {               /* Mutex priority must not already exist    */
 149   2              OS_EXIT_CRITICAL();                                /* Task already exist at priority ...       */
 150   2              *err = OS_PRIO_EXIST;                              /* ... inheritance priority                 */
 151   2              return ((OS_EVENT *)0);                            
 152   2          }
 153   1          OSTCBPrioTbl[prio] = (OS_TCB *)1;                      /* Reserve the table entry                  */
 154   1          pevent             = OSEventFreeList;                  /* Get next free event control block        */
 155   1          if (pevent == (OS_EVENT *)0) {                         /* See if an ECB was available              */
 156   2              OSTCBPrioTbl[prio] = (OS_TCB *)0;                  /* No, Release the table entry              */
 157   2              OS_EXIT_CRITICAL();
 158   2              *err               = OS_ERR_PEVENT_NULL;           /* No more event control blocks             */
 159   2              return (pevent);
 160   2          }
 161   1          OSEventFreeList     = (OS_EVENT *)OSEventFreeList->OSEventPtr;   /* Adjust the free list           */
 162   1          OS_EXIT_CRITICAL();
 163   1          pevent->OSEventType = OS_EVENT_TYPE_MUTEX;
 164   1          pevent->OSEventCnt  = ((INT16U)prio << 8) | OS_MUTEX_AVAILABLE;  /* Resource is available          */
 165   1          pevent->OSEventPtr  = (void *)0;                                 /* No task owning the mutex       */
 166   1      #if OS_EVENT_NAME_SIZE > 0
 167   1          (void)strcpy(pevent->OSEventName, "?");
 168   1      #endif
 169   1          OS_EventWaitListInit(pevent);
 170   1          *err                = OS_NO_ERR;
 171   1          return (pevent);
 172   1      }
 173          
 174          /*$PAGE*/
 175          /*
 176          *********************************************************************************************************
 177          *                                          DELETE A MUTEX
 178          *
C51 COMPILER V7.06   OS_MUTEX                                                              07/18/2003 11:06:01 PAGE 4   

 179          * Description: This function deletes a mutual exclusion semaphore and readies all tasks pending on the it.
 180          *
 181          * Arguments  : pevent        is a pointer to the event control block associated with the desired mutex.
 182          *
 183          *              opt           determines delete options as follows:
 184          *                            opt == OS_DEL_NO_PEND   Delete mutex ONLY if no task pending
 185          *                            opt == OS_DEL_ALWAYS    Deletes the mutex even if tasks are waiting.
 186          *                                                    In this case, all the tasks pending will be readied.
 187          *

⌨️ 快捷键说明

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