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

📄 os_mbox.lst

📁 将ucos-II 移植到 KeilC51 的小模式下。由于小模式运行速度比大模式运行速度快很多
💻 LST
📖 第 1 页 / 共 2 页
字号:
                  msg = pevent->OSEventPtr;
                  if (msg != (void DT_XDATA *)0) {                           /* See if there is already a message       
             -      */
                      pevent->OSEventPtr = (void DT_XDATA *)0;               /* Clear the mailbox                       
             -      */
                      OS_EXIT_CRITICAL();
                      *err = OS_NO_ERR;
                  } else if (OSIntNesting > 0) {                    /* See if called from ISR ...                    */
                      OS_EXIT_CRITICAL();                           /* ... can't PEND from an ISR                    */
                      *err = OS_ERR_PEND_ISR;
                  } else {
                      OSTCBCur->OSTCBStat |= OS_STAT_MBOX;          /* Message not available, task will pend         */
                      OSTCBCur->OSTCBDly   = timeout;               /* Load timeout in TCB                           */
                      OSEventTaskWait(pevent);                      /* Suspend task until event or timeout occurs    */
                      OS_EXIT_CRITICAL();
                      OSSched();                                    /* Find next highest priority task ready to run  */
                      OS_ENTER_CRITICAL();
                      if ((msg = OSTCBCur->OSTCBMsg) != (void DT_XDATA *)0) {     /* See if we were given the message   
             -      */
                          OSTCBCur->OSTCBMsg      = (void DT_XDATA *)0;           /* Yes, clear message received        
             -      */
                          OSTCBCur->OSTCBStat     = OS_STAT_RDY;
                          OSTCBCur->OSTCBEventPtr = (OS_EVENT DT_XDATA *)0;       /* No longer waiting for event        
             -      */
                          OS_EXIT_CRITICAL();
                          *err                    = OS_NO_ERR;
                      } else if (OSTCBCur->OSTCBStat & OS_STAT_MBOX) {   /* If status is not OS_STAT_RDY, timed out  */
                          OSEventTO(pevent);                             /* Make task ready                          */
                          OS_EXIT_CRITICAL();
                          msg                     = (void DT_XDATA *)0;           /* Set message contents to NULL       
             -      */
                          *err                    = OS_TIMEOUT;          /* Indicate that a timeout occured          */
                      } else {
                          msg                     = pevent->OSEventPtr;  /* Message received                         */
                          pevent->OSEventPtr      = (void DT_XDATA *)0;           /* Clear the mailbox                  
             -      */
                          OSTCBCur->OSTCBEventPtr = (OS_EVENT DT_XDATA *)0;
                          OS_EXIT_CRITICAL();
                          *err                    = OS_NO_ERR;
                      }
                  }
                  return (msg);                                          /* Return the message received (or NULL)    */
              }
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                       POST MESSAGE TO A MAILBOX
C51 COMPILER V7.06   OS_MBOX                                                               11/20/2008 19:25:23 PAGE 4   

              *
              * Description: This function sends a message to a mailbox
              *
              * Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
              *
              *              msg           is a pointer to the message to send.  You MUST NOT send a NULL pointer.  
              *
              * Returns    : OS_NO_ERR          The call was successful and the message was sent
              *              OS_MBOX_FULL       If the mailbox already contains a message.  You can can only send one
              *                                 message at a time and thus, the message MUST be consumed before you are
              *                                 allowed to send another one.
              *              OS_ERR_EVENT_TYPE  If you are attempting to post to a non mailbox.
              *********************************************************************************************************
              */
              
              INT8U OSMboxPost (OS_EVENT DT_XDATA *pevent, void DT_XDATA *msg) REENTRANT
              {
                  OS_ENTER_CRITICAL();
                  if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type                     */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_EVENT_TYPE);
                  }
                  if (pevent->OSEventGrp) {                         /* See if any task pending on mailbox            */
                      OSEventTaskRdy(pevent, msg, OS_STAT_MBOX);    /* Ready highest priority task waiting on event  */
                      OS_EXIT_CRITICAL();
                      OSSched();                                    /* Find highest priority task ready to run       */
                      return (OS_NO_ERR);
                  } else {
                      if (pevent->OSEventPtr != (void DT_XDATA *)0) {        /* Make sure mailbox doesn't already have a
             - msg  */
                          OS_EXIT_CRITICAL();
                          return (OS_MBOX_FULL);
                      } else {
                          pevent->OSEventPtr = msg;                 /* Place message in mailbox                      */
                          OS_EXIT_CRITICAL();
                          return (OS_NO_ERR);
                      }
                  }
              }
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                        QUERY A MESSAGE MAILBOX
              *
              * Description: This function obtains information about a message mailbox.
              *
              * Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
              *
              *              ppdata         is a pointer to a structure that will contain information about the message
              *                            mailbox.
              *
              * Returns    : OS_NO_ERR          The call was successful and the message was sent
              *              OS_ERR_EVENT_TYPE  If you are attempting to obtain data from a non mailbox.
              *********************************************************************************************************
              */
              
              INT8U OSMboxQuery (OS_EVENT DT_XDATA *pevent, OS_MBOX_DATA DT_XDATA *ppdata) REENTRANT
              {
                  INT8U  i;
                  INT8U DT_XDATA *psrc;
                  INT8U DT_XDATA *pdest;
                  
C51 COMPILER V7.06   OS_MBOX                                                               11/20/2008 19:25:23 PAGE 5   

                  
                  OS_ENTER_CRITICAL();
                  if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {       /* Validate event block type                */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_EVENT_TYPE);
                  }
                  ppdata->OSEventGrp = pevent->OSEventGrp;                /* Copy message mailbox wait list           */
                  psrc              = &pevent->OSEventTbl[0];
                  pdest             = &ppdata->OSEventTbl[0];
                  for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
                      *pdest++ = *psrc++;   
                  }
                  ppdata->OSMsg = pevent->OSEventPtr;                     /* Get message from mailbox                 */
                  OS_EXIT_CRITICAL();
                  return (OS_NO_ERR);
              }
              #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   ----    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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