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

📄 os_q.lst

📁 编译环境是 iar EWARM ,STM32 下的UCOSII
💻 LST
📖 第 1 页 / 共 5 页
字号:
    507          
    508          
    509          #if OS_ARG_CHK_EN > 0
    510              if (perr == (INT8U *)0) {                              /* Validate 'perr'                          */
    511                  return (0);
    512              }
    513              if (pevent == (OS_EVENT *)0) {                         /* Validate 'pevent'                        */
    514                  *perr = OS_ERR_PEVENT_NULL;
    515                  return (0);
    516              }
    517          #endif
    518              if (pevent->OSEventType != OS_EVENT_TYPE_Q) {          /* Validate event block type                */
    519                  *perr = OS_ERR_EVENT_TYPE;
    520                  return (0);
    521              }
    522              OS_ENTER_CRITICAL();
    523              if (pevent->OSEventGrp != 0) {                         /* See if any task waiting on queue?        */
    524                  nbr_tasks = 0;
    525                  switch (opt) {
    526                      case OS_PEND_OPT_BROADCAST:                    /* Do we need to abort ALL waiting tasks?   */
    527                           while (pevent->OSEventGrp != 0) {         /* Yes, ready ALL tasks waiting on queue    */
    528                               (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q, OS_STAT_PEND_ABORT);
    529                               nbr_tasks++;
    530                           }
    531                           break;
    532                         
    533                      case OS_PEND_OPT_NONE:
    534                      default:                                       /* No,  ready HPT       waiting on queue    */
    535                           (void)OS_EventTaskRdy(pevent, (void *)0, OS_STAT_Q, OS_STAT_PEND_ABORT);
    536                           nbr_tasks++;
    537                           break;
    538                  }
    539                  OS_EXIT_CRITICAL();
    540                  OS_Sched();                                        /* Find HPT ready to run                    */
    541                  *perr = OS_ERR_PEND_ABORT;
    542                  return (nbr_tasks);
    543              }
    544              OS_EXIT_CRITICAL();
    545              *perr = OS_ERR_NONE;
    546              return (0);                                            /* No tasks waiting on queue                */
    547          }
    548          #endif
    549          
    550          /*$PAGE*/
    551          /*
    552          *********************************************************************************************************
    553          *                                        POST MESSAGE TO A QUEUE
    554          *
    555          * Description: This function sends a message to a queue
    556          *
    557          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
    558          *
    559          *              pmsg          is a pointer to the message to send.
    560          *
    561          * Returns    : OS_ERR_NONE           The call was successful and the message was sent
    562          *              OS_ERR_Q_FULL         If the queue cannot accept any more messages because it is full.
    563          *              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
    564          *              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
    565          *
    566          * Note(s)    : As of V2.60, this function allows you to send NULL pointer messages.
    567          *********************************************************************************************************
    568          */
    569          
    570          #if OS_Q_POST_EN > 0
    571          INT8U  OSQPost (OS_EVENT *pevent, void *pmsg)
    572          {
    573              OS_Q      *pq;
    574          #if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register     */
    575              OS_CPU_SR  cpu_sr = 0;
    576          #endif
    577          
    578          
    579          
    580          #if OS_ARG_CHK_EN > 0
    581              if (pevent == (OS_EVENT *)0) {                     /* Validate 'pevent'                            */
    582                  return (OS_ERR_PEVENT_NULL);
    583              }
    584          #endif
    585              if (pevent->OSEventType != OS_EVENT_TYPE_Q) {      /* Validate event block type                    */
    586                  return (OS_ERR_EVENT_TYPE);
    587              }
    588              OS_ENTER_CRITICAL();
    589              if (pevent->OSEventGrp != 0) {                     /* See if any task pending on queue             */
    590                                                                 /* Ready highest priority task waiting on event */
    591                  (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
    592                  OS_EXIT_CRITICAL();
    593                  OS_Sched();                                    /* Find highest priority task ready to run      */
    594                  return (OS_ERR_NONE);
    595              }
    596              pq = (OS_Q *)pevent->OSEventPtr;                   /* Point to queue control block                 */
    597              if (pq->OSQEntries >= pq->OSQSize) {               /* Make sure queue is not full                  */
    598                  OS_EXIT_CRITICAL();
    599                  return (OS_ERR_Q_FULL);
    600              }
    601              *pq->OSQIn++ = pmsg;                               /* Insert message into queue                    */
    602              pq->OSQEntries++;                                  /* Update the nbr of entries in the queue       */
    603              if (pq->OSQIn == pq->OSQEnd) {                     /* Wrap IN ptr if we are at end of queue        */
    604                  pq->OSQIn = pq->OSQStart;
    605              }
    606              OS_EXIT_CRITICAL();
    607              return (OS_ERR_NONE);
    608          }
    609          #endif
    610          /*$PAGE*/
    611          /*
    612          *********************************************************************************************************
    613          *                                   POST MESSAGE TO THE FRONT OF A QUEUE
    614          *
    615          * Description: This function sends a message to a queue but unlike OSQPost(), the message is posted at
    616          *              the front instead of the end of the queue.  Using OSQPostFront() allows you to send
    617          *              'priority' messages.
    618          *
    619          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
    620          *
    621          *              pmsg          is a pointer to the message to send.
    622          *
    623          * Returns    : OS_ERR_NONE           The call was successful and the message was sent
    624          *              OS_ERR_Q_FULL         If the queue cannot accept any more messages because it is full.
    625          *              OS_ERR_EVENT_TYPE     If you didn't pass a pointer to a queue.
    626          *              OS_ERR_PEVENT_NULL    If 'pevent' is a NULL pointer
    627          *
    628          * Note(s)    : As of V2.60, this function allows you to send NULL pointer messages.
    629          *********************************************************************************************************
    630          */
    631          
    632          #if OS_Q_POST_FRONT_EN > 0
    633          INT8U  OSQPostFront (OS_EVENT *pevent, void *pmsg)
    634          {
    635              OS_Q      *pq;
    636          #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
    637              OS_CPU_SR  cpu_sr = 0;
    638          #endif
    639          
    640          
    641          
    642          #if OS_ARG_CHK_EN > 0
    643              if (pevent == (OS_EVENT *)0) {                    /* Validate 'pevent'                             */
    644                  return (OS_ERR_PEVENT_NULL);
    645              }
    646          #endif
    647              if (pevent->OSEventType != OS_EVENT_TYPE_Q) {     /* Validate event block type                     */
    648                  return (OS_ERR_EVENT_TYPE);
    649              }
    650              OS_ENTER_CRITICAL();
    651              if (pevent->OSEventGrp != 0) {                    /* See if any task pending on queue              */
    652                                                                /* Ready highest priority task waiting on event  */
    653                  (void)OS_EventTaskRdy(pevent, pmsg, OS_STAT_Q, OS_STAT_PEND_OK);
    654                  OS_EXIT_CRITICAL();
    655                  OS_Sched();                                   /* Find highest priority task ready to run       */
    656                  return (OS_ERR_NONE);
    657              }
    658              pq = (OS_Q *)pevent->OSEventPtr;                  /* Point to queue control block                  */
    659              if (pq->OSQEntries >= pq->OSQSize) {              /* Make sure queue is not full                   */
    660                  OS_EXIT_CRITICAL();
    661                  return (OS_ERR_Q_FULL);
    662              }
    663              if (pq->OSQOut == pq->OSQStart) {                 /* Wrap OUT ptr if we are at the 1st queue entry */
    664                  pq->OSQOut = pq->OSQEnd;
    665              }
    666              pq->OSQOut--;
    667              *pq->OSQOut = pmsg;                               /* Insert message into queue                     */
    668              pq->OSQEntries++;                                 /* Update the nbr of entries in the queue        */
    669              OS_EXIT_CRITICAL();
    670              return (OS_ERR_NONE);
    671          }
    672          #endif
    673          /*$PAGE*/
    674          /*
    675          *********************************************************************************************************
    676          *                                        POST MESSAGE TO A QUEUE
    677          *
    678          * Description: This function sends a message to a queue.  This call has been added to reduce code size
    679          *              since it can replace both OSQPost() and OSQPostFront().  Also, this function adds the
    680          *              capability to broadcast a message to ALL tasks waiting on the message queue.
    681          *
    682          * Arguments  : pevent        is a pointer to the event control block associated with the desired queue
    683          *
    684          *              pmsg          is a pointer to the message to send.
    685          *
    686          *              opt           determines the type of POST performed:
    687          *                            OS_POST_OPT_NONE         POST to a single waiting task
    688          *                                                     (Identical to OSQPost())
    689          *                            OS_POST_OPT_BROADCAST    POST to ALL tasks that are waiting on the queue
    690          *                            OS_POST_OPT_FRONT        POST as LIFO (Simulates OSQPostFront())
    691          *                            OS_POST_OPT_NO_SCHED     Indicates that the scheduler will NOT be invoked
    692          *
    693          * Returns    : OS_ERR_NONE           The call was successful and the message was sent
    694          *              OS_ERR_Q_FULL         If the queue cannot accept any more messages because it is full.

⌨️ 快捷键说明

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