原创 UCOS-II中消息队列学习笔记(3)

2011-12-7 22:41 1913 22 22 分类: MCU/ 嵌入式

 

4.向消息队列发送一则消息(FIFO)

INT8U  OSQPost (OS_EVENT *pevent,void *msg) reentrant

{

......................................

........................................

    OS_ENTER_CRITICAL();

    if (pevent->OSEventGrp !=0x00) {    /* See if any task pending onqueue  是否有任务在等待该消息队列           */

        OS_EventTaskRdy(pevent,msg, OS_STAT_Q);      /* Ready highestpriority task waiting on event  */

        OS_EXIT_CRITICAL();

        OS_Sched();                                   /* Find highestpriority task ready to run       */

        return (OS_NO_ERR);

    }

    pq = (OS_Q*)pevent->OSEventPtr;                 /* Point to queue control block                  */

    if (pq->OSQEntries >=pq->OSQSize) {  /*   消息队列当前消息数>=消息中可容纳的消息数                */

        OS_EXIT_CRITICAL();

        return (OS_Q_FULL);//返回消息队列已满

    }

    *pq->OSQIn++ = msg;                               /* Insertmessage into queue                     */

    pq->OSQEntries++;                                 /* Update thenbr of entries in the queue        */

    if (pq->OSQIn ==pq->OSQEnd) {                    /*Wrap IN ptr if we are at end of queue        */

        pq->OSQIn =pq->OSQStart;                  //构成环形队列

    }

    OS_EXIT_CRITICAL();

    return (OS_NO_ERR);

}

 

5.向消息队列发送一则消息(LIFO)

  if(pq->OSQOut == pq->OSQStart) {                 /*当插入指针=指针的起始地址(指针) */

       pq->OSQOut = pq->OSQEnd;                    //插入指针跳转到最后地址(指针)

    }

   pq->OSQOut--;                                                //插入指针减1   

*pq->OSQOut =msg; 

 

 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
22
关闭 站长推荐上一条 /1 下一条