User`s manual
UC-7408 User’s Manual Programmer’s Guide
5-16
#include <unistd.h>
#include <pthread.h>
#include <moxadevice.h>
#ifdef DEBUG
#define dbg_printf(x...) printf(x)
#else
#define dbg_printf(x...)
#endif
#define DURATION_NUM 7
#define TEST_NUM 10
static int ndin_StateChangeDetected, ndout_StateChangeDetected;
static int nDuration;
static unsigned long duration[2][DURATION_NUM]={ { 50, 40, 35, 30, 25, 20, 15 }, { 160,
140, 120, 100, 80, 60, 40, } };
/********************************************************************
When the din state changed form high to low, this function will be invoked
********************************************************************/
static void low2highevent(int diport)
{
ndin_StateChangeDetected++;
dbg_printf("din state changed:%d\n",ndin_StateChangeDetected);
}
/********************************************************************
This function is used to exchange the dout state periodically
********************************************************************/
void dout_control(int signo)
{
int state;
get_dout_state(0, &state);
dbg_printf("dout state changed:%d\n",state);
if(state) // exchange the dout state periodically
{
ndout_StateChangeDetected++;
set_dout_state(0, 0);
}
else
{
set_dout_state(0, 1);
}
}
void dio_test_function(void )
{
struct itimerval value;
int j, i, nChoice;
struct timeval tv;
do {
printf("0.Test for Din duration==0.\n");
printf("1.Test for Din duration!=0.\n");
printf("9.Quit.\n" );
printf("Please select a choice>");
scanf("%d",&nChoice);
if( nChoice == 9 ){ // Quit
break;
}
else if( nChoice == 0 ){ //test for din duration==0
for ( nDuration=0; nDuration < DURATION_NUM; nDuration++ ) {