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

📄 os_mbox.lst

📁 实现ucos任务调度时保存LCD上的显示信息
💻 LST
📖 第 1 页 / 共 3 页
字号:
 166   2          } else {
 167   2              tasks_waiting = FALSE;                             /* No                                       */
 168   2          }
 169   1          switch (opt) {
 170   2              case OS_DEL_NO_PEND:                               /* Delete mailbox only if no task waiting   */
 171   2                   if (tasks_waiting == FALSE) {
 172   3                       pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
 173   3                       pevent->OSEventPtr  = OSEventFreeList;    /* Return Event Control Block to free list  */
 174   3                       OSEventFreeList     = pevent;             /* Get next free event control block        */
 175   3                       OS_EXIT_CRITICAL();
 176   3                       *err = OS_NO_ERR;
 177   3                       return ((OS_EVENT *)0);                   /* Mailbox has been deleted                 */
 178   3                   } else {
C51 COMPILER V8.02   OS_MBOX                                                               05/22/2008 18:01:51 PAGE 4   

 179   3                       OS_EXIT_CRITICAL();
 180   3                       *err = OS_ERR_TASK_WAITING;
 181   3                       return (pevent);
 182   3                   }
 183   2      
 184   2              case OS_DEL_ALWAYS:                                /* Always delete the mailbox                */
 185   2                   while (pevent->OSEventGrp != 0x00) {          /* Ready ALL tasks waiting for mailbox      */
 186   3                       OS_EventTaskRdy(pevent, (void *)0, OS_STAT_MBOX);
 187   3                   }
 188   2                   pevent->OSEventType = OS_EVENT_TYPE_UNUSED;
 189   2                   pevent->OSEventPtr  = OSEventFreeList;        /* Return Event Control Block to free list  */
 190   2                   OSEventFreeList     = pevent;                 /* Get next free event control block        */
 191   2                   OS_EXIT_CRITICAL();
 192   2                   if (tasks_waiting == TRUE) {                  /* Reschedule only if task(s) were waiting  */
 193   3                       OS_Sched();                               /* Find highest priority task ready to run  */
 194   3                   }
 195   2                   *err = OS_NO_ERR;
 196   2                   return ((OS_EVENT *)0);                       /* Mailbox has been deleted                 */
 197   2      
 198   2              default:
 199   2                   OS_EXIT_CRITICAL();
 200   2                   *err = OS_ERR_INVALID_OPT;
 201   2                   return (pevent);
 202   2          }
 203   1      }
 204          #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) KCREENTRANT
 239          {
 240   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
C51 COMPILER V8.02   OS_MBOX                                                               05/22/2008 18:01:51 PAGE 5   

 241   1          OS_CPU_SR  cpu_sr;
 242   1      #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.02   OS_MBOX                                                               05/22/2008 18:01:51 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) KCREENTRANT
 311          {
 312   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
 313   1          OS_CPU_SR  cpu_sr;
 314   1      #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          }

⌨️ 快捷键说明

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