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

📄 os_mbox.ls1

📁 本文面向首次接触uC/OS-II的程序员
💻 LS1
📖 第 1 页 / 共 4 页
字号:
                     358     ;     void      *msg;
                     359     ; 
                     360     ; 
                     361     ;     if (OSIntNesting > 0) {                           /* See if called from ISR ...      
                                           */
                     362     ;         *err = OS_ERR_PEND_ISR;                       /* ... can't PEND from an ISR      
                                           */
                     363     ;         return ((void *)0);
                     364     ;     }
                     365     ; #if OS_ARG_CHK_EN > 0
                     366     ;     if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'               
                                           */
                     367     ;         *err = OS_ERR_PEVENT_NULL;
                     368     ;         return ((void *)0);
                     369     ;     }
                     370     ;     if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type       
                                           */
                     371     ;         *err = OS_ERR_EVENT_TYPE;
                     372     ;         return ((void *)0);
A51 MACRO ASSEMBLER  OS_MBOX                                                              05/17/2005 11:19:54 PAGE     8

                     373     ;     }
                     374     ; #endif
                     375     ;     OS_ENTER_CRITICAL();
                     376     ;     msg = pevent->OSEventPtr;
                     377     ;     if (msg != (void *)0) {                           /* See if there is already a messag
                             e             */
                     378     ;         pevent->OSEventPtr = (void *)0;               /* Clear the mailbox               
                                           */
                     379     ;         OS_EXIT_CRITICAL();
                     380     ;         *err = OS_NO_ERR;
                     381     ;         return (msg);                                 /* Return the message received (or 
                             NULL)         */
                     382     ;     }
                     383     ;     OSTCBCur->OSTCBStat |= OS_STAT_MBOX;              /* Message not available, task will
                              pend         */
                     384     ;     OSTCBCur->OSTCBDly   = timeout;                   /* Load timeout in TCB             
                                           */
                     385     ;     OS_EventTaskWait(pevent);                         /* Suspend task until event or time
                             out occurs    */
                     386     ;     OS_EXIT_CRITICAL();
                     387     ;     OS_Sched();                                       /* Find next highest priority task 
                             ready to run  */
                     388     ;     OS_ENTER_CRITICAL();
                     389     ;     msg = OSTCBCur->OSTCBMsg;
                     390     ;     if (msg != (void *)0) {                           /* See if we were given the message
                                           */
                     391     ;         OSTCBCur->OSTCBMsg      = (void *)0;          /* Yes, clear message received     
                                           */
                     392     ;         OSTCBCur->OSTCBStat     = OS_STAT_RDY;
                     393     ;         OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;      /* No longer waiting for event     
                                           */
                     394     ;         OS_EXIT_CRITICAL();
                     395     ;         *err                    = OS_NO_ERR;
                     396     ;         return (msg);                                 /* Return the message received     
                                           */
                     397     ;     }
                     398     ;     OS_EventTO(pevent);                               /* Timed out, Make task ready      
                                           */
                     399     ;     OS_EXIT_CRITICAL();
                     400     ;     *err = OS_TIMEOUT;                                /* Indicate that a timeout occured 
                                           */
                     401     ;     return ((void *)0);                               /* Return a NULL message           
                                           */
                     402     ; }
                     403     ; /*$PAGE*/
                     404     ; /*
                     405     ; *****************************************************************************************
                             ****************
                     406     ; *                                       POST MESSAGE TO A MAILBOX
                     407     ; *
                     408     ; * Description: This function sends a message to a mailbox
                     409     ; *
                     410     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired mailbox
                     411     ; *
                     412     ; *              msg           is a pointer to the message to send.  You MUST NOT send a NU
                             LL pointer.
                     413     ; *
                     414     ; * Returns    : OS_NO_ERR            The call was successful and the message was sent
                     415     ; *              OS_MBOX_FULL         If the mailbox already contains a message.  You can c
                             an only send one
                     416     ; *                                   message at a time and thus, the message MUST be consu
                             med before you
                     417     ; *                                   are allowed to send another one.
                     418     ; *              OS_ERR_EVENT_TYPE    If you are attempting to post to a non mailbox.
                     419     ; *              OS_ERR_PEVENT_NULL   If 'pevent' is a NULL pointer
A51 MACRO ASSEMBLER  OS_MBOX                                                              05/17/2005 11:19:54 PAGE     9

                     420     ; *              OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
                     421     ; *****************************************************************************************
                             ****************
                     422     ; */
                     423     ; 
                     424     ; #if OS_MBOX_POST_EN > 0
                     425     ; INT8U  OSMboxPost (OS_EVENT *pevent, void *msg)LG_REENTRANT
                     426     ; {
                     427     ; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status regis
                             ter           */
                     428     ;     OS_CPU_SR  cpu_sr;
                     429     ; #endif    
                     430     ;     
                     431     ;     
                     432     ; #if OS_ARG_CHK_EN > 0
                     433     ;     if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'               
                                           */
                     434     ;         return (OS_ERR_PEVENT_NULL);
                     435     ;     }
                     436     ;     if (msg == (void *)0) {                           /* Make sure we are not posting a N
                             ULL pointer   */
                     437     ;         return (OS_ERR_POST_NULL_PTR);
                     438     ;     }
                     439     ;     if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type       
                                           */
                     440     ;         return (OS_ERR_EVENT_TYPE);
                     441     ;     }
                     442     ; #endif
                     443     ;     OS_ENTER_CRITICAL();
                     444     ;     if (pevent->OSEventGrp != 0x00) {                 /* See if any task pending on mailb
                             ox            */
                     445     ;         OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX);   /* Ready highest priority task wait
                             ing on event  */
                     446     ;         OS_EXIT_CRITICAL();
                     447     ;         OS_Sched();                                   /* Find highest priority task ready
                              to run       */
                     448     ;         return (OS_NO_ERR);
                     449     ;     }
                     450     ;     if (pevent->OSEventPtr != (void *)0) {            /* Make sure mailbox doesn't alread
                             y have a msg  */
                     451     ;         OS_EXIT_CRITICAL();
                     452     ;         return (OS_MBOX_FULL);
                     453     ;     }
                     454     ;     pevent->OSEventPtr = msg;                         /* Place message in mailbox        
                                           */
                     455     ;     OS_EXIT_CRITICAL();
                     456     ;     return (OS_NO_ERR);
                     457     ; }
                     458     ; #endif
                     459     ; 
                     460     ; /*$PAGE*/
                     461     ; /*
                     462     ; *****************************************************************************************
                             ****************
                     463     ; *                                       POST MESSAGE TO A MAILBOX
                     464     ; *
                     465     ; * Description: This function sends a message to a mailbox
                     466     ; *
                     467     ; * Arguments  : pevent        is a pointer to the event control block associated with the 
                             desired mailbox
                     468     ; *
                     469     ; *              msg           is a pointer to the message to send.  You MUST NOT send a NU
                             LL pointer.
                     470     ; *
                     471     ; *              opt           determines the type of POST performed:
                     472     ; *                            OS_POST_OPT_NONE         POST to a single waiting task 
A51 MACRO ASSEMBLER  OS_MBOX                                                              05/17/2005 11:19:54 PAGE    10

                     473     ; *                                                     (Identical to OSMboxPost())
                     474     ; *                            OS_POST_OPT_BROADCAST    POST to ALL tasks that are waiting 
                             on the mailbox
                     475     ; *
                     476     ; * Returns    : OS_NO_ERR            The call was successful and the message was sent
                     477     ; *              OS_MBOX_FULL         If the mailbox already contains a message.  You can c
                             an only send one
                     478     ; *                                   message at a time and thus, the message MUST be consu
                             med before you
                     479     ; *                                   are allowed to send another one.
                     480     ; *              OS_ERR_EVENT_TYPE    If you are attempting to post to a non mailbox.
                     481     ; *              OS_ERR_PEVENT_NULL   If 'pevent' is a NULL pointer
                     482     ; *              OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
                     483     ; *
                     484     ; * Warning    : Interrupts can be disabled for a long time if you do a 'broadcast'.  In fa
                             ct, the 
                     485     ; *              interrupt disable time is proportional to the number of tasks waiting on t
                             he mailbox.
                     486     ; *****************************************************************************************
                             ****************
                     487     ; */
                     488     ; 
                     489     ; #if OS_MBOX_POST_OPT_EN > 0
                     490     ; INT8U  OSMboxPostOpt (OS_EVENT *pevent, void *msg, INT8U opt)LG_REENTRANT
                     491     ; {
                     492     ; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status regis
                             ter           */
                     493     ;     OS_CPU_SR  cpu_sr;
                     494     ; #endif    
                     495     ;     
                     496     ;     
                     497     ; #if OS_ARG_CHK_EN > 0
                     498     ;     if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'               
                                           */
                     499     ;         return (OS_ERR_PEVENT_NULL);
                     500     ;     }
                     501     ;     if (msg == (void *)0) {                           /* Make sure we are not posting a N
                             ULL pointer   */
                     502     ;         return (OS_ERR_POST_NULL_PTR);
                     503     ;     }
                     504     ;     if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type       
                                           */
                     505     ;         return (OS_ERR_EVENT_TYPE);
                     506     ;     }
                     507     ; #endif
                     508     ;     OS_ENTER_CRITICAL();
                     509     ;     if (pevent->OSEventGrp != 0x00) {                 /* See if any task pending on mailb
                             ox            */
                     510     ;         if ((opt & OS_POST_OPT_BROADCAST) != 0x00) {  /* Do we need to post msg to ALL wa
                             iting tasks ? */
                     511     ;             while (pevent->OSEventGrp != 0x00) {      /* Yes, Post to ALL tasks waiting o
                             n mailbox     */           
                     512     ;                 OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX);    
                     513     ;             }
                     514     ;         } else {
                     515     ;             OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX);    /* No,  Post to HPT waiting on
                              mbox         */
                     516     ;         }
                     517     ;         OS_EXIT_CRITICAL();
                     518     ;         OS_Sched();                                        /* Find highest priority task 
                             ready to run  */
                     519     ;         return (OS_NO_ERR);
                     520     ;     }
                     521     ;     if (pevent->OSEventPtr != (void *)0) {            /* Make sure mailbox doesn't alread
                             y have a msg  */
                     522     ;         OS_EXIT_CRITICAL();
A51 MACRO ASSEMBLER  OS_MBOX                                                              05/17/2005 11:19:54 PAGE    11

                     523     ;         return (OS_MBOX_FULL);
                     524     ;     }
                     525     ;     pevent->OSEventPtr = msg;                         /* Place message in mailbox        

⌨️ 快捷键说明

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