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

📄 test.c

📁 Vxworks的培训教程,大家分享下啊,
💻 C
字号:
/* test.c -- set of routines to help test drivers */#include "daadioLib.h"#include "pioLib.h"#define LIGHT_0				0			/* first channel */#define MAX_LIGHTS			3			/* number of channels */int seconds = 3;	 /* All the programs below (except the off 					  * routine) use this global variable to					  * determine their run time. *//**************************************************off -- turn channels off ***************************************************/off (port)	{	int i;	for (i=LIGHT_0; i<MAX_LIGHTS; i++)		PIO_OFF (port, i);	}/**************************************************rotate -- Turns channels 0 through 2, one by one,  on then off.Program terminates after specified number of seconds have elapsed.**************************************************/STATUS rotate (port)	int port;	{	/* Number of ticks that channel is on */	int delay = sysClkRateGet() / 3;	/* Value of system tick after specified seconds have elapsed */	int endTime = tickGet() + sysClkRateGet() * seconds;	int channel;	while (tickGet() < endTime)		{		for (channel=LIGHT_0; channel<LIGHT_0+MAX_LIGHTS; channel++)			{			if (PIO_ON (port, channel) == ERROR)				return (ERROR);			if (taskDelay (delay) == ERROR)				return (ERROR);			if (PIO_OFF (port, channel) == ERROR)				return (ERROR);			}		}	off(port);	return (OK);	}/*************************************************rotateCCDown -- Rotate through channels, turning them on thenoff, but in reverse order. After each cycle through channelsthe number of ticks that the channels are on are shortened by<inc> until they are , andthen increased.  Global interger <seconds> determine durationof routine.*************************************************/STATUS rotateCCDown (port)	int port;	{	/* Max number of ticks that channel is on */	int maxDelay = sysClkRateGet() / 3;	/* Min number of ticks that channel is on */	int minDelay = 5;	/* Actual number of ticks channels is on this cycle */	int delay = maxDelay;	/* Number of ticks delay is incremented each cycle */	int inc = -3;	/* Value of system tick after specified seconds have elapsed */	int endTime = tickGet() + sysClkRateGet() * seconds;	int channel;	while (tickGet() < endTime)		{		for (channel=MAX_LIGHTS-1; channel>=LIGHT_0; channel--)			{			if (PIO_ON (port, channel) == ERROR)				return (ERROR);			if (taskDelay (delay) == ERROR)				return (ERROR);			if (PIO_OFF (port, channel) == ERROR)				return (ERROR);			}			/* Increment the number of ticks delayed for next cycle */			delay += inc;			/* If delay reaches min or max, invert the sign of <inc> */			if (delay < minDelay || delay > maxDelay)				inc *= -1;		}	off(port);	return (OK);	}/*************************************************rotateDown -- Turns channels on and off, decreasing the number ofticks the channels are on until <minDelay> is reached. Then thenumber of ticks are increased until <maxDelay> is reached.*************************************************/STATUS rotateDown (port)	int port;	{	/* Number of ticks that channel is on */	int maxDelay = sysClkRateGet() / 3;	int minDelay = 5;	int delay = maxDelay;	int inc = -2;	/* Value of system tick after specified seconds have elapsed */	int endTime = tickGet() + sysClkRateGet() * seconds;	int channel;	while (tickGet() < endTime)		{		for (channel=LIGHT_0; channel<LIGHT_0+MAX_LIGHTS; channel++)			{			if (PIO_ON (port, channel) == ERROR)				return (ERROR);			if (taskDelay (delay) == ERROR)				return (ERROR);			if (PIO_OFF (port, channel) == ERROR)				return (ERROR);			}			delay += inc;			if (delay < minDelay || delay > maxDelay)				inc *= -1;		}	off(port);	return (OK);	}/**************************************************flash -- Turns all channels on, then all channels off.Program terminates after specified number of seconds have elapsed. **************************************************/flash (port)	int port;	{	/* Number of ticks that channel is on or off */	int delay = sysClkRateGet() / 3;	/* Value of system tick after specified seconds have elapsed */	int endTime = tickGet() + sysClkRateGet() * seconds;	/* On/off state of the channels */	UINT8 state = 1;	int channel;	while (tickGet() < endTime)		{		for (channel=LIGHT_0; channel<LIGHT_0+MAX_LIGHTS; channel++)			{			if (pioSet (port, channel, state) == ERROR)				return (ERROR);			}		/* Invert state */		state = !state;		if (taskDelay (delay) == ERROR)			return (ERROR);		}		off(port);		return (OK);	}/*************************************************blink -- Turns even numbered channels on, odd numbered channelsoff on first cycle. Then turns odd numbered channels on, and evennumbered channels off on second cycle and so on.*************************************************/blink (port)	int port;	{	/* Number of ticks that channel is on or off */	int delay = sysClkRateGet() / 3;	/* Value of system tick after specified seconds have elapsed */	int endTime = tickGet() + sysClkRateGet() * seconds;	/* On/off state of the channels */	UINT8 state = 1;	int channel;	while (tickGet() < endTime)		{		for (channel=LIGHT_0; channel<LIGHT_0+MAX_LIGHTS; channel++)			{			if (pioSet (port, channel, state) == ERROR)				return (ERROR);			state = !state;			}		if (taskDelay (delay) == ERROR)			return (ERROR);		}		off(port);		return (OK);	}/*************************************************blinkDown -- Same as blink, but first decreases the timeeach channel is on (until <minDelay> is reached), and thenincreases the time (until <maxDelay> is reached). Total timeprogram runs is defined by global variable <seconds>.*************************************************/blinkDown (port)	int port;	{	/* Number of ticks that channel is on or off */	int maxDelay = sysClkRateGet() / 3;	int minDelay = 5;	int delay = maxDelay;	/* Value of system tick after specified seconds have elapsed */	int endTime = tickGet() + sysClkRateGet() * seconds;	/* On/off state of the channels */	UINT8 state = 1;	int channel;	int inc = -1;	while (tickGet() < endTime)		{		for (channel=LIGHT_0; channel<LIGHT_0+MAX_LIGHTS; channel++)			{			if (pioSet (port, channel, state) == ERROR)				return (ERROR);			state = !state;			}		if (taskDelay (delay) == ERROR)			return (ERROR);		delay += inc;		if (delay < minDelay || delay > maxDelay)			inc *= -1;		}		off(port);		return (OK);	}/*************************************************all - Call all the above routines.*************************************************/all (port)	int port;	{	rotate (port);	rotateDown (port);	rotateCCDown (port);	blink (port);	blinkDown (port);	flash (port);	}

⌨️ 快捷键说明

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