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

📄 os_mbox.lst

📁 1. UC/OS 8051中完全应用。 2. 显示各个任务的执行时间, 执行时间占总时间百分比, tick计数器 3.任务中信号量,消息以及消息队列的使用。 我自己仔细测试过了
💻 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 {
C51 COMPILER V8.08   OS_MBOX                                                               08/19/2008 10:59:09 PAGE 4   

                               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      */
                               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
 205          
 206          /*$PAGE*/
 207          /*
 208          *********************************************************************************************************
 209          *                                      PEND ON MAILBOX FOR A MESSAGE
 210          *
 211          * Description: This function waits for a message to be sent to a mailbox
 212          *
 213          * Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
 214          *
 215          *              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
 216          *                            wait for a message to arrive at the mailbox up to the amount of time
 217          *                            specified by this argument.  If you specify 0, however, your task will wait
 218          *                            forever at the specified mailbox or, until a message arrives.
 219          *
 220          *              err           is a pointer to where an error message will be deposited.  Possible error
 221          *                            messages are:
 222          *
 223          *                            OS_NO_ERR           The call was successful and your task received a
 224          *                                                message.
 225          *                            OS_TIMEOUT          A message was not received within the specified timeout
 226          *                            OS_ERR_EVENT_TYPE   Invalid event type
 227          *                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
 228          *                                                would lead to a suspension.
 229          *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
 230          *
 231          * Returns    : != (void *)0  is a pointer to the message received
 232          *              == (void *)0  if no message was received or,
 233          *                            if 'pevent' is a NULL pointer or,
 234          *                            if you didn't pass the proper pointer to the event control block.
 235          *********************************************************************************************************
 236          */
 237          
 238          void  *OSMboxPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) reentrant
 239          {
 240   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
C51 COMPILER V8.08   OS_MBOX                                                               08/19/2008 10:59:09 PAGE 5   

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

 303          *              OS_ERR_EVENT_TYPE    If you are attempting to post to a non mailbox.
 304          *              OS_ERR_PEVENT_NULL   If 'pevent' is a NULL pointer
 305          *              OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
 306          *********************************************************************************************************
 307          */
 308          
 309          #if OS_MBOX_POST_EN > 0
 310          INT8U  OSMboxPost (OS_EVENT *pevent, void *msg) reentrant
 311          {
 312   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif    
 315   1          
 316   1          
 317   1      #if OS_ARG_CHK_EN > 0
 318   1          if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 319   2              return (OS_ERR_PEVENT_NULL);
 320   2          }
 321   1          if (msg == (void *)0) {                           /* Make sure we are not posting a NULL pointer   */
 322   2              return (OS_ERR_POST_NULL_PTR);
 323   2          }
 324   1          if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type                     */
 325   2              return (OS_ERR_EVENT_TYPE);
 326   2          }
 327   1      #endif
 328   1          OS_ENTER_CRITICAL();
 329   1          if (pevent->OSEventGrp != 0x00) {                 /* See if any task pending on mailbox            */
 330   2              OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX);   /* Ready highest priority task waiting on event  */
 331   2              OS_EXIT_CRITICAL();
 332   2              OS_Sched();                                   /* Find highest priority task ready to run       */
 333   2              return (OS_NO_ERR);
 334   2          }
 335   1          if (pevent->OSEventPtr != (void *)0) {            /* Make sure mailbox doesn't already have a msg  */
 336   2              OS_EXIT_CRITICAL();
 337   2              return (OS_MBOX_FULL);
 338   2          }
 339   1          pevent->OSEventPtr = msg;                         /* Place message in mailbox                      */
 340   1          OS_EXIT_CRITICAL();

⌨️ 快捷键说明

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