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

📄 os_q.lst

📁 一个关于UCOS的KEIL工程
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V6.23a  OS_Q                                                                  12/09/2004 16:50:26 PAGE 1   


C51 COMPILER V6.23a, COMPILATION OF MODULE OS_Q
OBJECT MODULE PLACED IN OS_Q.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE OS_Q.C LARGE BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                uC/OS-II
   4          *                                          The Real-Time Kernel
   5          *                                        MESSAGE QUEUE MANAGEMENT
   6          *
   7          *                          (c) Copyright 1992-2002, 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 "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
  39          void  *OSQAccept (OS_EVENT *pevent) KCREENTRANT
  40          {
  41   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif
  44   1          void      *msg;
  45   1          OS_Q      *pq;
  46   1      
  47   1      
  48   1      #if OS_ARG_CHK_EN > 0
  49   1          if (pevent == (OS_EVENT *)0) {               /* Validate 'pevent'                                  */
  50   2              return ((void *)0);
  51   2          }
  52   1          if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type                          */
  53   2              return ((void *)0);
  54   2          }
  55   1      #endif
C51 COMPILER V6.23a  OS_Q                                                                  12/09/2004 16:50:26 PAGE 2   

  56   1          OS_ENTER_CRITICAL();
  57   1          pq = (OS_Q *)pevent->OSEventPtr;             /* Point at queue control block                       */
  58   1          if (pq->OSQEntries > 0) {                    /* See if any messages in the queue                   */
  59   2              msg = *pq->OSQOut++;                     /* Yes, extract oldest message from the queue         */
  60   2              pq->OSQEntries--;                        /* Update the number of entries in the queue          */
  61   2              if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end of the queue */
  62   3                  pq->OSQOut = pq->OSQStart;
  63   3              }
  64   2          } else {
  65   2              msg = (void *)0;                         /* Queue is empty                                     */
  66   2          }
  67   1          OS_EXIT_CRITICAL();
  68   1          return (msg);                                /* Return message received (or NULL)                  */
  69   1      }
  70          #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) KCREENTRANT
  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();
 111   2              pq = OSQFreeList;                        /* Get a free queue control block                     */
 112   2              if (pq != (OS_Q *)0) {                   /* Were we able to get a queue control block ?        */
 113   3                  OSQFreeList         = OSQFreeList->OSQPtr;    /* Yes, Adjust free list pointer to next free*/
 114   3                  OS_EXIT_CRITICAL();
 115   3                  pq->OSQStart        = start;                  /*      Initialize the queue                 */
 116   3                  pq->OSQEnd          = &start[size];
 117   3                  pq->OSQIn           = start;
C51 COMPILER V6.23a  OS_Q                                                                  12/09/2004 16:50:26 PAGE 3   

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

⌨️ 快捷键说明

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