os_q.ls1

来自「在51单片机上移植成功的UCOS-II操作系统源代码,包括源代码及相关注释」· LS1 代码 · 共 740 行 · 第 1/4 页

LS1
740
字号
                                           */
                     149     ;         msg = *pq->OSQOut++;                     /* Yes, extract oldest message from the 
                             queue         */
                     150     ;         pq->OSQEntries--;                        /* Update the number of entries in the q
                             ueue          */
                     151     ;         if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end
                              of the queue */
                     152     ;             pq->OSQOut = pq->OSQStart;
                     153     ;         }
                     154     ;     } else {
                     155     ;         msg = (void *)0;                         /* Queue is empty                       
                                           */
                     156     ;     }
                     157     ;     OS_EXIT_CRITICAL();
                     158     ;     return (msg);                                /* Return message received (or NULL)    
                                           */
                     159     ; }
                     160     ; /*$PAGE*/
A51 MACRO ASSEMBLER  OS_Q                                                                 09/09/2007 21:12:59 PAGE     4

                     161     ; /*
                     162     ; *****************************************************************************************
                             ****************
                     163     ; *                                        CREATE A MESSAGE QUEUE
                     164     ; *
                     165     ; * Description: This function creates a message queue if free event control blocks are ava
                             ilable.
                     166     ; *
                     167     ; * Arguments  : start         is a pointer to the base address of the message queue storag
                             e area.  The
                     168     ; *                            storage area MUST be declared as an array of pointers to 'vo
                             id' as follows
                     169     ; *
                     170     ; *                            void *MessageStorage[size]
                     171     ; *
                     172     ; *              size          is the number of elements in the storage area
                     173     ; *
                     174     ; * Returns    : != (void *)0  is a pointer to the event control clock (OS_EVENT) associate
                             d with the
                     175     ; *                            created queue
                     176     ; *              == (void *)0  if no event control blocks were available
                     177     ; *****************************************************************************************
                             ****************
                     178     ; */
                     179     ; 
                     180     ; OS_EVENT *OSQCreate (void **start, INT16U size) reentrant
                     181     ; {
                     182     ;     OS_EVENT *pevent;
                     183     ;     OS_Q     *pq;
                     184     ; 
                     185     ; 
                     186     ;     OS_ENTER_CRITICAL();
                     187     ;     pevent = OSEventFreeList;                    /* Get next free event control block    
                                           */
                     188     ;     if (OSEventFreeList != (OS_EVENT *)0) {      /* See if pool of free ECB pool was empt
                             y             */
                     189     ;         OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
                     190     ;     }
                     191     ;     OS_EXIT_CRITICAL();
                     192     ;     if (pevent != (OS_EVENT *)0) {               /* See if we have an event control block
                                           */
                     193     ;         OS_ENTER_CRITICAL();                     /* Get a free queue control block       
                                           */
                     194     ;         pq = OSQFreeList;
                     195     ;         if (OSQFreeList != (OS_Q *)0) {
                     196     ;             OSQFreeList = OSQFreeList->OSQPtr;
                     197     ;         }
                     198     ;         OS_EXIT_CRITICAL();
                     199     ;         if (pq != (OS_Q *)0) {                   /* See if we were able to get a queue co
                             ntrol block   */
                     200     ;             pq->OSQStart        = start;         /* Yes, initialize the queue            
                                           */
                     201     ;             pq->OSQEnd          = &start[size];
                     202     ;             pq->OSQIn           = start;
                     203     ;             pq->OSQOut          = start;
                     204     ;             pq->OSQSize         = size;
                     205     ;             pq->OSQEntries      = 0;
                     206     ;             pevent->OSEventType = OS_EVENT_TYPE_Q;
                     207     ;             pevent->OSEventPtr  = pq;
                     208     ;             OSEventWaitListInit(pevent);
                     209     ;         } else {                                 /* No,  since we couldn't get a queue co
                             ntrol block   */
                     210     ;             OS_ENTER_CRITICAL();                 /* Return event control block on error  
                                           */
                     211     ;             pevent->OSEventPtr = (void *)OSEventFreeList;
                     212     ;             OSEventFreeList    = pevent;
A51 MACRO ASSEMBLER  OS_Q                                                                 09/09/2007 21:12:59 PAGE     5

                     213     ;             OS_EXIT_CRITICAL();
                     214     ;             pevent = (OS_EVENT *)0;
                     215     ;         }
                     216     ;     }
                     217     ;     return (pevent);
                     218     ; }
                     219     ; /*$PAGE*/
                     220     ; /*
                     221     ; *****************************************************************************************
                             ****************
                     222     ; *                                           FLUSH QUEUE
                     223     ; *
                     224     ; * Description : This function is used to flush the contents of the message queue.
                     225     ; *
                     226     ; * Arguments   : none
                     227     ; *
                     228     ; * Returns     : OS_NO_ERR          upon success
                     229     ; *               OS_ERR_EVENT_TYPE  If you didn't pass a pointer to a queue
                     230     ; *****************************************************************************************
                             ****************
                     231     ; */
                     232     ; 
                     233     ; INT8U OSQFlush (OS_EVENT *pevent) reentrant
                     234     ; {
                     235     ;     OS_Q  *pq;
                     236     ;     
                     237     ; 
                     238     ;     OS_ENTER_CRITICAL();
                     239     ;     if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type       
                                           */
                     240     ;         OS_EXIT_CRITICAL();
                     241     ;         return (OS_ERR_EVENT_TYPE);
                     242     ;     }
                     243     ;     pq             = pevent->OSEventPtr;              /* Point to queue storage structure
                                           */
                     244     ;     pq->OSQIn      = pq->OSQStart;
                     245     ;     pq->OSQOut     = pq->OSQStart;
                     246     ;     pq->OSQEntries = 0;
                     247     ;     OS_EXIT_CRITICAL();
                     248     ;     return (OS_NO_ERR);
                     249     ; }
                     250     ; 
                     251     ; /*$PAGE*/
                     252     ; /*
                     253     ; *****************************************************************************************
                             ****************
                     254     ; *                                      QUEUE MODULE INITIALIZATION
                     255     ; *
                     256     ; * Description : This function is called by uC/OS-II to initialize the message queue modul
                             e.  Your
                     257     ; *               application MUST NOT call this function.
                     258     ; *
                     259     ; * Arguments   :  none
                     260     ; *
                     261     ; * Returns     : none
                     262     ; *****************************************************************************************
                             ****************
                     263     ; */
                     264     ; 
                     265     ; void OSQInit (void) reentrant
                     266     ; {
                     267     ;     INT16U i;
                     268     ; 
                     269     ; 
                     270     ;     for (i = 0; i < (OS_MAX_QS - 1); i++) {      /* Init. list of free QUEUE control bloc
                             ks            */
A51 MACRO ASSEMBLER  OS_Q                                                                 09/09/2007 21:12:59 PAGE     6

                     271     ;         OSQTbl[i].OSQPtr = &OSQTbl[i+1];
                     272     ;     }
                     273     ;     OSQTbl[OS_MAX_QS - 1].OSQPtr = (OS_Q *)0;
                     274     ;     OSQFreeList                  = &OSQTbl[0];
                     275     ; }
                     276     ; 
                     277     ; /*$PAGE*/
                     278     ; /*
                     279     ; *****************************************************************************************
                             ****************
                     280     ; *                                     PEND ON A QUEUE FOR A MESSAGE
                     281     ; *
                     282     ; * Description: This function waits for a message to be sent to a queue
                     283     ; *
                     284     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired queue
                     285     ; *
                     286     ; *              timeout       is an optional timeout period (in clock ticks).  If non-zero
                             , your task will
                     287     ; *                            wait for a message to arrive at the queue up to the amount o
                             f time 
                     288     ; *                            specified by this argument.  If you specify 0, however, your
                              task will wait 
                     289     ; *                            forever at the specified queue or, until a message arrives.
                     290     ; *
                     291     ; *              err           is a pointer to where an error message will be deposited.  P
                             ossible error
                     292     ; *                            messages are:
                     293     ; *

⌨️ 快捷键说明

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