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

📄 os_q.ls1

📁 UCOS在51上的移植,绝对经典!可以较少开发人员的工作量
💻 LS1
📖 第 1 页 / 共 5 页
字号:
                     462     ;     pq = (OS_Q *)pevent->OSEventPtr;             /* Point at queue control block         
                                           */
                     463     ;     if (pq->OSQEntries > 0) {                    /* See if any messages in the queue     
                                           */
                     464     ;         msg = *pq->OSQOut++;                     /* Yes, extract oldest message from the 
                             queue         */
                     465     ;         pq->OSQEntries--;                        /* Update the number of entries in the q
                             ueue          */
                     466     ;         if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end
                              of the queue */
                     467     ;             pq->OSQOut = pq->OSQStart;
                     468     ;         }
                     469     ;         OS_EXIT_CRITICAL();
                     470     ;         *err = OS_NO_ERR;
                     471     ;         return (msg);                            /* Return message received              
                                           */
                     472     ;     }
                     473     ;     OSTCBCur->OSTCBStat |= OS_STAT_Q;            /* Task will have to pend for a message 
                             to be posted  */
                     474     ;     OSTCBCur->OSTCBDly   = timeout;              /* Load timeout into TCB                
                                           */
                     475     ;     OS_EventTaskWait(pevent);                    /* Suspend task until event or timeout o
                             ccurs         */
A51 MACRO ASSEMBLER  OS_Q                                                                 05/17/2005 11:19:56 PAGE    10

                     476     ;     OS_EXIT_CRITICAL();
                     477     ;     OS_Sched();                                  /* Find next highest priority task ready
                              to run       */
                     478     ;     OS_ENTER_CRITICAL();
                     479     ;     msg = OSTCBCur->OSTCBMsg;
                     480     ;     if (msg != (void *)0) {                      /* Did we get a message?                
                                           */
                     481     ;         OSTCBCur->OSTCBMsg      = (void *)0;     /* Extract message from TCB (Put there b
                             y QPost)      */
                     482     ;         OSTCBCur->OSTCBStat     = OS_STAT_RDY;
                     483     ;         OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event          
                                           */
                     484     ;         OS_EXIT_CRITICAL();
                     485     ;         *err                    = OS_NO_ERR;
                     486     ;         return (msg);                            /* Return message received              
                                           */
                     487     ;     }
                     488     ;     OS_EventTO(pevent);                          /* Timed out                            
                                           */
                     489     ;     OS_EXIT_CRITICAL();
                     490     ;     *err = OS_TIMEOUT;                           /* Indicate a timeout occured           
                                           */
                     491     ;     return ((void *)0);                          /* No message received                  
                                           */
                     492     ; }
                     493     ; /*$PAGE*/
                     494     ; /*
                     495     ; *****************************************************************************************
                             ****************
                     496     ; *                                        POST MESSAGE TO A QUEUE
                     497     ; *
                     498     ; * Description: This function sends a message to a queue
                     499     ; *
                     500     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired queue
                     501     ; *
                     502     ; *              msg           is a pointer to the message to send.  You MUST NOT send a NU
                             LL pointer.
                     503     ; *
                     504     ; * Returns    : OS_NO_ERR             The call was successful and the message was sent
                     505     ; *              OS_Q_FULL             If the queue cannot accept any more messages because
                              it is full.
                     506     ; *              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
                     507     ; *              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
                     508     ; *              OS_ERR_POST_NULL_PTR  If you are attempting to post a NULL pointer
                     509     ; *****************************************************************************************
                             ****************
                     510     ; */
                     511     ; 
                     512     ; #if OS_Q_POST_EN > 0
                     513     ; INT8U  OSQPost (OS_EVENT *pevent, void *msg)LG_REENTRANT
                     514     ; {
                     515     ; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status regis
                             ter           */
                     516     ;     OS_CPU_SR  cpu_sr;
                     517     ; #endif
                     518     ;     OS_Q      *pq;
                     519     ; 
                     520     ; 
                     521     ; #if OS_ARG_CHK_EN > 0
                     522     ;     if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'               
                                           */
                     523     ;         return (OS_ERR_PEVENT_NULL);
                     524     ;     }
                     525     ;     if (msg == (void *)0) {                           /* Make sure we are not posting a N
                             ULL pointer   */
A51 MACRO ASSEMBLER  OS_Q                                                                 05/17/2005 11:19:56 PAGE    11

                     526     ;         return (OS_ERR_POST_NULL_PTR);
                     527     ;     }
                     528     ;     if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type       
                                           */
                     529     ;         return (OS_ERR_EVENT_TYPE);
                     530     ;     }
                     531     ; #endif
                     532     ;     OS_ENTER_CRITICAL();
                     533     ;     if (pevent->OSEventGrp != 0x00) {                 /* See if any task pending on queue
                                           */
                     534     ;         OS_EventTaskRdy(pevent, msg, OS_STAT_Q);      /* Ready highest priority task wait
                             ing on event  */
                     535     ;         OS_EXIT_CRITICAL();
                     536     ;         OS_Sched();                                   /* Find highest priority task ready
                              to run       */
                     537     ;         return (OS_NO_ERR);
                     538     ;     }
                     539     ;     pq = (OS_Q *)pevent->OSEventPtr;                  /* Point to queue control block    
                                           */
                     540     ;     if (pq->OSQEntries >= pq->OSQSize) {              /* Make sure queue is not full     
                                           */
                     541     ;         OS_EXIT_CRITICAL();
                     542     ;         return (OS_Q_FULL);
                     543     ;     }
                     544     ;     *pq->OSQIn++ = msg;                               /* Insert message into queue       
                                           */
                     545     ;     pq->OSQEntries++;                                 /* Update the nbr of entries in the
                              queue        */
                     546     ;     if (pq->OSQIn == pq->OSQEnd) {                    /* Wrap IN ptr if we are at end of 
                             queue         */
                     547     ;         pq->OSQIn = pq->OSQStart;
                     548     ;     }
                     549     ;     OS_EXIT_CRITICAL();
                     550     ;     return (OS_NO_ERR);
                     551     ; }
                     552     ; #endif
                     553     ; /*$PAGE*/
                     554     ; /*
                     555     ; *****************************************************************************************
                             ****************
                     556     ; *                                   POST MESSAGE TO THE FRONT OF A QUEUE
                     557     ; *
                     558     ; * Description: This function sends a message to a queue but unlike OSQPost(), the message
                              is posted at
                     559     ; *              the front instead of the end of the queue.  Using OSQPostFront() allows yo
                             u to send
                     560     ; *              'priority' messages.
                     561     ; *
                     562     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired queue
                     563     ; *
                     564     ; *              msg           is a pointer to the message to send.  You MUST NOT send a NU
                             LL pointer.
                     565     ; *
                     566     ; * Returns    : OS_NO_ERR             The call was successful and the message was sent
                     567     ; *              OS_Q_FULL             If the queue cannot accept any more messages because
                              it is full.
                     568     ; *              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
                     569     ; *              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
                     570     ; *              OS_ERR_POST_NULL_PTR  If you are attempting to post to a non queue.
                     571     ; *****************************************************************************************
                             ****************
                     572     ; */
                     573     ; 
                     574     ; #if OS_Q_POST_FRONT_EN > 0
                     575     ; INT8U  OSQPostFront (OS_EVENT *pevent, void *msg)LG_REENTRANT
A51 MACRO ASSEMBLER  OS_Q                                                                 05/17/2005 11:19:56 PAGE    12

                     576     ; {
                     577     ; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status regis
                             ter           */
                     578     ;     OS_CPU_SR  cpu_sr;
                     579     ; #endif
                     580     ;     OS_Q      *pq;
                     581     ; 
                     582     ; 
                     583     ; #if OS_ARG_CHK_EN > 0
                     584     ;     if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'               
                                           */
                     585     ;         return (OS_ERR_PEVENT_NULL);
                     586     ;     }
                     587     ;     if (msg == (void *)0) {                           /* Make sure we are not posting a N
                             ULL pointer   */
                     588     ;         return (OS_ERR_POST_NULL_PTR);
                     589     ;     }
                     590     ;     if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type       
                                           */
                     591     ;         return (OS_ERR_EVENT_TYPE);
                     592     ;     }
                     593     ; #endif
                     594     ;     OS_ENTER_CRITICAL();
                     595     ;     if (pevent->OSEventGrp != 0x00) {                 /* See if any task pending on queue
                                           */
                     596     ;         OS_EventTaskRdy(pevent, msg, OS_STAT_Q);      /* Ready highest priority task wait
                             ing on event  */
                     597     ;         OS_EXIT_CRITICAL();
                     598     ;         OS_Sched();                                   /* Find highest priority task ready
                              to run       */
                     599     ;         return (OS_NO_ERR);
                     600     ;     }
                     601     ;     pq = (OS_Q *)pevent->OSEventPtr;                  /* Point to queue control block    
                                           */
                     602     ;     if (pq->OSQEntries >= pq->OSQSize) {              /* Make sure queue is not full     

⌨️ 快捷键说明

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