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

📄 os_q.ls1

📁 UCOS在51上的移植,绝对经典!可以较少开发人员的工作量
💻 LS1
📖 第 1 页 / 共 5 页
字号:
                     171     ;     OS_ENTER_CRITICAL();
                     172     ;     pq = (OS_Q *)pevent->OSEventPtr;             /* Point at queue control block         
                                           */
                     173     ;     if (pq->OSQEntries > 0) {                    /* See if any messages in the queue     
                                           */
                     174     ;         msg = *pq->OSQOut++;                     /* Yes, extract oldest message from the 
                             queue         */
A51 MACRO ASSEMBLER  OS_Q                                                                 05/17/2005 11:19:56 PAGE     4

                     175     ;         pq->OSQEntries--;                        /* Update the number of entries in the q
                             ueue          */
                     176     ;         if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end
                              of the queue */
                     177     ;             pq->OSQOut = pq->OSQStart;
                     178     ;         }
                     179     ;     } else {
                     180     ;         msg = (void *)0;                         /* Queue is empty                       
                                           */
                     181     ;     }
                     182     ;     OS_EXIT_CRITICAL();
                     183     ;     return (msg);                                /* Return message received (or NULL)    
                                           */
                     184     ; }
                     185     ; #endif
                     186     ; /*$PAGE*/
                     187     ; /*
                     188     ; *****************************************************************************************
                             ****************
                     189     ; *                                        CREATE A MESSAGE QUEUE
                     190     ; *
                     191     ; * Description: This function creates a message queue if free event control blocks are ava
                             ilable.
                     192     ; *
                     193     ; * Arguments  : start         is a pointer to the base address of the message queue storag
                             e area.  The
                     194     ; *                            storage area MUST be declared as an array of pointers to 'vo
                             id' as follows
                     195     ; *
                     196     ; *                            void *MessageStorage[size]
                     197     ; *
                     198     ; *              size          is the number of elements in the storage area
                     199     ; *
                     200     ; * Returns    : != (OS_EVENT *)0  is a pointer to the event control clock (OS_EVENT) assoc
                             iated with the
                     201     ; *                                created queue
                     202     ; *              == (OS_EVENT *)0  if no event control blocks were available or an error wa
                             s detected
                     203     ; *****************************************************************************************
                             ****************
                     204     ; */
                     205     ; 
                     206     ; OS_EVENT  *OSQCreate (void **start, INT16U size)LG_REENTRANT
                     207     ; {
                     208     ; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status regis
                             ter           */
                     209     ;     OS_CPU_SR  cpu_sr;
                     210     ; #endif
                     211     ;     OS_EVENT  *pevent;
                     212     ;     OS_Q      *pq;
                     213     ; 
                     214     ; 
                     215     ;     if (OSIntNesting > 0) {                      /* See if called from ISR ...           
                                           */
                     216     ;         return ((OS_EVENT *)0);                  /* ... can't CREATE from an ISR         
                                           */
                     217     ;     }
                     218     ;     OS_ENTER_CRITICAL();
                     219     ;     pevent = OSEventFreeList;                    /* Get next free event control block    
                                           */
                     220     ;     if (OSEventFreeList != (OS_EVENT *)0) {      /* See if pool of free ECB pool was empt
                             y             */
                     221     ;         OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
                     222     ;     }
                     223     ;     OS_EXIT_CRITICAL();
                     224     ;     if (pevent != (OS_EVENT *)0) {               /* See if we have an event control block
A51 MACRO ASSEMBLER  OS_Q                                                                 05/17/2005 11:19:56 PAGE     5

                                           */
                     225     ;         OS_ENTER_CRITICAL();
                     226     ;         pq = OSQFreeList;                        /* Get a free queue control block       
                                           */
                     227     ;         if (pq != (OS_Q *)0) {                   /* Were we able to get a queue control b
                             lock ?        */
                     228     ;             OSQFreeList         = OSQFreeList->OSQPtr;    /* Yes, Adjust free list pointe
                             r to next free*/
                     229     ;             OS_EXIT_CRITICAL();
                     230     ;             pq->OSQStart        = start;                  /*      Initialize the queue   
                                           */
                     231     ;             pq->OSQEnd          = &start[size];
                     232     ;             pq->OSQIn           = start;
                     233     ;             pq->OSQOut          = start;
                     234     ;             pq->OSQSize         = size;
                     235     ;             pq->OSQEntries      = 0;
                     236     ;             pevent->OSEventType = OS_EVENT_TYPE_Q;
                     237     ;             pevent->OSEventCnt  = 0;
                     238     ;             pevent->OSEventPtr  = pq;
                     239     ;             OS_EventWaitListInit(pevent);                 /*      Initalize the wait list
                                           */
                     240     ;         } else {
                     241     ;             pevent->OSEventPtr = (void *)OSEventFreeList; /* No,  Return event control bl
                             ock on error  */
                     242     ;             OSEventFreeList    = pevent;
                     243     ;             OS_EXIT_CRITICAL();
                     244     ;             pevent = (OS_EVENT *)0;
                     245     ;         }
                     246     ;     }
                     247     ;     return (pevent);
                     248     ; }
                     249     ; /*$PAGE*/
                     250     ; /*
                     251     ; *****************************************************************************************
                             ****************
                     252     ; *                                        DELETE A MESSAGE QUEUE
                     253     ; *
                     254     ; * Description: This function deletes a message queue and readies all tasks pending on the
                              queue.
                     255     ; *
                     256     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired
                     257     ; *                            queue.
                     258     ; *
                     259     ; *              opt           determines delete options as follows:
                     260     ; *                            opt == OS_DEL_NO_PEND   Delete the queue ONLY if no task pen
                             ding
                     261     ; *                            opt == OS_DEL_ALWAYS    Deletes the queue even if tasks are 
                             waiting.
                     262     ; *                                                    In this case, all the tasks pending 
                             will be readied.
                     263     ; *
                     264     ; *              err           is a pointer to an error code that can contain one of the fo
                             llowing values:
                     265     ; *                            OS_NO_ERR               The call was successful and the queu
                             e was deleted
                     266     ; *                            OS_ERR_DEL_ISR          If you tried to delete the queue fro
                             m an ISR
                     267     ; *                            OS_ERR_INVALID_OPT      An invalid option was specified
                     268     ; *                            OS_ERR_TASK_WAITING     One or more tasks were waiting on th
                             e queue
                     269     ; *                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a qu
                             eue
                     270     ; *                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
                     271     ; *
                     272     ; * Returns    : pevent        upon error
A51 MACRO ASSEMBLER  OS_Q                                                                 05/17/2005 11:19:56 PAGE     6

                     273     ; *              (OS_EVENT *)0 if the queue was successfully deleted.
                     274     ; *
                     275     ; * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect
                              the presence of
                     276     ; *                 the queue MUST check the return code of OSQPend().
                     277     ; *              2) OSQAccept() callers will not know that the intended queue has been dele
                             ted unless
                     278     ; *                 they check 'pevent' to see that it's a NULL pointer.
                     279     ; *              3) This call can potentially disable interrupts for a long time.  The inte
                             rrupt disable
                     280     ; *                 time is directly proportional to the number of tasks waiting on the que
                             ue.
                     281     ; *              4) Because ALL tasks pending on the queue will be readied, you MUST be car
                             eful in
                     282     ; *                 applications where the queue is used for mutual exclusion because the r
                             esource(s)
                     283     ; *                 will no longer be guarded by the queue.
                     284     ; *              5) If the storage for the message queue was allocated dynamically (i.e. us
                             ing a malloc()
                     285     ; *                 type call) then your application MUST release the memory storage by cal
                             l the counterpart
                     286     ; *                 call of the dynamic allocation scheme used.  If the queue storage was c
                             reated statically
                     287     ; *                 then, the storage can be reused.
                     288     ; *****************************************************************************************
                             ****************
                     289     ; */
                     290     ; 
                     291     ; #if OS_Q_DEL_EN > 0
                     292     ; OS_EVENT  *OSQDel (OS_EVENT *pevent, INT8U opt, INT8U *err)LG_REENTRANT
                     293     ; {
                     294     ; #if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU st
                             atus register */
                     295     ;     OS_CPU_SR  cpu_sr;
                     296     ; #endif
                     297     ;     BOOLEAN    tasks_waiting;
                     298     ;     OS_Q      *pq;
                     299     ; 
                     300     ; 
                     301     ;     if (OSIntNesting > 0) {                                /* See if called from ISR ... 
                                           */
                     302     ;         *err = OS_ERR_DEL_ISR;                             /* ... can't DELETE from an IS
                             R             */
                     303     ;         return ((OS_EVENT *)0);
                     304     ;     }
                     305     ; #if OS_ARG_CHK_EN > 0
                     306     ;     if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'          
                                           */
                     307     ;         *err = OS_ERR_PEVENT_NULL;
                     308     ;         return (pevent);
                     309     ;     }

⌨️ 快捷键说明

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