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

📄 os_q.ls1

📁 uCOS-II_2.52在51上的移植程序
💻 LS1
📖 第 1 页 / 共 5 页
字号:
                     301     ;                  OS_Sched();                               /* Find highest priority task 
                             ready to run  */
                     302     ;              }
                     303     ;              *err = OS_NO_ERR;
                     304     ;              return ((OS_EVENT *)0);                       /* Queue has been deleted     
                                           */
                     305     ; 
                     306     ;         default:
                     307     ;              OS_EXIT_CRITICAL();
                     308     ;              *err = OS_ERR_INVALID_OPT;
                     309     ;              return (pevent);
                     310     ;     }
                     311     ; }
A51 MACRO ASSEMBLER  OS_Q                                                                 08/08/2005 11:36:51 PAGE     7

                     312     ; #endif
                     313     ; 
                     314     ; /*$PAGE*/
                     315     ; /*
                     316     ; *****************************************************************************************
                             ****************
                     317     ; *                                           FLUSH QUEUE
                     318     ; *
                     319     ; * Description : This function is used to flush the contents of the message queue.
                     320     ; *
                     321     ; * Arguments   : none
                     322     ; *
                     323     ; * Returns     : OS_NO_ERR           upon success
                     324     ; *               OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a queue
                     325     ; *               OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
                     326     ; *****************************************************************************************
                             ****************
                     327     ; */
                     328     ; 
                     329     ; #if OS_Q_FLUSH_EN > 0
                     330     ; INT8U  OSQFlush (OS_EVENT *pevent)
                     331     ; {
                     332     ; 
                     333     ;     OS_Q      *pq;
                     334     ; 
                     335     ; 
                     336     ; #if OS_ARG_CHK_EN > 0
                     337     ;     if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'               
                                           */
                     338     ;         return (OS_ERR_PEVENT_NULL);
                     339     ;     }
                     340     ;     if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type       
                                           */
                     341     ;         return (OS_ERR_EVENT_TYPE);
                     342     ;     }
                     343     ; #endif
                     344     ;     OS_ENTER_CRITICAL();
                     345     ;     pq             = (OS_Q *)pevent->OSEventPtr;      /* Point to queue storage structure
                                           */
                     346     ;     pq->OSQIn      = pq->OSQStart;
                     347     ;     pq->OSQOut     = pq->OSQStart;
                     348     ;     pq->OSQEntries = 0;
                     349     ;     OS_EXIT_CRITICAL();
                     350     ;     return (OS_NO_ERR);
                     351     ; }
                     352     ; #endif
                     353     ; 
                     354     ; /*$PAGE*/
                     355     ; /*
                     356     ; *****************************************************************************************
                             ****************
                     357     ; *                                     PEND ON A QUEUE FOR A MESSAGE
                     358     ; *
                     359     ; * Description: This function waits for a message to be sent to a queue
                     360     ; *
                     361     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired queue
                     362     ; *
                     363     ; *              timeout       is an optional timeout period (in clock ticks).  If non-zero
                             , your task will
                     364     ; *                            wait for a message to arrive at the queue up to the amount o
                             f time
                     365     ; *                            specified by this argument.  If you specify 0, however, your
                              task will wait
                     366     ; *                            forever at the specified queue or, until a message arrives.
                     367     ; *
A51 MACRO ASSEMBLER  OS_Q                                                                 08/08/2005 11:36:51 PAGE     8

                     368     ; *              err           is a pointer to where an error message will be deposited.  P
                             ossible error
                     369     ; *                            messages are:
                     370     ; *
                     371     ; *                            OS_NO_ERR           The call was successful and your task re
                             ceived a
                     372     ; *                                                message.
                     373     ; *                            OS_TIMEOUT          A message was not received within the sp
                             ecified timeout
                     374     ; *                            OS_ERR_EVENT_TYPE   You didn't pass a pointer to a queue
                     375     ; *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
                     376     ; *                            OS_ERR_PEND_ISR     If you called this function from an ISR 
                             and the result
                     377     ; *                                                would lead to a suspension.
                     378     ; *
                     379     ; * Returns    : != (void *)0  is a pointer to the message received
                     380     ; *              == (void *)0  if no message was received or,
                     381     ; *                            if 'pevent' is a NULL pointer or,
                     382     ; *                            if you didn't pass a pointer to a queue.
                     383     ; *****************************************************************************************
                             ****************
                     384     ; */
                     385     ; 
                     386     ; void  *OSQPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)
                     387     ; {
                     388     ; 
                     389     ;     void      *msg;
                     390     ;     OS_Q      *pq;
                     391     ; 
                     392     ; 
                     393     ;     if (OSIntNesting > 0) {                      /* See if called from ISR ...           
                                           */
                     394     ;         *err = OS_ERR_PEND_ISR;                  /* ... can't PEND from an ISR           
                                           */
                     395     ;         return ((void *)0);
                     396     ;     }
                     397     ; #if OS_ARG_CHK_EN > 0
                     398     ;     if (pevent == (OS_EVENT *)0) {               /* Validate 'pevent'                    
                                           */
                     399     ;         *err = OS_ERR_PEVENT_NULL;
                     400     ;         return ((void *)0);
                     401     ;     }
                     402     ;     if (pevent->OSEventType != OS_EVENT_TYPE_Q) {/* Validate event block type            
                                           */
                     403     ;         *err = OS_ERR_EVENT_TYPE;
                     404     ;         return ((void *)0);
                     405     ;     }
                     406     ; #endif
                     407     ;     OS_ENTER_CRITICAL();
                     408     ;     pq = (OS_Q *)pevent->OSEventPtr;             /* Point at queue control block         
                                           */
                     409     ;     if (pq->OSQEntries > 0) {                    /* See if any messages in the queue     
                                           */
                     410     ;         msg = *pq->OSQOut++;                     /* Yes, extract oldest message from the 
                             queue         */
                     411     ;         pq->OSQEntries--;                        /* Update the number of entries in the q
                             ueue          */
                     412     ;         if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end
                              of the queue */
                     413     ;             pq->OSQOut = pq->OSQStart;
                     414     ;         }
                     415     ;         OS_EXIT_CRITICAL();
                     416     ;         *err = OS_NO_ERR;
                     417     ;         return (msg);                            /* Return message received              
                                           */
                     418     ;     }
A51 MACRO ASSEMBLER  OS_Q                                                                 08/08/2005 11:36:51 PAGE     9

                     419     ;     OSTCBCur->OSTCBStat |= OS_STAT_Q;            /* Task will have to pend for a message 
                             to be posted  */
                     420     ;     OSTCBCur->OSTCBDly   = timeout;              /* Load timeout into TCB                
                                           */
                     421     ;     OS_EventTaskWait(pevent);                    /* Suspend task until event or timeout o
                             ccurs         */
                     422     ;     OS_EXIT_CRITICAL();
                     423     ;     OS_Sched();                                  /* Find next highest priority task ready
                              to run       */
                     424     ;     OS_ENTER_CRITICAL();
                     425     ;     msg = OSTCBCur->OSTCBMsg;
                     426     ;     if (msg != (void *)0) {                      /* Did we get a message?                
                                           */
                     427     ;         OSTCBCur->OSTCBMsg      = (void *)0;     /* Extract message from TCB (Put there b
                             y QPost)      */
                     428     ;         OSTCBCur->OSTCBStat     = OS_STAT_RDY;
                     429     ;         OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event          
                                           */
                     430     ;         OS_EXIT_CRITICAL();
                     431     ;         *err                    = OS_NO_ERR;
                     432     ;         return (msg);                            /* Return message received              
                                           */
                     433     ;     }
                     434     ;     OS_EventTO(pevent);                          /* Timed out                            
                                           */
                     435     ;     OS_EXIT_CRITICAL();
                     436     ;     *err = OS_TIMEOUT;                           /* Indicate a timeout occured           
                                           */
                     437     ;     return ((void *)0);                          /* No message received                  
                                           */
                     438     ; }
                     439     ; /*$PAGE*/
                     440     ; /*
                     441     ; *****************************************************************************************
                             ****************
                     442     ; *                                        POST MESSAGE TO A QUEUE
                     443     ; *
                     444     ; * Description: This function sends a message to a queue
                     445     ; *
                     446     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired queue
                     447     ; *
                     448     ; *              msg           is a pointer to the message to send.  You MUST NOT send a NU
                             LL pointer.
                     449     ; *
                     450     ; * Returns    : OS_NO_ERR             The call was successful and the message was sent

⌨️ 快捷键说明

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