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

📄 pipeserver.c

📁 以上两个程序是基于VxWorks嵌入式操作系统C源代码程序
💻 C
字号:
/* pipeServer.c - reads requests over pipe */

#include "vxWorks.h"
#include "pipeDrv.h"
#include "taskLib.h"
#include "ioLib.h"
void print(int ii);

typedef struct
	{
	VOIDFUNCPTR routine;
	int arg;
	} MSG_REQUEST;


#define TASK_PRI	254		/* server priority */
#define TASK_STACK	20000	/* server stack space */
#define PIPE_NAME	"/pipe/server"
#define NUM_MSGS	10

int pipeFd;
int i;

LOCAL void pipeServer ();
STATUS serverSend();
/**************************************************
* serverStart -- Initializes a server task to
* execute functons at a low priority. Uses pipes as
* the communication mechanism.
*
* RETURNS: OK or ERROR on failure.
*/

STATUS serverStart (void)
	{

	/* Create the pipe device */

	if (pipeDevCreate (PIPE_NAME, NUM_MSGS, sizeof (MSG_REQUEST)) == ERROR)
		return (ERROR);
	
	/* Open the pipe */

	if ((pipeFd = open (PIPE_NAME, UPDATE, 0)) == ERROR)
		return (ERROR);

	/* Spawn the server task */

	if (taskSpawn ("tServer", 253, 0, TASK_STACK,(FUNCPTR)pipeServer,
						0,0,0,0,0,0,0,0,0,0) == ERROR)
		{
		close (pipeFd);
		return (ERROR);
		}
	
	if (taskSpawn ("tSend", 254, 0, TASK_STACK,(FUNCPTR)serverSend,
						(FUNCPTR)print,1,0,0,0,0,0,0,0,0) == ERROR)
		{
		close (pipeFd);
		return (ERROR);
		}

	return (OK);
	}

/**************************************************
* serverSend -- Sends a request to the server to
* execute a function at the server's priority.
*
* RETURNS: OK or ERROR on failure.
*/

STATUS serverSend 
	(
	VOIDFUNCPTR routine,
	int arg
	)
	{
	MSG_REQUEST msgRequest;
	int status;

	/* Initialize the message structure */

	msgRequest.routine = routine;

for(i=1;i<10;i++)

{	msgRequest.arg = i;


	/* Send the message and return the results */

	status = write (pipeFd, (char *)&msgRequest, sizeof (MSG_REQUEST));


}
	return ((status == sizeof (MSG_REQUEST)) ?
	}

/**************************************************
* pipeServer -- Server task which reads from a pipe
* and executes the function passed in the
* MSG_REQUEST data structure.
*
*/

LOCAL void pipeServer (void)
	{
	MSG_REQUEST msgRequest;
int j;
for(j=1;j<10;j++)

{	while (read (pipeFd, (char *)&msgRequest, sizeof (MSG_REQUEST)) > 0)
		(*msgRequest.routine) (msgRequest.arg);
}
	
}


void print(int ii)
{
printf("Hello,I am task %d\n\n",ii);
}

⌨️ 快捷键说明

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