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

📄 os_mbox.lst

📁 uCOS 嵌入式操作系统的改进版,增加了网络通讯.
💻 LST
📖 第 1 页 / 共 3 页
字号:
 169   2          } else {
 170   2              tasks_waiting = FALSE;                             /* No                                       */
 171   2          }
 172   1          switch (opt) {
 173   2              case OS_DEL_NO_PEND:                               /* Delete mailbox only if no task waiting   */
 174   2                   if (tasks_waiting == FALSE) {
 175   3      #if OS_EVENT_NAME_SIZE > 0
 176   3                       (void)strcpy(pevent->OSEventName, "?");   /* Unknown name                             */
 177   3      #endif
 178   3                       pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
C51 COMPILER V7.06   OS_MBOX                                                               07/18/2003 11:05:58 PAGE 4   

 179   3                       pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block to free list  */
 180   3                       pevent->OSEventCnt  = 0;
 181   3                       OSEventFreeList     = pevent;             /* Get next free event control block        */
 182   3                       OS_EXIT_CRITICAL();
 183   3                       *err                = OS_NO_ERR;
 184   3                       return ((OS_EVENT *)0);                   /* Mailbox has been deleted                 */
 185   3                   } else {
 186   3                       OS_EXIT_CRITICAL();
 187   3                       *err                = OS_ERR_TASK_WAITING;
 188   3                       return (pevent);
 189   3                   }
 190   2      
 191   2              case OS_DEL_ALWAYS:                                /* Always delete the mailbox                */
 192   2                   while (pevent->OSEventGrp != 0x00) {          /* Ready ALL tasks waiting for mailbox      */
 193   3                       OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX);
 194   3                   }
 195   2      #if OS_EVENT_NAME_SIZE > 0
 196   2                   (void)strcpy(pevent->OSEventName, "?");       /* Unknown name                             */
 197   2      #endif
 198   2                   pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
 199   2                   pevent->OSEventPtr  = OSEventFreeList;        /* Return Event Control Block to free list  */
 200   2                   pevent->OSEventCnt  = 0;
 201   2                   OSEventFreeList     = pevent;                 /* Get next free event control block        */
 202   2                   OS_EXIT_CRITICAL();
 203   2                   if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) were waiting  */
 204   3                       OS_Sched();                               /* Find highest priority task ready to run  */
 205   3                   }
 206   2                   *err = OS_NO_ERR;
 207   2                   return ((OS_EVENT *)0);                       /* Mailbox has been deleted                 */
 208   2      
 209   2              default:
 210   2                   OS_EXIT_CRITICAL();
 211   2                   *err = OS_ERR_INVALID_OPT;
 212   2                   return (pevent);
 213   2          }
 214   1      }
 215          #endif
 216          
 217          /*$PAGE*/
 218          /*
 219          *********************************************************************************************************
 220          *                                      PEND ON MAILBOX FOR A MESSAGE
 221          *
 222          * Description: This function waits for a message to be sent to a mailbox
 223          *
 224          * Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
 225          *
 226          *              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
 227          *                            wait for a message to arrive at the mailbox up to the amount of time
 228          *                            specified by this argument.  If you specify 0, however, your task will wait
 229          *                            forever at the specified mailbox or, until a message arrives.
 230          *
 231          *              err           is a pointer to where an error message will be deposited.  Possible error
 232          *                            messages are:
 233          *
 234          *                            OS_NO_ERR           The call was successful and your task received a
 235          *                                                message.
 236          *                            OS_TIMEOUT          A message was not received within the specified timeout
 237          *                            OS_ERR_EVENT_TYPE   Invalid event type
 238          *                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
 239          *                                                would lead to a suspension.
 240          *                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer
C51 COMPILER V7.06   OS_MBOX                                                               07/18/2003 11:05:58 PAGE 5   

 241          *
 242          * Returns    : != (void *)0  is a pointer to the message received
 243          *              == (void *)0  if no message was received or,
 244          *                            if 'pevent' is a NULL pointer or,
 245          *                            if you didn't pass the proper pointer to the event control block.
 246          *********************************************************************************************************
 247          */
 248          
 249          void  *OSMboxPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) reentrant //using 0
 250          {
 251   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
 252   1          OS_CPU_SR  cpu_sr;
 253   1      #endif    
 254   1          void      *msg;
 255   1      
 256   1      
 257   1          if (OSIntNesting > 0) {                           /* See if called from ISR ...                    */
 258   2              *err = OS_ERR_PEND_ISR;                       /* ... can't PEND from an ISR                    */
 259   2              return ((void *)0);
 260   2          }
 261   1      #if OS_ARG_CHK_EN > 0
 262   1          if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 263   2              *err = OS_ERR_PEVENT_NULL;
 264   2              return ((void *)0);
 265   2          }
 266   1      #endif
 267   1          if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type                     */
 268   2              *err = OS_ERR_EVENT_TYPE;
 269   2              return ((void *)0);
 270   2          }
 271   1          OS_ENTER_CRITICAL();
 272   1          msg = pevent->OSEventPtr;
 273   1          if (msg != (void *)0) {                           /* See if there is already a message             */
 274   2              pevent->OSEventPtr = (void *)0;               /* Clear the mailbox                             */
 275   2              OS_EXIT_CRITICAL();
 276   2              *err = OS_NO_ERR;
 277   2              return (msg);                                 /* Return the message received (or NULL)         */
 278   2          }
 279   1          OSTCBCur->OSTCBStat |= OS_STAT_MBOX;              /* Message not available, task will pend         */
 280   1          OSTCBCur->OSTCBDly   = timeout;                   /* Load timeout in TCB                           */
 281   1          OS_EventTaskWait(pevent);                         /* Suspend task until event or timeout occurs    */
 282   1          OS_EXIT_CRITICAL();
 283   1          OS_Sched();                                       /* Find next highest priority task ready to run  */
 284   1          OS_ENTER_CRITICAL();
 285   1          msg = OSTCBCur->OSTCBMsg;
 286   1          if (msg != (void *)0) {                           /* See if we were given the message              */
 287   2              OSTCBCur->OSTCBMsg      = (void *)0;          /* Yes, clear message received                   */
 288   2              OSTCBCur->OSTCBStat     = OS_STAT_RDY;
 289   2              OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;      /* No longer waiting for event                   */
 290   2              OS_EXIT_CRITICAL();
 291   2              *err                    = OS_NO_ERR;
 292   2              return (msg);                                 /* Return the message received                   */
 293   2          }
 294   1          OS_EventTO(pevent);                               /* Timed out, Make task ready                    */
 295   1          OS_EXIT_CRITICAL();
 296   1          *err = OS_TIMEOUT;                                /* Indicate that a timeout occured               */
 297   1          return ((void *)0);                               /* Return a NULL message                         */
 298   1      }
 299          /*$PAGE*/
 300          /*
 301          *********************************************************************************************************
 302          *                                       POST MESSAGE TO A MAILBOX
C51 COMPILER V7.06   OS_MBOX                                                               07/18/2003 11:05:58 PAGE 6   

 303          *
 304          * Description: This function sends a message to a mailbox
 305          *
 306          * Arguments  : pevent        is a pointer to the event control block associated with the desired mailbox
 307          *
 308          *              msg           is a pointer to the message to send.  You MUST NOT send a NULL pointer.
 309          *
 310          * Returns    : OS_NO_ERR            The call was successful and the message was sent
 311          *              OS_MBOX_FULL         If the mailbox already contains a message.  You can can only send one
 312          *                                   message at a time and thus, the message MUST be consumed before you
 313          *                                   are allowed to send another one.
 314          *              OS_ERR_EVENT_TYPE    If you are attempting to post to a non mailbox.
 315          *              OS_ERR_PEVENT_NULL   If 'pevent' is a NULL pointer
 316          *              OS_ERR_POST_NULL_PTR If you are attempting to post a NULL pointer
 317          *********************************************************************************************************
 318          */
 319          
 320          #if OS_MBOX_POST_EN > 0
 321          INT8U  OSMboxPost (OS_EVENT *pevent, void *msg) reentrant //using 0
 322          {
 323   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
 324   1          OS_CPU_SR  cpu_sr;
 325   1      #endif    
 326   1          
 327   1          
 328   1      #if OS_ARG_CHK_EN > 0
 329   1          if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 330   2              return (OS_ERR_PEVENT_NULL);
 331   2          }
 332   1          if (msg == (void *)0) {                           /* Make sure we are not posting a NULL pointer   */
 333   2              return (OS_ERR_POST_NULL_PTR);
 334   2          }
 335   1      #endif
 336   1          if (pevent->OSEventType != OS_EVENT_TYPE_MBOX) {  /* Validate event block type                     */
 337   2              return (OS_ERR_EVENT_TYPE);
 338   2          }
 339   1          OS_ENTER_CRITICAL();
 340   1          if (pevent->OSEventGrp != 0x00) {                 /* See if any task pending on mailbox            */
 341   2              OS_EventTaskRdy(pevent, msg, OS_STAT_MBOX);   /* Ready highest priority task waiting on event  */
 342   2              OS_EXIT_CRITICAL();
 343   2              OS_Sched();                                   /* Find highest priority task ready to run       */
 344   2              return (OS_NO_ERR);

⌨️ 快捷键说明

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