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

📄 os_q.lst

📁 uCOS 嵌入式操作系统的改进版,增加了网络通讯.
💻 LST
📖 第 1 页 / 共 4 页
字号:
 383   1          pq = (OS_Q *)pevent->OSEventPtr;             /* Point at queue control block                       */
 384   1          if (pq->OSQEntries > 0) {                    /* See if any messages in the queue                   */
 385   2              msg = *pq->OSQOut++;                     /* Yes, extract oldest message from the queue         */
 386   2              pq->OSQEntries--;                        /* Update the number of entries in the queue          */
 387   2              if (pq->OSQOut == pq->OSQEnd) {          /* Wrap OUT pointer if we are at the end of the queue */
 388   3                  pq->OSQOut = pq->OSQStart;
 389   3              }
 390   2              OS_EXIT_CRITICAL();
 391   2              *err = OS_NO_ERR;
 392   2              return (msg);                            /* Return message received                            */
 393   2          }
 394   1          OSTCBCur->OSTCBStat |= OS_STAT_Q;            /* Task will have to pend for a message to be posted  */
 395   1          OSTCBCur->OSTCBDly   = timeout;              /* Load timeout into TCB                              */
 396   1          OS_EventTaskWait(pevent);                    /* Suspend task until event or timeout occurs         */
 397   1          OS_EXIT_CRITICAL();
 398   1          OS_Sched();                                  /* Find next highest priority task ready to run       */
 399   1          OS_ENTER_CRITICAL();
 400   1          if (OSTCBCur->OSTCBStat & OS_STAT_Q) {       /* Was task readied because of a timeout?             */
 401   2              OS_EventTO(pevent);                      /* Yes                                                */
 402   2              OS_EXIT_CRITICAL();
 403   2              *err = OS_TIMEOUT;                       /*     Indicate a timeout occured                     */
 404   2              return ((void *)0);                      /*     No message received                            */
 405   2          }
 406   1          msg                     = OSTCBCur->OSTCBMsg;/* No, Extract message from TCB (Put there by QPost)  */
 407   1          OSTCBCur->OSTCBMsg      = (void *)0;
 408   1          OSTCBCur->OSTCBStat     = OS_STAT_RDY;
 409   1          OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;     /*     No longer waiting for event                    */
 410   1          OS_EXIT_CRITICAL();
 411   1          *err                    = OS_NO_ERR;
 412   1          return (msg);                                /*     Return message received                        */
 413   1      }
 414          /*$PAGE*/
 415          /*
 416          *********************************************************************************************************
 417          *                                        POST MESSAGE TO A QUEUE
 418          *
 419          * Description: This function sends a message to a queue
 420          *
 421          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
 422          *
 423          *              msg           is a pointer to the message to send.  You MUST NOT send a NULL pointer.
 424          *
 425          * Returns    : OS_NO_ERR             The call was successful and the message was sent
 426          *              OS_Q_FULL             If the queue cannot accept any more messages because it is full.
C51 COMPILER V7.06   OS_Q                                                                  07/18/2003 11:06:02 PAGE 8   

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

 489          *
 490          * Note(s)    : As of V2.60, this function allows you to send NULL pointer messages.
 491          *********************************************************************************************************
 492          */
 493          
 494          #if OS_Q_POST_FRONT_EN > 0
 495          INT8U  OSQPostFront (OS_EVENT *pevent, void *msg) reentrant //using 0
 496          {
 497   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
 498   1          OS_CPU_SR  cpu_sr;
 499   1      #endif
 500   1          OS_Q      *pq;
 501   1      
 502   1      
 503   1      #if OS_ARG_CHK_EN > 0
 504   1          if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
 505   2              return (OS_ERR_PEVENT_NULL);
 506   2          }
 507   1      #endif
 508   1          if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type                     */
 509   2              return (OS_ERR_EVENT_TYPE);
 510   2          }
 511   1          OS_ENTER_CRITICAL();
 512   1          if (pevent->OSEventGrp != 0x00) {                 /* See if any task pending on queue              */
 513   2              OS_EventTaskRdy(pevent, msg, OS_STAT_Q);      /* Ready highest priority task waiting on event  */
 514   2              OS_EXIT_CRITICAL();
 515   2              OS_Sched();                                   /* Find highest priority task ready to run       */
 516   2              return (OS_NO_ERR);
 517   2          }
 518   1          pq = (OS_Q *)pevent->OSEventPtr;                  /* Point to queue control block                  */
 519   1          if (pq->OSQEntries >= pq->OSQSize) {              /* Make sure queue is not full                   */
 520   2              OS_EXIT_CRITICAL();
 521   2              return (OS_Q_FULL);
 522   2          }
 523   1          if (pq->OSQOut == pq->OSQStart) {                 /* Wrap OUT ptr if we are at the 1st queue entry */
 524   2              pq->OSQOut = pq->OSQEnd;
 525   2          }
 526   1          pq->OSQOut--;
 527   1          *pq->OSQOut = msg;                                /* Insert message into queue                     */
 528   1          pq->OSQEntries++;                                 /* Update the nbr of entries in the queue        */
 529   1          OS_EXIT_CRITICAL();
 530   1          return (OS_NO_ERR);
 531   1      }
 532          #endif
 533          /*$PAGE*/
 534          /*
 535          *********************************************************************************************************
 536          *                                        POST MESSAGE TO A QUEUE
 537          *
 538          * Description: This function sends a message to a queue.  This call has been added to reduce code size
 539          *              since it can replace both OSQPost() and OSQPostFront().  Also, this function adds the
 540          *              capability to broadcast a message to ALL tasks waiting on the message queue.
 541          *
 542          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
 543          *
 544          *              msg           is a pointer to the message to send.  You MUST NOT send a NULL pointer.
 545          *
 546          *              opt           determines the type of POST performed:
 547          *                            OS_POST_OPT_NONE         POST to a single waiting task
 548          *                                                     (Identical to OSQPost())
 549          *                            OS_POST_OPT_BROADCAST    POST to ALL tasks that are waiting on the queue
 550          *                            OS_POST_OPT_FRONT        POST as LIFO (Simulates OSQPostFront())
C51 COMPILER V7.06   OS_Q                                                                  07/18/2003 11:06:02 PAGE 10  

 551          *
 552          *                            Below is a list of ALL the possible combination of these flags:
 553          *
 554          *                                 1) OS_POST_OPT_NONE
 555          *                                    identical to OSQPost()
 556          *
 557          *                                 2) OS_POST_OPT_FRONT
 558          *                                    identical to OSQPostFront()
 559          *
 560          *                                 3) OS_POST_OPT_BROADCAST
 561          *                                    identical to OSQPost() but will broadcast 'msg' to ALL waiting tasks
 562          *
 563          *                                 4) OS_POST_OPT_FRONT + OS_POST_OPT_BROADCAST  is identical to
 564          *                                    OSQPostFront() except that will broadcast 'msg' to ALL waiting tasks
 565          *
 566          * Returns    : OS_NO_ERR             The call was successful and the message was sent
 567          *              OS_Q_FULL             If the queue cannot accept any more messages because it is full.
 568          *              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
 569          *              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
 570          *              OS_ERR_POST_NULL_PTR  If you are attempting to post a NULL pointer
 571          *
 572          * Warning    : Interrupts can be disabled for a long time if you do a 'broadcast'.  In fact, the
 573          *              interrupt disable time is proportional to the number of tasks waiting on the queue.
 574          *********************************************************************************************************
 575          */
 576          
 577          #if OS_Q_POST_OPT_EN > 0
 578          INT8U  OSQPostOpt (OS_EVENT *pevent, void *msg, INT8U opt) reentrant //using 0

⌨️ 快捷键说明

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