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

📄 os_mbox.lst

📁 ucos移植学习
💻 LST
📖 第 1 页 / 共 2 页
字号:
 129   1          msg = pevent->OSEventPtr;
 130   1          if (msg != (void DT_XDATA *)0) {                           /* See if there is already a message       
             -      */
 131   2              pevent->OSEventPtr = (void DT_XDATA *)0;               /* Clear the mailbox                       
             -      */
 132   2              OS_EXIT_CRITICAL();
 133   2              *err = OS_NO_ERR;
 134   2          } else if (OSIntNesting > 0) {                    /* See if called from ISR ...                    */
 135   2              OS_EXIT_CRITICAL();                           /* ... can't PEND from an ISR                    */
 136   2              *err = OS_ERR_PEND_ISR;
 137   2          } else {
 138   2              OSTCBCur->OSTCBStat |= OS_STAT_MBOX;          /* Message not available, task will pend         */
 139   2              OSTCBCur->OSTCBDly   = timeout;               /* Load timeout in TCB                           */
 140   2              OSEventTaskWait(pevent);                      /* Suspend task until event or timeout occurs    */
 141   2              OS_EXIT_CRITICAL();
 142   2              OSSched();                                    /* Find next highest priority task ready to run  */
 143   2              OS_ENTER_CRITICAL();
 144   2              if ((msg = OSTCBCur->OSTCBMsg) != (void DT_XDATA *)0) {     /* See if we were given the message   
             -      */
 145   3                  OSTCBCur->OSTCBMsg      = (void DT_XDATA *)0;           /* Yes, clear message received        
             -      */
 146   3                  OSTCBCur->OSTCBStat     = OS_STAT_RDY;
 147   3                  OSTCBCur->OSTCBEventPtr = (OS_EVENT DT_XDATA *)0;       /* No longer waiting for event        
             -      */
 148   3                  OS_EXIT_CRITICAL();
 149   3                  *err                    = OS_NO_ERR;
 150   3              } else if (OSTCBCur->OSTCBStat & OS_STAT_MBOX) {   /* If status is not OS_STAT_RDY, timed out  */
 151   3                  OSEventTO(pevent);                             /* Make task ready                          */
 152   3                  OS_EXIT_CRITICAL();
 153   3                  msg                     = (void DT_XDATA *)0;           /* Set message contents to NULL       
             -      */
 154   3                  *err                    = OS_TIMEOUT;          /* Indicate that a timeout occured          */
 155   3              } else {
 156   3                  msg                     = pevent->OSEventPtr;  /* Message received                         */
 157   3                  pevent->OSEventPtr      = (void DT_XDATA *)0;           /* Clear the mailbox                  
             -      */
 158   3                  OSTCBCur->OSTCBEventPtr = (OS_EVENT DT_XDATA *)0;
 159   3                  OS_EXIT_CRITICAL();
 160   3                  *err                    = OS_NO_ERR;
 161   3              }
 162   2          }
 163   1          return (msg);                                          /* Return the message received (or NULL)    */
 164   1      }
 165          /*$PAGE*/
 166          /*
 167          *********************************************************************************************************
 168          *                                       POST MESSAGE TO A MAILBOX
C51 COMPILER V7.02a   OS_MBOX                                                              10/16/2006 15:27:51 PAGE 4   

 169          *
 170          * Description: This function sends a message to a mailbox
 171          *
 172          * Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
 173          *
 174          *              msg           is a pointer to the message to send.  You MUST NOT send a NULL pointer.  
 175          *
 176          * Returns    : OS_NO_ERR          The call was successful and the message was sent
 177          *              OS_MBOX_FULL       If the mailbox already contains a message.  You can can only send one
 178          *                                 message at a time and thus, the message MUST be consumed before you are
 179          *                                 allowed to send another one.
 180          *              OS_ERR_EVENT_TYPE  If you are attempting to post to a non mailbox.
 181          *********************************************************************************************************
 182          */
 183          
 184          INT8U OSMboxPost (OS_EVENT DT_XDATA *pevent, void DT_XDATA *msg) REENTRANT
 185          {
 186   1          OS_ENTER_CRITICAL();
 187   1          if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type                     */
 188   2              OS_EXIT_CRITICAL();
 189   2              return (OS_ERR_EVENT_TYPE);
 190   2          }
 191   1          if (pevent->OSEventGrp) {                         /* See if any task pending on mailbox            */
 192   2              OSEventTaskRdy(pevent, msg, OS_STAT_MBOX);    /* Ready highest priority task waiting on event  */
 193   2              OS_EXIT_CRITICAL();
 194   2              OSSched();                                    /* Find highest priority task ready to run       */
 195   2              return (OS_NO_ERR);
 196   2          } else {
 197   2              if (pevent->OSEventPtr != (void DT_XDATA *)0) {        /* Make sure mailbox doesn't already have a
             - msg  */
 198   3                  OS_EXIT_CRITICAL();
 199   3                  return (OS_MBOX_FULL);
 200   3              } else {
 201   3                  pevent->OSEventPtr = msg;                 /* Place message in mailbox                      */
 202   3                  OS_EXIT_CRITICAL();
 203   3                  return (OS_NO_ERR);
 204   3              }
 205   2          }
 206   1      }
 207          /*$PAGE*/
 208          /*
 209          *********************************************************************************************************
 210          *                                        QUERY A MESSAGE MAILBOX
 211          *
 212          * Description: This function obtains information about a message mailbox.
 213          *
 214          * Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
 215          *
 216          *              ppdata         is a pointer to a structure that will contain information about the message
 217          *                            mailbox.
 218          *
 219          * Returns    : OS_NO_ERR          The call was successful and the message was sent
 220          *              OS_ERR_EVENT_TYPE  If you are attempting to obtain data from a non mailbox.
 221          *********************************************************************************************************
 222          */
 223          
 224          INT8U OSMboxQuery (OS_EVENT DT_XDATA *pevent, OS_MBOX_DATA DT_XDATA *ppdata) REENTRANT
 225          {
 226   1          INT8U  i;
 227   1          INT8U DT_XDATA *psrc;
 228   1          INT8U DT_XDATA *pdest;
 229   1          
C51 COMPILER V7.02a   OS_MBOX                                                              10/16/2006 15:27:51 PAGE 5   

 230   1          
 231   1          OS_ENTER_CRITICAL();
 232   1          if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {       /* Validate event block type                */
 233   2              OS_EXIT_CRITICAL();
 234   2              return (OS_ERR_EVENT_TYPE);
 235   2          }
 236   1          ppdata->OSEventGrp = pevent->OSEventGrp;                /* Copy message mailbox wait list           */
 237   1          psrc              = &pevent->OSEventTbl[0];
 238   1          pdest             = &ppdata->OSEventTbl[0];
 239   1          for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
 240   2              *pdest++ = *psrc++;   
 241   2          }
 242   1          ppdata->OSMsg = pevent->OSEventPtr;                     /* Get message from mailbox                 */
 243   1          OS_EXIT_CRITICAL();
 244   1          return (OS_NO_ERR);
 245   1      }
 246          #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1031    ----
   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 + -