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

📄 os_q.lst

📁 UCOSii for c8051f020
💻 LST
📖 第 1 页 / 共 4 页
字号:
 369   2              OSTCBCur->OSTCBStat     = OS_STAT_RDY;
 370   2              OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0; /* No longer waiting for event                        */
 371   2              OS_EXIT_CRITICAL();
 372   2              *err                    = OS_NO_ERR;
 373   2              return (msg);                            /* Return message received                            */
 374   2          }
 375   1          OS_EventTO(pevent);                          /* Timed out                                          */
 376   1          OS_EXIT_CRITICAL();
 377   1          *err = OS_TIMEOUT;                           /* Indicate a timeout occured                         */
 378   1          return ((void *)0);                          /* No message received                                */
 379   1      }
 380          /*$PAGE*/
 381          /*
 382          *********************************************************************************************************
 383          *                                        POST MESSAGE TO A QUEUE
 384          *
 385          * Description: This function sends a message to a queue
 386          *
 387          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
 388          *
 389          *              msg           is a pointer to the message to send.  You MUST NOT send a NULL pointer.
 390          *
 391          * Returns    : OS_NO_ERR             The call was successful and the message was sent
 392          *              OS_Q_FULL             If the queue cannot accept any more messages because it is full.
 393          *              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
 394          *              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
 395          *              OS_ERR_POST_NULL_PTR  If you are attempting to post a NULL pointer
 396          *********************************************************************************************************
 397          */
 398          
 399          #if OS_Q_POST_EN > 0
 400          INT8U  OSQPost (OS_EVENT *pevent, void *msg) reentrant
 401          {
 402   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif    
 405   1          OS_Q      *pq;
 406   1      
 407   1      
 408   1      #if OS_ARG_CHK_EN > 0
 409   1          if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 410   2              return (OS_ERR_PEVENT_NULL);
 411   2          }
 412   1          if (msg == (void *)0) {                           /* Make sure we are not posting a NULL pointer   */
 413   2              return (OS_ERR_POST_NULL_PTR);
 414   2          }
 415   1          if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type                     */
 416   2              return (OS_ERR_EVENT_TYPE);
 417   2          }
 418   1      #endif
 419   1          OS_ENTER_CRITICAL();
 420   1          if (pevent->OSEventGrp != 0x00) {                 /* See if any task pending on queue              */
 421   2              OS_EventTaskRdy(pevent, msg, OS_STAT_Q);      /* Ready highest priority task waiting on event  */
 422   2              OS_EXIT_CRITICAL();
 423   2              OS_Sched();                                   /* Find highest priority task ready to run       */
 424   2              return (OS_NO_ERR);
 425   2          }
 426   1          pq = (OS_Q *)pevent->OSEventPtr;                  /* Point to queue control block                  */
C51 COMPILER V7.06   OS_Q                                                                  03/05/2008 20:23:54 PAGE 8   

 427   1          if (pq->OSQEntries >= pq->OSQSize) {              /* Make sure queue is not full                   */
 428   2              OS_EXIT_CRITICAL();
 429   2              return (OS_Q_FULL);
 430   2          }
 431   1          *pq->OSQIn++ = msg;                               /* Insert message into queue                     */
 432   1          pq->OSQEntries++;                                 /* Update the nbr of entries in the queue        */
 433   1          if (pq->OSQIn == pq->OSQEnd) {                    /* Wrap IN ptr if we are at end of queue         */
 434   2              pq->OSQIn = pq->OSQStart;
 435   2          }
 436   1          OS_EXIT_CRITICAL();
 437   1          return (OS_NO_ERR);
 438   1      }
 439          #endif
 440          /*$PAGE*/
 441          /*
 442          *********************************************************************************************************
 443          *                                   POST MESSAGE TO THE FRONT OF A QUEUE
 444          *
 445          * Description: This function sends a message to a queue but unlike OSQPost(), the message is posted at
 446          *              the front instead of the end of the queue.  Using OSQPostFront() allows you to send
 447          *              'priority' messages.
 448          *
 449          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
 450          *
 451          *              msg           is a pointer to the message to send.  You MUST NOT send a NULL pointer.
 452          *
 453          * Returns    : OS_NO_ERR             The call was successful and the message was sent
 454          *              OS_Q_FULL             If the queue cannot accept any more messages because it is full.
 455          *              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
 456          *              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
 457          *              OS_ERR_POST_NULL_PTR  If you are attempting to post to a non queue.
 458          *********************************************************************************************************
 459          */
 460          
 461          #if OS_Q_POST_FRONT_EN > 0
 462          INT8U  OSQPostFront (OS_EVENT *pevent, void *msg) reentrant
 463          {
 464   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif    
 467   1          OS_Q      *pq;
 468   1      
 469   1      
 470   1      #if OS_ARG_CHK_EN > 0
 471   1          if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 472   2              return (OS_ERR_PEVENT_NULL);
 473   2          }
 474   1          if (msg == (void *)0) {                           /* Make sure we are not posting a NULL pointer   */
 475   2              return (OS_ERR_POST_NULL_PTR);
 476   2          }
 477   1          if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type                     */
 478   2              return (OS_ERR_EVENT_TYPE);
 479   2          }
 480   1      #endif
 481   1          OS_ENTER_CRITICAL();
 482   1          if (pevent->OSEventGrp != 0x00) {                 /* See if any task pending on queue              */
 483   2              OS_EventTaskRdy(pevent, msg, OS_STAT_Q);      /* Ready highest priority task waiting on event  */
 484   2              OS_EXIT_CRITICAL();
 485   2              OS_Sched();                                   /* Find highest priority task ready to run       */
 486   2              return (OS_NO_ERR);
 487   2          }
 488   1          pq = (OS_Q *)pevent->OSEventPtr;                  /* Point to queue control block                  */
C51 COMPILER V7.06   OS_Q                                                                  03/05/2008 20:23:54 PAGE 9   

 489   1          if (pq->OSQEntries >= pq->OSQSize) {              /* Make sure queue is not full                   */
 490   2              OS_EXIT_CRITICAL();
 491   2              return (OS_Q_FULL);
 492   2          }
 493   1          if (pq->OSQOut == pq->OSQStart) {                 /* Wrap OUT ptr if we are at the 1st queue entry */
 494   2              pq->OSQOut = pq->OSQEnd;
 495   2          }
 496   1          pq->OSQOut--;
 497   1          *pq->OSQOut = msg;                                /* Insert message into queue                     */
 498   1          pq->OSQEntries++;                                 /* Update the nbr of entries in the queue        */
 499   1          OS_EXIT_CRITICAL();
 500   1          return (OS_NO_ERR);
 501   1      }
 502          #endif
 503          /*$PAGE*/
 504          /*
 505          *********************************************************************************************************
 506          *                                        POST MESSAGE TO A QUEUE
 507          *
 508          * Description: This function sends a message to a queue.  This call has been added to reduce code size
 509          *              since it can replace both OSQPost() and OSQPostFront().  Also, this function adds the 
 510          *              capability to broadcast a message to ALL tasks waiting on the message queue.
 511          *
 512          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
 513          *
 514          *              msg           is a pointer to the message to send.  You MUST NOT send a NULL pointer.
 515          *
 516          *              opt           determines the type of POST performed:
 517          *                            OS_POST_OPT_NONE         POST to a single waiting task 
 518          *                                                     (Identical to OSQPost())
 519          *                            OS_POST_OPT_BROADCAST    POST to ALL tasks that are waiting on the queue
 520          *                            OS_POST_OPT_FRONT        POST as LIFO (Simulates OSQPostFront())
 521          *
 522          *                            Below is a list of ALL the possible combination of these flags:
 523          *
 524          *                                 1) OS_POST_OPT_NONE
 525          *                                    identical to OSQPost()
 526          *
 527          *                                 2) OS_POST_OPT_FRONT  
 528          *                                    identical to OSQPostFront()
 529          *
 530          *                                 3) OS_POST_OPT_BROADCAST
 531          *                                    identical to OSQPost() but will broadcast 'msg' to ALL waiting tasks
 532          *
 533          *                                 4) OS_POST_OPT_FRONT + OS_POST_OPT_BROADCAST  is identical to
 534          *                                    OSQPostFront() except that will broadcast 'msg' to ALL waiting tasks
 535          *
 536          * Returns    : OS_NO_ERR             The call was successful and the message was sent
 537          *              OS_Q_FULL             If the queue cannot accept any more messages because it is full.
 538          *              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
 539          *              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
 540          *              OS_ERR_POST_NULL_PTR  If you are attempting to post a NULL pointer
 541          *
 542          * Warning    : Interrupts can be disabled for a long time if you do a 'broadcast'.  In fact, the 
 543          *              interrupt disable time is proportional to the number of tasks waiting on the queue.
 544          *********************************************************************************************************
 545          */
 546          
 547          #if OS_Q_POST_OPT_EN > 0
              INT8U  OSQPostOpt (OS_EVENT *pevent, void *msg, INT8U opt) reentrant
              {
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
C51 COMPILER V7.06   OS_Q                                                                  03/05/2008 20:23:54 PAGE 10  

                  OS_CPU_SR  cpu_sr;
              #endif    
                  OS_Q      *pq;
              
              
              #if OS_ARG_CHK_EN > 0
                  if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */

⌨️ 快捷键说明

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