📄 test.c
字号:
#include "vxWorks.h"#include "semLib.h"LOCAL SEM_ID testSemId;LOCAL int tid;STATUS setPortA () { if ((testSemId = semBCreate (SEM_Q_FIFO, SEM_FULL)) == NULL) return (ERROR); off (PORT_C); if ((tid = sp (testFunc)) == ERROR) return (ERROR); return (OK); }testFunc () { BOOL state = OFF; FOREVER { if (semTake (testSemId, WAIT_FOREVER) == ERROR) { printf ("testFunc fatal error\n"); return; } state != state; pioSet (PORT_C, 0, state); pioSet (PORT_C, 1, state); pioSet (PORT_C, 2, state); } }STATUS testNext (die) int die; { if (die) { td (tid); semDelete (testSemId); } else { if (semGive (testSemId) == ERROR) return (ERROR); } return (OK); }/* 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; { static int channel1 = LIGHT_0; static int channel2 = LIGHT_0; if (PIO_OFF (port, channel2) == ERROR) return (ERROR); if (PIO_ON (port, channel1) == ERROR) return (ERROR); channel2 = channel1; if (++channel1 >= MAX_LIGHTS) channel1 = LIGHT_0; 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 rotateCC (port) int port; { static int channel1 = MAX_LIGHTS - 1; static int channel2 = MAX_LIGHTS - 1; if (PIO_OFF (port, channel2) == ERROR) return (ERROR); if (PIO_ON (port, channel1) == ERROR) return (ERROR); channel2 = channel1; if (--channel1 < LIGHT_0) channel1 = MAX_LIGHTS -1; return (OK); }/**************************************************flash -- Turns all channels on, then all channels off.Program terminates after specified number of seconds have elapsed. **************************************************/flash (port) int port; { /* On/off state of the channels */ static BOOL state = ON; int channel; for (channel=LIGHT_0; channel<MAX_LIGHTS; channel++) { if (pioSet (port, channel, state) == ERROR) return (ERROR); } /* Invert state */ state = !state; 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; { /* On/off state of the channels */ static BOOL state = ON; int channel; for (channel=LIGHT_0; channel<LIGHT_0+MAX_LIGHTS; channel++) { if (pioSet (port, channel, state) == ERROR) return (ERROR); state = !state; } 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 + -