// User space program for reading the impulse count and frequency. // Source: http://linuxdevices.com/articles/AT9847654820.html // // Tested from 0 to 270 kHz. // Enhaced 2005-6 by Rolf Freitag #include #include #include #include #include #include #include #define FIFO_W "/dev/rtf0" #define FIFO_R "/dev/rtf1" int main () { int fd1, fd2, r; unsigned long long int dat[2]; const char zero = 0, one = 1; mlockall(MCL_CURRENT|MCL_FUTURE); fd1 = open (FIFO_W, O_WRONLY); fd2 = open (FIFO_R, O_RDONLY); assert (fd1 > 2); assert (fd2 > 2); for (;;) { write (fd1, &zero, 1); r = read (fd2, dat, sizeof (dat[0])); assert (r == sizeof (dat[0])); write (fd1, &one, 1); r = read (fd2, &dat[1], sizeof (dat[0])); assert (r == sizeof (dat[0])); printf ("Interrupt count = %llu, actual frequency = %llu Hz\n", dat[0], dat[1]); sleep (1); } close (fd1); close (fd2); return (0); }