VxWorks 任务间通信的简单例子

色郎中 2006-04-22 01:45:06
include "vxWorks.h"
#include "msgQLib.h"
#include "taskLib.h"
#include "timers.h"
#include "string.h"
#include "stdio.h"

void recvMSG_Task(void);
void sendMSG_Task(void);
void CreateTask(void);

MSG_Q_ID TestMSGQId;


void sendMSG_Task(void)
{
/* struct Tag_timespec
{
time_t tv_sec;
long tv_nsec;
}current_time;
*/
原来的 书中程序 注释掉了
struct timespec current_time; // 这个是我从新声明结构;

int maxMsgs;
int maxMsgLength;
int options;

long loop_num;
char MSGbuffer[64];
int timeout;
unsigned long CurrentTick;

maxMsgs=64;
maxMsgLength=1024;
options=MSG_Q_FIFO;
strcpy(MSGbuffer,"The Great China");
timeout=100;
TestMSGQId=msgQCreate(maxMsgs,maxMsgLength,options);
if(TestMSGQId==NULL)
{
printf("it is error for test msgQCreate!");
return;
}

for(loop_num=0;;loop_num++)
{
if(loop_num==0x1000000)
{
/*clock_gettime(CLOCK_REALTIME,(timespec *)&(current_time));*/ 这个是书中的原程序 有错误 编译不通过
clock_gettime(CLOCK_REALTIME,&(current_time)); 改了的
printf("current time is %d.\n",current_time.tv_nsec);
msgQSend(TestMSGQId,MSGbuffer,sizeof(MSGbuffer),timeout,MSG_PRI_NORMAL);
CurrentTick=tickGet();
printf("current tick is %d;current loop num is %d.\n",CurrentTick,loop_num);
clock_gettime(CLOCK_REALTIME,&(current_time)); // 这也是改了后的
printf("current time is %d.\n",current_time.tv_nsec);
loop_num=0;
}
}
printf("ERROR occurs is Task Sending MSG");
}


void recvMSG_Task(void)
{
int maxMsgs;
unsigned int maxBytes;
char MSGbuffer[64];
int timeout;
int revBytes;

maxMsgs=64;
maxBytes=1024;
timeout=100;

for(;;)
{
revBytes=msgQReceive(TestMSGQId,MSGbuffer,maxBytes,timeout);
if(0!=revBytes)
printf("recv msg is \n %s\n",MSGbuffer);
}
printf("ERROR occurs is Task Sending MSG");

}

void CreateTask(void)
{
int RetValue;
RetValue=taskSpawn("send MSG Task",100,VX_PRIVATE_ENV,512,(FUNCPTR)sendMSG_Task,0,0,0,0,0,0,0,0,0,0);

if (RetValue==ERROR)
printf("ERROR occurs is Task Ctreating");

RetValue=taskSpawn("recv MSG Task",100,VX_PRIVATE_ENV,512,(FUNCPTR)recvMSG_Task,0,0,0,0,0,0,0,0,0,0);

if (RetValue==ERROR)
printf("ERROR occurs is Task Ctreating");
}



这程序有错误,改动的地方 在程序中注释了
调试结果
正常 呵呵

tornado2.2 环境调试

...全文
860 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
nokiakobe 2006-08-06
  • 打赏
  • 举报
回复
为什么我调试就不对啊,ccsimpc -g -mpentium -ansi -fno-builtin -fno-defer-pop -I.. -ID:\Tornado\target\config\sim
pc -ID:\Tornado\target\h -ID:\Tornado\target\config\comps\src -ID:\Tornado\target\src\drv
-DCPU=SIMNT -DTOOL_FAMILY=gnu -DTOOL=gnu -DPRJ_BUILD -c F:\TaskMSG.c
F:\TaskMSG.c: In function `sendMSG_Task':
F:\TaskMSG.c:38: warning: assignment makes pointer from integer without a cast
F:\TaskMSG.c:62: parse error before `void'
F:\TaskMSG.c:72: `maxBytes' undeclared (first use in this function)
F:\TaskMSG.c:72: (Each undeclared identifier is reported only once
F:\TaskMSG.c:72: for each function it appears in.)
F:\TaskMSG.c:78: `revBytes' undeclared (first use in this function)
make: *** [TaskMSG.o] Error 0x1

Done.
请指教,在没看到你的帖子前我调过不对,按你的改后也不对,以上是结果
alixnuaa 2006-06-04
  • 打赏
  • 举报
回复
vxworks系统感觉不是很难的,主要是和具体项目应用起来,自己编的时候要设计好。
我现在刚刚接触这些东西,看别人写的一些程序,深入一点的是不是就是 BSP开发什么的?
月吻长河 2006-05-01
  • 打赏
  • 举报
回复
这个并不算vxWorks的特色
只要你熟悉UNIX进程间通信,用这个简直很快
sterrys 2006-04-24
  • 打赏
  • 举报
回复
最常用的还是 Message que, Semaphore

2,179

社区成员

发帖
与我相关
我的任务
社区描述
xworks是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统。
社区管理员
  • VxWorks开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧