/**************************************************************************** ** parint_nice.c - The interface to the parint driver is ioctl(). It has an ** ugly interface. This parint_nice.c file provides a nicer interface to ** the driver calls. **************************************************************************** */ #define EXTERN extern /*------------------------ ** Include files **------------------------ */ #include #include #include #include #include #include #include /*---------------------------------------------------------------------- ** parint_get_time() - Get timestamp data from parint ** returns: ** 0 = no error ** ENOMEM - unable to malloc() need data. ** ETIMEOUT - timer expired, no data. **---------------------------------------------------------------------- */ int parint_get_time( int fd, // fd to driver unsigned int * i_cnt, // O: i_cnt - interrupt count int * num_ret, // O: number of time copied to tv[] struct timeval * tv, // 0: copy data here. int max_tv // I: max size of tv[] ) { struct parint_parms_t p; p.p[0] = i_cnt; p.p[1] = num_ret; p.p[2] = tv; p.l[0] = max_tv; ioctl( fd, PARINT_IOCTL_GET_TIME, &p ); return p.ret; } /*---------------------------------------------------------------------- ** parint_flush() - flushes timestamp data in the driver. **---------------------------------------------------------------------- */ int parint_flush( int fd // fd to driver ) { struct parint_parms_t p; ioctl( fd, PARINT_IOCTL_FLUSH, &p ); return p.ret; } /*---------------------------------------------------------------------- ** parint_pulse() - Test/debug function to toggle output bits. **---------------------------------------------------------------------- */ int parint_pulse( int fd, struct timeval *tv) { struct parint_parms_t p; p.p[0] = tv; // returns timestamp to caller. ioctl( fd, PARINT_IOCTL_PULSE, &p ); return p.ret; } /*---------------------------------------------------------------------- ** parint_oneshot_clear() - clears and enable oneshot **---------------------------------------------------------------------- */ int parint_oneshot_clear( int fd ) { struct parint_parms_t p; ioctl( fd, PARINT_IOCTL_ONESHOT_CLEAR, &p ); return p.ret; } /*---------------------------------------------------------------------- ** parint_oneshot_get() - gets the oneshot data. **---------------------------------------------------------------------- */ int parint_oneshot_get( int fd, int * has_data, struct timeval *tv ) { struct parint_parms_t p; p.p[0] = has_data; // returns 'has_data' flag. p.p[1] = tv; // returns timestamp to caller. ioctl( fd, PARINT_IOCTL_ONESHOT_GET, &p ); return p.ret; } /*---------------------------------------------------------------------- ** parint_t1() - ioctl_t1() - test1 **---------------------------------------------------------------------- */ int parint_t1( int fd ) { struct parint_parms_t p; ioctl( fd, PARINT_IOCTL_T1, &p ); return p.ret; } /*---------------------------------------------------------------------- ** parint_t2() - ioctl_t2() - test2 **---------------------------------------------------------------------- */ int parint_t2( int fd, unsigned char *uc ) { struct parint_parms_t p; p.p[0] = uc; // returns data to caller.. should be uchar uc[3]; ioctl( fd, PARINT_IOCTL_T2, &p ); return p.ret; }