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

📄 os_mbox.ls1

📁 uCOS-II_2.52在51上的移植程序
💻 LS1
📖 第 1 页 / 共 4 页
字号:
                             k             */
                     165     ;         OS_EventWaitListInit(pevent);
                     166     ;     }
A51 MACRO ASSEMBLER  OS_MBOX                                                              08/08/2005 11:36:44 PAGE     4

                     167     ;     return (pevent);                             /* Return pointer to event control block
                                           */
                     168     ; }
                     169     ; /*$PAGE*/
                     170     ; /*
                     171     ; *****************************************************************************************
                             ****************
                     172     ; *                                         DELETE A MAIBOX
                     173     ; *
                     174     ; * Description: This function deletes a mailbox and readies all tasks pending on the mailb
                             ox.
                     175     ; *
                     176     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired
                     177     ; *                            mailbox.
                     178     ; *
                     179     ; *              opt           determines delete options as follows:
                     180     ; *                            opt == OS_DEL_NO_PEND   Delete the mailbox ONLY if no task p
                             ending
                     181     ; *                            opt == OS_DEL_ALWAYS    Deletes the mailbox even if tasks ar
                             e waiting.
                     182     ; *                                                    In this case, all the tasks pending 
                             will be readied.
                     183     ; *
                     184     ; *              err           is a pointer to an error code that can contain one of the fo
                             llowing values:
                     185     ; *                            OS_NO_ERR               The call was successful and the mail
                             box was deleted
                     186     ; *                            OS_ERR_DEL_ISR          If you attempted to delete the mailb
                             ox from an ISR
                     187     ; *                            OS_ERR_INVALID_OPT      An invalid option was specified
                     188     ; *                            OS_ERR_TASK_WAITING     One or more tasks were waiting on th
                             e mailbox
                     189     ; *                            OS_ERR_EVENT_TYPE       If you didn't pass a pointer to a ma
                             ilbox
                     190     ; *                            OS_ERR_PEVENT_NULL      If 'pevent' is a NULL pointer.
                     191     ; *
                     192     ; * Returns    : pevent        upon error
                     193     ; *              (OS_EVENT *)0 if the mailbox was successfully deleted.
                     194     ; *
                     195     ; * Note(s)    : 1) This function must be used with care.  Tasks that would normally expect
                              the presence of
                     196     ; *                 the mailbox MUST check the return code of OSMboxPend().
                     197     ; *              2) OSMboxAccept() callers will not know that the intended mailbox has been
                              deleted!
                     198     ; *              3) This call can potentially disable interrupts for a long time.  The inte
                             rrupt disable
                     199     ; *                 time is directly proportional to the number of tasks waiting on the mai
                             lbox.
                     200     ; *              4) Because ALL tasks pending on the mailbox will be readied, you MUST be c
                             areful in
                     201     ; *                 applications where the mailbox is used for mutual exclusion because the
                              resource(s)
                     202     ; *                 will no longer be guarded by the mailbox.
                     203     ; *****************************************************************************************
                             ****************
                     204     ; */
                     205     ; 
                     206     ; #if OS_MBOX_DEL_EN > 0
                     207     ; OS_EVENT  *OSMboxDel (OS_EVENT *pevent, INT8U opt, INT8U *err)
                     208     ; {
                     209     ;    
                     210     ;     BOOLEAN    tasks_waiting;
                     211     ; 
                     212     ; 
                     213     ;     if (OSIntNesting > 0) {                                /* See if called from ISR ... 
A51 MACRO ASSEMBLER  OS_MBOX                                                              08/08/2005 11:36:44 PAGE     5

                                           */
                     214     ;         *err = OS_ERR_DEL_ISR;                             /* ... can't DELETE from an IS
                             R             */
                     215     ;         return (pevent);
                     216     ;     }
                     217     ; #if OS_ARG_CHK_EN > 0
                     218     ;     if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'          
                                           */
                     219     ;         *err = OS_ERR_PEVENT_NULL;
                     220     ;         return (pevent);
                     221     ;     }
                     222     ;     if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {       /* Validate event block type  
                                           */
                     223     ;         *err = OS_ERR_EVENT_TYPE;
                     224     ;         return (pevent);
                     225     ;     }
                     226     ; #endif
                     227     ;     OS_ENTER_CRITICAL();
                     228     ;     if (pevent->OSEventGrp != 0x00) {                      /* See if any tasks waiting on
                              mailbox      */
                     229     ;         tasks_waiting = TRUE;                              /* Yes                        
                                           */
                     230     ;     } else {
                     231     ;         tasks_waiting = FALSE;                             /* No                         
                                           */
                     232     ;     }
                     233     ;     switch (opt) {
                     234     ;         case OS_DEL_NO_PEND:                               /* Delete mailbox only if no t
                             ask waiting   */
                     235     ;              if (tasks_waiting == FALSE) {
                     236     ;                  pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
                     237     ;                  pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block 
                             to free list  */
                     238     ;                  OSEventFreeList     = pevent;             /* Get next free event control
                              block        */
                     239     ;                  OS_EXIT_CRITICAL();
                     240     ;                  *err = OS_NO_ERR;
                     241     ;                  return ((OS_EVENT *)0);                   /* Mailbox has been deleted   
                                           */
                     242     ;              } else {
                     243     ;                  OS_EXIT_CRITICAL();
                     244     ;                  *err = OS_ERR_TASK_WAITING;
                     245     ;                  return (pevent);
                     246     ;              }
                     247     ; 
                     248     ;         case OS_DEL_ALWAYS:                                /* Always delete the mailbox  
                                           */
                     249     ;              while (pevent->OSEventGrp != 0x00) {          /* Ready ALL tasks waiting for
                              mailbox      */
                     250     ;                  OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX);
                     251     ;              }
                     252     ;              pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
                     253     ;              pevent->OSEventPtr  = OSEventFreeList;        /* Return Event Control Block 
                             to free list  */
                     254     ;              OSEventFreeList     = pevent;                 /* Get next free event control
                              block        */
                     255     ;              OS_EXIT_CRITICAL();
                     256     ;              if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) 
                             were waiting  */
                     257     ;                  OS_Sched();                               /* Find highest priority task 
                             ready to run  */
                     258     ;              }
                     259     ;              *err = OS_NO_ERR;
                     260     ;              return ((OS_EVENT *)0);                       /* Mailbox has been deleted   
                                           */
                     261     ; 
A51 MACRO ASSEMBLER  OS_MBOX                                                              08/08/2005 11:36:44 PAGE     6

                     262     ;         default:
                     263     ;              OS_EXIT_CRITICAL();
                     264     ;              *err = OS_ERR_INVALID_OPT;
                     265     ;              return (pevent);
                     266     ;     }
                     267     ; }
                     268     ; #endif
                     269     ; 
                     270     ; /*$PAGE*/
                     271     ; /*
                     272     ; *****************************************************************************************
                             ****************
                     273     ; *                                      PEND ON MAILBOX FOR A MESSAGE
                     274     ; *
                     275     ; * Description: This function waits for a message to be sent to a mailbox
                     276     ; *
                     277     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired mailbox
                     278     ; *
                     279     ; *              timeout       is an optional timeout period (in clock ticks).  If non-zero
                             , your task will
                     280     ; *                            wait for a message to arrive at the mailbox up to the amount
                              of time
                     281     ; *                            specified by this argument.  If you specify 0, however, your
                              task will wait
                     282     ; *                            forever at the specified mailbox or, until a message arrives
                             .
                     283     ; *
                     284     ; *              err           is a pointer to where an error message will be deposited.  P
                             ossible error
                     285     ; *                            messages are:
                     286     ; *
                     287     ; *                            OS_NO_ERR           The call was successful and your task re
                             ceived a
                     288     ; *                                                message.
                     289     ; *                            OS_TIMEOUT          A message was not received within the sp
                             ecified timeout
                     290     ; *                            OS_ERR_EVENT_TYPE   Invalid event type
                     291     ; *                            OS_ERR_PEND_ISR     If you called this function from an ISR 
                             and the result
                     292     ; *                                                would lead to a suspension.
                     293     ; *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
                     294     ; *
                     295     ; * Returns    : != (void *)0  is a pointer to the message received
                     296     ; *              == (void *)0  if no message was received or,
                     297     ; *                            if 'pevent' is a NULL pointer or,
                     298     ; *                            if you didn't pass the proper pointer to the event control b
                             lock.
                     299     ; *****************************************************************************************
                             ****************
                     300     ; */
                     301     ; 
                     302     ; void  *OSMboxPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)
                     303     ; {
                     304     ;    
                     305     ;     void      *msg;
                     306     ; 
                     307     ; 
                     308     ;     if (OSIntNesting > 0) {                           /* See if called from ISR ...      

⌨️ 快捷键说明

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