#include <vxWorks.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <semLib.h>
#include <taskLib.h>
#include <msgQLib.h>
#include <logLib.h>
#include <ioLib.h>
#define MAX_MSGS 10
#define MAX_MSG_LEN 100
#define DELAY_TICKS 50
#define STACK_SIZE 20000
int taskManage;
int taskSingal;
int taskSend;
int taskRev;
int i=1;
/*定义信号量,消息队列*/
SEM_ID synSemId;
MSG_Q_ID msgQId1;
MSG_Q_ID msgQId2;
MSG_Q_ID msgQId3;
MSG_Q_ID msgQId4;
/*函数声明*/
STATUS progStart(void);
STATUS tManage(void);
STATUS tSingal(void);
STATUS tSend(void);
STATUS tRev(void);
/*创建各种信号量、任务、消息队列*/
STATUS progStart(void)
{
synSemId=semBCreate(SEM_Q_FIFO,SEM_EMPTY); /*创建信号量*/
/*创建四个任务*/
taskManage = taskSpawn("taskManage", 200, 0, STACK_SIZE, (FUNCPTR)tManage,0,0,0,0,0,0,0,0,0,0);
taskSingal = taskSpawn("taskSingal", 130, 0, STACK_SIZE, (FUNCPTR)tSingal,0,0,0,0,0,0,0,0,0,0);
taskSend = taskSpawn("taskSend", 130, 0, STACK_SIZE, (FUNCPTR)tSend,0,0,0,0,0,0,0,0,0,0);
taskRev = taskSpawn("taskRev", 130, 0, STACK_SIZE, (FUNCPTR)tRev,0,0,0,0,0,0,0,0,0,0);
/*创建消息队列*/
msgQId1=msgQCreate(MAX_MSGS,MAX_MSG_LEN,MSG_Q_PRIORITY);
msgQId2=msgQCreate(MAX_MSGS,MAX_MSG_LEN,MSG_Q_PRIORITY);
msgQId3=msgQCreate(MAX_MSGS,MAX_MSG_LEN,MSG_Q_PRIORITY);
msgQId4=msgQCreate(MAX_MSGS,MAX_MSG_LEN,MSG_Q_PRIORITY);
return(OK);
}
/*taskManage管理函数*/
STATUS tManage(void)
{
char msgbuf[50] = {'\0'};
char msgexit[50]= "exit";
taskDelay(DELAY_TICKS);
printf("The initial has done!\n");
semFlush(synSemId);
FOREVER
{
msgQReceive(msgQId1, msgbuf, MAX_MSG_LEN, WAIT_FOREVER);
if(strcmp(msgbuf,msgexit)==0)
{
logMsg("\nThe system will be ended\n",0,0,0,0,0,0);
semDelete(synSemId);
taskDelete(taskSingal);
taskDelete(taskSend);
taskDelete(taskRev);
logMsg("\nGoodbye!\n",0,0,0,0,0,0);
taskDelete(taskManage);
}
else
{
logMsg(msgbuf,0,0,0,0,0,0);
}
}
}
/*开始信号激励函数*/
STATUS tSingal(void)
{
printf("The system is initialling...\n");
printf("Task2 initialization is OK!\n");
semTake(synSemId,WAIT_FOREVER);
for(i;i<=20;i++)
{
if(msgQSend(msgQId3, "begin", sizeof("begin"), WAIT_FOREVER, MSG_PRI_NORMAL) == ERROR)
return(ERROR);
if(msgQSend(msgQId4, "begin", sizeof("begin"), WAIT_FOREVER, MSG_PRI_NORMAL) == ERROR)
return(ERROR);
taskDelay(DELAY_TICKS);
}
if(msgQSend(msgQId1, "exit", sizeof("exit"), WAIT_FOREVER, MSG_PRI_NORMAL) == ERROR)
return ERROR;
}
STATUS tSend(void)
{
char msgBuf[20];
char msgErro[50] = "The message is erro!\n";
printf("Task3 initialization is OK!\n");
semTake(synSemId,WAIT_FOREVER);
FOREVER
{
if(msgQReceive(msgQId3, msgBuf, MAX_MSG_LEN, WAIT_FOREVER) == ERROR)
return(ERROR);
if((strlen(msgBuf)!=0)&&(strcmp(msgBuf,"begin"))==0)
{
printf("The task3 received message from the task2 is:");
printf("%s",msgBuf);
printf("\n");
}
if(msgQSend(msgQId4, "Sending", sizeof("Sending"), WAIT_FOREVER, MSG_PRI_NORMAL) == ERROR)
return(ERROR);
if((strlen(msgBuf)!=0)&&(strcmp(msgBuf,"Receiving"))==0)
{
printf("The task3 received message from the task4 is:");
printf("%s",msgBuf);
printf("\n");
}
else
if(msgQSend(msgQId1, msgErro, sizeof(msgErro), WAIT_FOREVER, MSG_PRI_NORMAL) == ERROR)
return(ERROR);
memset(msgBuf,0,20);
}
return (OK);
}
/*接收回复函数*/
STATUS tRev(void)
{
char msgBuf[20];
char msgErro[50] = "The message is erro!\n";
printf("Task4 initialization is OK!\n");
semTake(synSemId,WAIT_FOREVER);
FOREVER
{
if(msgQReceive(msgQId4, msgBuf, MAX_MSG_LEN, WAIT_FOREVER) == ERROR)
{
return(ERROR);
}
if((strlen(msgBuf)!=0)&&(strcmp(msgBuf,"begin"))==0)
{
printf("The task4 received message from the task2 is:");
printf("%s",msgBuf);
printf("\n");
}
if((strlen(msgBuf)!=0)&&(strcmp(msgBuf,"Sending"))==0)
{
printf("The task4 received message from the task3 is:");
printf("%s",msgBuf);
printf("\n");
if(msgQSend(msgQId3, "Receiving", sizeof("Receiving"), WAIT_FOREVER, MSG_PRI_NORMAL) == ERROR)
return(ERROR);
}
}
return (OK);
}
邓凌佳
- 粉丝: 79
- 资源: 1万+
最新资源
- 基于大数据环境搭建,本项目为大数据基础镜像组件,Hadoop、Spark、Hive、Tez、Hue、Flink、Zookeeper、Kafka、MySQL等,用
- 基于开源的flink,对其实时sql进行扩展;主要实现了流与维表的join,支持原生flink SQL所有的语法详细文档+全部资料.zip
- 基于开源flink,源码阅读注释详细文档+全部资料.zip
- 基于微服务架构的实时计算(Flink)展示平台详细文档+全部资料.zip
- 工具4:股权激励如何实施.xls
- 天津滨海快速交通发展有限公司股权激励机制探讨2.ppt
- 某某交通股份有限公司高层股权激励方案.doc
- 话费管理规定.docx
- 话费补贴申请书.doc
- 交通补贴及移动话费补贴政策.doc
- 话费补贴管理制度.doc
- 电话费补贴管理办法(暂行).doc
- 话费补助管理制度.doc
- 员工话费补贴管理制度.doc
- 手机补贴标准管理办法.doc
- 加班与加班费的控制技巧.ppt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈