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

📄 mymsgq.c

📁 vxWorks下的消息队列程序
💻 C
字号:
/* In this example, task t1 creates the message queue and sends a message 
 * to task t2. Task t2 receives the message from the queue and simply 
 * displays the message. 
 */
 
/* includes */ 
#include "vxWorks.h" 
#include "msgQLib.h"
 
/* defines */ 
#define MAX_MSGS (10) 
#define MAX_MSG_LEN (100)
 
MSG_Q_ID myMsgQId;

task3(void)
{
/* create message queue */
    if ((myMsgQId = msgQCreate (MAX_MSGS, MAX_MSG_LEN, MSG_Q_PRIORITY))  
        == NULL) 
        return (ERROR);
  
}
 
task2 (void) 
    { 
    char msgBuf[MAX_MSG_LEN];
 
 
    /* get message from queue; if necessary wait until msg is available */ 
    if (msgQReceive(myMsgQId, msgBuf, MAX_MSG_LEN, WAIT_FOREVER) == ERROR) 
        return (ERROR);
 
    /* display message */ 
    printf ("Message from task 1:\n%s\n", msgBuf); 
    }
 
#define MESSAGE "Greetings from Task 1" 
task1 (void) 
    { 

   if (msgQSend (myMsgQId, MESSAGE, MAX_MSG_LEN, WAIT_FOREVER, 
                  MSG_PRI_NORMAL) == ERROR) 
        return (ERROR); 

    /* send a normal priority message, blocking if queue is full
    if (msgQSend (myMsgQId, MESSAGE, sizeof (MESSAGE), WAIT_FOREVER, 
                  MSG_PRI_NORMAL) == ERROR) 
        return (ERROR); 
     */
    }
 
void mymsgQ(void)
{
taskSpawn("t3",100,0,0x20000,(FUNCPTR)task3,0,0,0,0,0,0,0,0,0,0);
taskSpawn("t2",100,0,0x20000,(FUNCPTR)task2,0,0,0,0,0,0,0,0,0,0);
taskSpawn("t1",100,0,0x20000,(FUNCPTR)task1,0,0,0,0,0,0,0,0,0,0);
}


myprint()
{
printf("Hello world\n");
}

⌨️ 快捷键说明

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