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

📄 os_q.ls1

📁 uCOS-II_2.52在51上的移植程序
💻 LS1
📖 第 1 页 / 共 5 页
字号:
                     160     ; OS_EVENT  *OSQCreate (void **start, INT16U size)
                     161     ; {
                     162     ; 
                     163     ;     OS_EVENT  *pevent;
                     164     ;     OS_Q      *pq;
                     165     ; 
A51 MACRO ASSEMBLER  OS_Q                                                                 08/08/2005 11:36:51 PAGE     4

                     166     ; 
                     167     ;     if (OSIntNesting > 0) {                      /* See if called from ISR ...           
                                           */
                     168     ;         return ((OS_EVENT *)0);                  /* ... can't CREATE from an ISR         
                                           */
                     169     ;     }
                     170     ;     OS_ENTER_CRITICAL();
                     171     ;     pevent = OSEventFreeList;                    /* Get next free event control block    
                                           */
                     172     ;     if (OSEventFreeList != (OS_EVENT *)0) {      /* See if pool of free ECB pool was empt
                             y             */
                     173     ;         OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
                     174     ;     }
                     175     ;     OS_EXIT_CRITICAL();
                     176     ;     if (pevent != (OS_EVENT *)0) {               /* See if we have an event control block
                                           */
                     177     ;         OS_ENTER_CRITICAL();
                     178     ;         pq = OSQFreeList;                        /* Get a free queue control block       
                                           */
                     179     ;         if (pq != (OS_Q *)0) {                   /* Were we able to get a queue control b
                             lock ?        */
                     180     ;             OSQFreeList         = OSQFreeList->OSQPtr;    /* Yes, Adjust free list pointe
                             r to next free*/
                     181     ;             OS_EXIT_CRITICAL();
                     182     ;             pq->OSQStart        = start;                  /*      Initialize the queue   
                                           */
                     183     ;             pq->OSQEnd          = &start[size];
                     184     ;             pq->OSQIn           = start;
                     185     ;             pq->OSQOut          = start;
                     186     ;             pq->OSQSize         = size;
                     187     ;             pq->OSQEntries      = 0;
                     188     ;             pevent->OSEventType = OS_EVENT_TYPE_Q;
                     189     ;             pevent->OSEventCnt  = 0;
                     190     ;             pevent->OSEventPtr  = pq;
                     191     ;             OS_EventWaitListInit(pevent);                 /*      Initalize the wait list
                                           */
                     192     ;         } else {
                     193     ;             pevent->OSEventPtr = (void *)OSEventFreeList; /* No,  Return event control bl
                             ock on error  */
                     194     ;             OSEventFreeList    = pevent;
                     195     ;             OS_EXIT_CRITICAL();
                     196     ;             pevent = (OS_EVENT *)0;
                     197     ;         }
                     198     ;     }
                     199     ;     return (pevent);
                     200     ; }
                     201     ; /*$PAGE*/
                     202     ; /*
                     203     ; *****************************************************************************************
                             ****************
                     204     ; *                                        DELETE A MESSAGE QUEUE
                     205     ; *
                     206     ; * Description: This function deletes a message queue and readies all tasks pending on the
                              queue.
                     207     ; *
                     208     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired
                     209     ; *                            queue.
                     210     ; *
                     211     ; *              opt           determines delete options as follows:
                     212     ; *                            opt == OS_DEL_NO_PEND   Delete the queue ONLY if no task pen
                             ding
                     213     ; *                            opt == OS_DEL_ALWAYS    Deletes the queue even if tasks are 
                             waiting.
                     214     ; *                                                    In this case, all the tasks pending 
                             will be readied.
A51 MACRO ASSEMBLER  OS_Q                                                                 08/08/2005 11:36:51 PAGE     5

                     215     ; *
                     216     ; *              err           is a pointer to an error code that can contain one of the fo
                             llowing values:
                     217     ; *                            OS_NO_ERR               The call was successful and the queu
                             e was deleted
                     218     ; *                            OS_ERR_DEL_ISR          If you tried to delete the queue fro
                             m an ISR
                     219     ; *                            OS_ERR_INVALID_OPT      An invalid option was specified
                     220     ; *                            OS_ERR_TASK_WAITING     One or more tasks were waiting on th
                             e queue
                     221     ; *                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a qu
                             eue
                     222     ; *                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
                     223     ; *
                     224     ; * Returns    : pevent        upon error
                     225     ; *              (OS_EVENT *)0 if the queue was successfully deleted.
                     226     ; *
                     227     ; * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect
                              the presence of
                     228     ; *                 the queue MUST check the return code of OSQPend().
                     229     ; *              2) OSQAccept() callers will not know that the intended queue has been dele
                             ted unless
                     230     ; *                 they check 'pevent' to see that it's a NULL pointer.
                     231     ; *              3) This call can potentially disable interrupts for a long time.  The inte
                             rrupt disable
                     232     ; *                 time is directly proportional to the number of tasks waiting on the que
                             ue.
                     233     ; *              4) Because ALL tasks pending on the queue will be readied, you MUST be car
                             eful in
                     234     ; *                 applications where the queue is used for mutual exclusion because the r
                             esource(s)
                     235     ; *                 will no longer be guarded by the queue.
                     236     ; *              5) If the storage for the message queue was allocated dynamically (i.e. us
                             ing a malloc()
                     237     ; *                 type call) then your application MUST release the memory storage by cal
                             l the counterpart
                     238     ; *                 call of the dynamic allocation scheme used.  If the queue storage was c
                             reated statically
                     239     ; *                 then, the storage can be reused.
                     240     ; *****************************************************************************************
                             ****************
                     241     ; */
                     242     ; 
                     243     ; #if OS_Q_DEL_EN > 0
                     244     ; OS_EVENT  *OSQDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
                     245     ; {
                     246     ; 
                     247     ;     BOOLEAN    tasks_waiting;
                     248     ;     OS_Q      *pq;
                     249     ; 
                     250     ; 
                     251     ;     if (OSIntNesting > 0) {                                /* See if called from ISR ... 
                                           */
                     252     ;         *err = OS_ERR_DEL_ISR;                             /* ... can't DELETE from an IS
                             R             */
                     253     ;         return ((OS_EVENT *)0);
                     254     ;     }
                     255     ; #if OS_ARG_CHK_EN > 0
                     256     ;     if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'          
                                           */
                     257     ;         *err = OS_ERR_PEVENT_NULL;
                     258     ;         return (pevent);
                     259     ;     }
                     260     ;     if (pevent->OSEventType != OS_EVENT_TYPE_Q) {          /* Validate event block type  
                                           */
                     261     ;         *err = OS_ERR_EVENT_TYPE;
A51 MACRO ASSEMBLER  OS_Q                                                                 08/08/2005 11:36:51 PAGE     6

                     262     ;         return (pevent);
                     263     ;     }
                     264     ; #endif
                     265     ;     OS_ENTER_CRITICAL();
                     266     ;     if (pevent->OSEventGrp != 0x00) {                      /* See if any tasks waiting on
                              queue        */
                     267     ;         tasks_waiting = TRUE;                              /* Yes                        
                                           */
                     268     ;     } else {
                     269     ;         tasks_waiting = FALSE;                             /* No                         
                                           */
                     270     ;     }
                     271     ;     switch (opt) {
                     272     ;         case OS_DEL_NO_PEND:                               /* Delete queue only if no tas
                             k waiting     */
                     273     ;              if (tasks_waiting == FALSE) {
                     274     ;                  pq                  = (OS_Q *)pevent->OSEventPtr;  /* Return OS_Q to fre
                             e list        */
                     275     ;                  pq->OSQPtr          = OSQFreeList;
                     276     ;                  OSQFreeList         = pq;
                     277     ;                  pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
                     278     ;                  pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block 
                             to free list  */
                     279     ;                  OSEventFreeList     = pevent;             /* Get next free event control
                              block        */
                     280     ;                  OS_EXIT_CRITICAL();
                     281     ;                  *err = OS_NO_ERR;
                     282     ;                  return ((OS_EVENT *)0);                   /* Queue has been deleted     
                                           */
                     283     ;              } else {
                     284     ;                  OS_EXIT_CRITICAL();
                     285     ;                  *err = OS_ERR_TASK_WAITING;
                     286     ;                  return (pevent);
                     287     ;              }
                     288     ; 
                     289     ;         case OS_DEL_ALWAYS:                                /* Always delete the queue    
                                           */
                     290     ;              while (pevent->OSEventGrp != 0x00) {          /* Ready ALL tasks waiting for
                              queue        */
                     291     ;                  OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q);
                     292     ;              }
                     293     ;              pq                  = (OS_Q *)pevent->OSEventPtr;      /* Return OS_Q to fre
                             e list        */
                     294     ;              pq->OSQPtr          = OSQFreeList;
                     295     ;              OSQFreeList         = pq;
                     296     ;              pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
                     297     ;              pevent->OSEventPtr  = OSEventFreeList;        /* Return Event Control Block 
                             to free list  */
                     298     ;              OSEventFreeList     = pevent;                 /* Get next free event control
                              block        */
                     299     ;              OS_EXIT_CRITICAL();
                     300     ;              if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) 
                             were waiting  */

⌨️ 快捷键说明

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