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

📄 os_q.lst

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


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

stmt level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/OS-II
   4          *                                          The Real-Time Kernel
   5          *                                        MESSAGE QUEUE MANAGEMENT
   6          *
   7          *                          (c) Copyright 1992-2001, Jean J. Labrosse, Weston, FL
   8          *                                           All Rights Reserved
   9          *
  10          * File : OS_Q.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_Q_EN > 0) && (OS_MAX_QS > 0)
  20          /*
  21          *********************************************************************************************************
  22          *                                      ACCEPT MESSAGE FROM QUEUE
  23          *
  24          * Description: This function checks the queue to see if a message is available.  Unlike OSQPend(),
  25          *              OSQAccept() does not suspend the calling task if a message is not available.
  26          *
  27          * Arguments  : pevent        is a pointer to the event control block
  28          *
  29          * Returns    : != (void *)0  is the message in the queue if one is available.  The message is removed
  30          *                            from the so the next time OSQAccept() is called, the queue will contain
  31          *                            one less entry.
  32          *              == (void *)0  if the queue is empty or,
  33          *                            if 'pevent' is a NULL pointer or,
  34          *                            if you passed an invalid event type
  35          *********************************************************************************************************
  36          */
  37          
  38          #if OS_Q_ACCEPT_EN > 0
              void  *OSQAccept (OS_EVENT *pevent) reentrant
              {
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif    
                  void      *msg;
                  OS_Q      *pq;
              
              
              #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {               /* Validate 'pevent'                                  */
                      return ((void *)0);
                  }
                  if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type                          */
                      return ((void *)0);
                  }
C51 COMPILER V7.06   OS_Q                                                                  03/05/2008 20:23:54 PAGE 2   

              #endif
                  OS_ENTER_CRITICAL();
                  pq = (OS_Q *)pevent->OSEventPtr;             /* Point at queue control block                       */
                  if (pq->OSQEntries != 0) {                   /* See if any messages in the queue                   */
                      msg = *pq->OSQOut++;                     /* Yes, extract oldest message from the queue         */
                      pq->OSQEntries--;                        /* Update the number of entries in the queue          */
                      if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end of the queue */
                          pq->OSQOut = pq->OSQStart;
                      }
                  } else {
                      msg = (void *)0;                         /* Queue is empty                                     */
                  }
                  OS_EXIT_CRITICAL();
                  return (msg);                                /* Return message received (or NULL)                  */
              }
              #endif
  71          /*$PAGE*/
  72          /*
  73          *********************************************************************************************************
  74          *                                        CREATE A MESSAGE QUEUE
  75          *
  76          * Description: This function creates a message queue if free event control blocks are available.
  77          *
  78          * Arguments  : start         is a pointer to the base address of the message queue storage area.  The
  79          *                            storage area MUST be declared as an array of pointers to 'void' as follows
  80          *
  81          *                            void *MessageStorage[size]
  82          *
  83          *              size          is the number of elements in the storage area
  84          *
  85          * Returns    : != (OS_EVENT *)0  is a pointer to the event control clock (OS_EVENT) associated with the
  86          *                                created queue
  87          *              == (OS_EVENT *)0  if no event control blocks were available or an error was detected
  88          *********************************************************************************************************
  89          */
  90          
  91          OS_EVENT  *OSQCreate (void **start, INT16U size) reentrant
  92          {
  93   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif    
  96   1          OS_EVENT  *pevent;
  97   1          OS_Q      *pq;
  98   1      
  99   1      
 100   1          if (OSIntNesting > 0) {                      /* See if called from ISR ...                         */
 101   2              return ((OS_EVENT *)0);                  /* ... can't CREATE from an ISR                       */
 102   2          }
 103   1          OS_ENTER_CRITICAL();
 104   1          pevent = OSEventFreeList;                    /* Get next free event control block                  */
 105   1          if (OSEventFreeList != (OS_EVENT *)0) {      /* See if pool of free ECB pool was empty             */
 106   2              OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
 107   2          }
 108   1          OS_EXIT_CRITICAL();
 109   1          if (pevent != (OS_EVENT *)0) {               /* See if we have an event control block              */
 110   2              OS_ENTER_CRITICAL();                     /* Get a free queue control block                     */
 111   2              pq = OSQFreeList;
 112   2              if (OSQFreeList != (OS_Q *)0) {
 113   3                  OSQFreeList = OSQFreeList->OSQPtr;
 114   3              }
 115   2              OS_EXIT_CRITICAL();
 116   2              if (pq != (OS_Q *)0) {                   /* See if we were able to get a queue control block   */
C51 COMPILER V7.06   OS_Q                                                                  03/05/2008 20:23:54 PAGE 3   

 117   3                  pq->OSQStart        = start;         /* Yes, initialize the queue                          */
 118   3                  pq->OSQEnd          = &start[size];
 119   3                  pq->OSQIn           = start;
 120   3                  pq->OSQOut          = start;
 121   3                  pq->OSQSize         = size;
 122   3                  pq->OSQEntries      = 0;
 123   3                  pevent->OSEventType = OS_EVENT_TYPE_Q;
 124   3                  pevent->OSEventPtr  = pq;
 125   3                  OS_EventWaitListInit(pevent);
 126   3              } else {                                 /* No,  since we couldn't get a queue control block   */
 127   3                  OS_ENTER_CRITICAL();                 /* Return event control block on error                */
 128   3                  pevent->OSEventPtr = (void *)OSEventFreeList;
 129   3                  OSEventFreeList    = pevent;
 130   3                  OS_EXIT_CRITICAL();
 131   3                  pevent = (OS_EVENT *)0;
 132   3              }
 133   2          }
 134   1          return (pevent);
 135   1      }
 136          /*$PAGE*/
 137          /*
 138          *********************************************************************************************************
 139          *                                        DELETE A MESSAGE QUEUE
 140          *
 141          * Description: This function deletes a message queue and readies all tasks pending on the queue.
 142          *
 143          * Arguments  : pevent        is a pointer to the event control block associated with the desired
 144          *                            queue.
 145          *
 146          *              opt           determines delete options as follows:
 147          *                            opt == OS_DEL_NO_PEND   Delete the queue ONLY if no task pending
 148          *                            opt == OS_DEL_ALWAYS    Deletes the queue even if tasks are waiting.
 149          *                                                    In this case, all the tasks pending will be readied.
 150          *
 151          *              err           is a pointer to an error code that can contain one of the following values:
 152          *                            OS_NO_ERR               The call was successful and the queue was deleted
 153          *                            OS_ERR_DEL_ISR          If you tried to delete the queue from an ISR
 154          *                            OS_ERR_INVALID_OPT      An invalid option was specified
 155          *                            OS_ERR_TASK_WAITING     One or more tasks were waiting on the queue
 156          *                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a queue
 157          *                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
 158          *
 159          * Returns    : pevent        upon error
 160          *              (OS_EVENT *)0 if the queue was successfully deleted.
 161          *
 162          * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect the presence of
 163          *                 the queue MUST check the return code of OSQPend().
 164          *              2) OSQAccept() callers will not know that the intended queue has been deleted unless
 165          *                 they check 'pevent' to see that it's a NULL pointer.
 166          *              3) This call can potentially disable interrupts for a long time.  The interrupt disable
 167          *                 time is directly proportional to the number of tasks waiting on the queue.
 168          *              4) Because ALL tasks pending on the queue will be readied, you MUST be careful in
 169          *                 applications where the queue is used for mutual exclusion because the resource(s)
 170          *                 will no longer be guarded by the queue.
 171          *              5) If the storage for the message queue was allocated dynamically (i.e. using a malloc()
 172          *                 type call) then your application MUST release the memory storage by call the counterpart
 173          *                 call of the dynamic allocation scheme used.  If the queue storage was created statically
 174          *                 then, the storage can be reused.
 175          *********************************************************************************************************
 176          */
 177          
 178          #if OS_Q_DEL_EN > 0
C51 COMPILER V7.06   OS_Q                                                                  03/05/2008 20:23:54 PAGE 4   

              OS_EVENT  *OSQDel (OS_EVENT *pevent, INT8U opt, INT8U *err) reentrant

⌨️ 快捷键说明

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