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

📄 poll.c

📁 Vxworks的培训教程,大家分享下啊,
💻 C
字号:
#include "pioLib.h"IMPORT DAADIO	daadio;IMPORT PIO 		pio;void pioPoll (port, msgQId)	int port;	MSG_Q_ID msgQId;	{	PIO_MSG_Q_DATA 	msgQData;	UINT8 			currentState;	UINT8 			lastState[PIO_MAX_CHANNELS_PER_PORT];	int 			channel;		IMPORT int 		errno;	UINT8 *			pOutputEnablePort;	/* Error checking */	if (pio.initialized == FALSE)		{		printf ("pio not initialized\n");		return;		}	/* Fail if not an input port, i.e. if the corresponding bit in the	   output enable register is on */	pOutputEnablePort = (UINT8 *) daadio.baseAddr + PIO_OUTPUT_ENABLE_OFFSET;	if (*pOutputEnablePort & (1 << port))		{		printf ("Cannot poll an output port\n");		return;		}		/* Initialize our record of the last state of each channel to be OFF */	for (channel=0; channel<PIO_MAX_CHANNELS_PER_PORT; channel++)		lastState[channel] = OFF;	FOREVER		{		/* check each channel in port */		for (channel=0; channel<PIO_MAX_CHANNELS_PER_PORT; channel++)			{			/* Get the current state of the channel */			currentState = pioGet (port, channel);				/* Check to see if the current state differs from the state			   of the channel the last time we checked. If it is, we			   need to generated a message. */			if (lastState[channel] != currentState)				{				/* Initialize the message structure and send it. */				msgQData.port = port;				msgQData.channel = channel;				msgQData.state = currentState;				msgQData.timeStamp = tickGet();					if (msgQSend (msgQId, &msgQData, sizeof (PIO_MSG_Q_DATA),								 NO_WAIT, MSG_PRI_NORMAL) == ERROR)					{					/* If failure was because queue is full, just print					   warning and continue. Any other failure, print					   message and terminate. */					if (errno == S_objLib_OBJ_UNAVAILABLE)						printf ("Msg Queue full: dumping data for port %d, channel %d, status is %s at clock tick %d\n", port, channel, (currentState) ? "ON" :								"OFF", msgQData.timeStamp);					else						{						printf ("Msg Queue fatal error: aborting poll task\n");						return;						}					}								/* Update our record of the last state for this channel. */				lastState[channel] = currentState;				}			taskDelay (PIO_POLL_DELAY);			}		}	}

⌨️ 快捷键说明

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