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

📄 os_mbox.lst

📁 在C8051F060上实现嵌入式系统ucos
💻 LST
📖 第 1 页 / 共 3 页
字号:
                      tasks_waiting = FALSE;                             /* No                                       */
                  }
                  switch (opt) {
                      case OS_DEL_NO_PEND:                               /* Delete mailbox only if no task waiting   */
                           if (tasks_waiting == FALSE) {
                               pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
                               pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block to free list  */
                               OSEventFreeList     = pevent;             /* Get next free event control block        */
                               OS_EXIT_CRITICAL();
                               *err = OS_NO_ERR;
                               return ((OS_EVENT *)0);                   /* Mailbox has been deleted                 */
                           } else {
                               OS_EXIT_CRITICAL();
                               *err = OS_ERR_TASK_WAITING;
                               return (pevent);
                           }
              
                      case OS_DEL_ALWAYS:                                /* Always delete the mailbox                */
                           while (pevent->OSEventGrp != 0x00) {          /* Ready ALL tasks waiting for mailbox      */
C51 COMPILER V8.08   OS_MBOX                                                               03/02/2009 10:42:36 PAGE 4   

                               OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX);
                           }
                           pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
                           pevent->OSEventPtr  = OSEventFreeList;        /* Return Event Control Block to free list  */
                           OSEventFreeList     = pevent;                 /* Get next free event control block        */
                           OS_EXIT_CRITICAL();
                           if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) were waiting  */
                               OS_Sched();                               /* Find highest priority task ready to run  */
                           }
                           *err = OS_NO_ERR;
                           return ((OS_EVENT *)0);                       /* Mailbox has been deleted                 */
              
                      default:
                           OS_EXIT_CRITICAL();
                           *err = OS_ERR_INVALID_OPT;
                           return (pevent);
                  }
              }
              #endif
 198          
 199          /*$PAGE*/
 200          /*
 201          *********************************************************************************************************
 202          *                                      PEND ON MAILBOX FOR A MESSAGE
 203          *
 204          * Description: This function waits for a message to be sent to a mailbox
 205          *
 206          * Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
 207          *
 208          *              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
 209          *                            wait for a message to arrive at the mailbox up to the amount of time
 210          *                            specified by this argument.  If you specify 0, however, your task will wait
 211          *                            forever at the specified mailbox or, until a message arrives.
 212          *
 213          *              err           is a pointer to where an error message will be deposited.  Possible error
 214          *                            messages are:
 215          *
 216          *                            OS_NO_ERR           The call was successful and your task received a
 217          *                                                message.
 218          *                            OS_TIMEOUT          A message was not received within the specified timeout
 219          *                            OS_ERR_EVENT_TYPE   Invalid event type
 220          *                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
 221          *                                                would lead to a suspension.
 222          *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
 223          *
 224          * Returns    : != (void *)0  is a pointer to the message received
 225          *              == (void *)0  if no message was received or,
 226          *                            if 'pevent' is a NULL pointer or,
 227          *                            if you didn't pass the proper pointer to the event control block.
 228          *********************************************************************************************************
 229          */
 230          
 231          void  *OSMboxPend (OS_EVENT *pevent, INT16U timeout, INT8U *err)reentrant
 232          {
 233   1         
 234   1          void      *msg;
 235   1      
 236   1      
 237   1          if (OSIntNesting > 0) {                           /* See if called from ISR ...                    */
 238   2              *err = OS_ERR_PEND_ISR;                       /* ... can't PEND from an ISR                    */
 239   2              return ((void *)0);
 240   2          }
C51 COMPILER V8.08   OS_MBOX                                                               03/02/2009 10:42:36 PAGE 5   

 241   1      #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
                      *err = OS_ERR_PEVENT_NULL;
                      return ((void *)0);
                  }
                  if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type                     */
                      *err = OS_ERR_EVENT_TYPE;
                      return ((void *)0);
                  }
              #endif
 251   1          OS_ENTER_CRITICAL();
 252   1          msg = pevent->OSEventPtr;
 253   1          if (msg != (void *)0) {                           /* See if there is already a message             */
 254   2              pevent->OSEventPtr = (void *)0;               /* Clear the mailbox                             */
 255   2              OS_EXIT_CRITICAL();
 256   2              *err = OS_NO_ERR;
 257   2              return (msg);                                 /* Return the message received (or NULL)         */
 258   2          }
 259   1          OSTCBCur->OSTCBStat |= OS_STAT_MBOX;              /* Message not available, task will pend         */
 260   1          OSTCBCur->OSTCBDly   = timeout;                   /* Load timeout in TCB                           */
 261   1          OS_EventTaskWait(pevent);                         /* Suspend task until event or timeout occurs    */
 262   1          OS_EXIT_CRITICAL();
 263   1          OS_Sched();                                       /* Find next highest priority task ready to run  */
 264   1          OS_ENTER_CRITICAL();
 265   1          msg = OSTCBCur->OSTCBMsg;
 266   1          if (msg != (void *)0) {                           /* See if we were given the message              */
 267   2              OSTCBCur->OSTCBMsg      = (void *)0;          /* Yes, clear message received                   */
 268   2              OSTCBCur->OSTCBStat     = OS_STAT_RDY;
 269   2              OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;      /* No longer waiting for event                   */
 270   2              OS_EXIT_CRITICAL();
 271   2              *err                    = OS_NO_ERR;
 272   2              return (msg);                                 /* Return the message received                   */
 273   2          }
 274   1          OS_EventTO(pevent);                               /* Timed out, Make task ready                    */
 275   1          OS_EXIT_CRITICAL();
 276   1          *err = OS_TIMEOUT;                                /* Indicate that a timeout occured               */
 277   1          return ((void *)0);                               /* Return a NULL message                         */
 278   1      }
 279          /*$PAGE*/
 280          /*
 281          *********************************************************************************************************
 282          *                                       POST MESSAGE TO A MAILBOX
 283          *
 284          * Description: This function sends a message to a mailbox
 285          *
 286          * Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
 287          *
 288          *              msg           is a pointer to the message to send.  You MUST NOT send a NULL pointer.
 289          *
 290          * Returns    : OS_NO_ERR            The call was successful and the message was sent
 291          *              OS_MBOX_FULL         If the mailbox already contains a message.  You can can only send one
 292          *                                   message at a time and thus, the message MUST be consumed before you
 293          *                                   are allowed to send another one.
 294          *              OS_ERR_EVENT_TYPE    If you are attempting to post to a non mailbox.
 295          *              OS_ERR_PEVENT_NULL   If 'pevent' is a NULL pointer
 296          *              OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
 297          *********************************************************************************************************
 298          */
 299          
 300          #if OS_MBOX_POST_EN > 0
 301          INT8U  OSMboxPost (OS_EVENT *pevent, void *msg)reentrant
 302          {
C51 COMPILER V8.08   OS_MBOX                                                               03/02/2009 10:42:36 PAGE 6   

 303   1        
 304   1          
 305   1          
 306   1      #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
                      return (OS_ERR_PEVENT_NULL);
                  }
                  if (msg == (void *)0) {                           /* Make sure we are not posting a NULL pointer   */
                      return (OS_ERR_POST_NULL_PTR);
                  }
                  if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type                     */
                      return (OS_ERR_EVENT_TYPE);
                  }
              #endif
 317   1          OS_ENTER_CRITICAL();
 318   1          if (pevent->OSEventGrp != 0x00) {                 /* See if any task pending on mailbox            */
 319   2              OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX);   /* Ready highest priority task waiting on event  */
 320   2              OS_EXIT_CRITICAL();
 321   2              OS_Sched();                                   /* Find highest priority task ready to run       */
 322   2              return (OS_NO_ERR);
 323   2          }
 324   1          if (pevent->OSEventPtr != (void *)0) {            /* Make sure mailbox doesn't already have a msg  */
 325   2              OS_EXIT_CRITICAL();
 326   2              return (OS_MBOX_FULL);

⌨️ 快捷键说明

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