[LinuxPPS] select() on /dev/pps
Xavier Bestel
xavier.bestel at free.fr
Thu Jul 30 10:00:25 CEST 2015
I forgot the kernel version I'm using:
Linux lmde 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt7-1 (2015-03-01)
x86_64 GNU/Linux
Xav
Le 30/07/2015 09:39, Xavier Bestel a écrit :
> Hi,
>
> for an application of mine I would need to be able to wait for events
> on a char device and on a PPS device; on the char device the select()
> call is the obvious candidate, but it doesn't seem to work on the PPS
> device. That is, select() always returns immediately telling some data
> is available, and a PPS_FETCH either returns immediately if flags=0 or
> waits for 1s if flags=PPS_TIME_INVALID;
>
> That looks wrong to me. IMHO select() should wait for 1s and PPS_FETCH
> should "consume" the data without waiting.
> If it should work, could you tell me where is my code wrong ?
>
> Thanks,
>
> Xav
>
>
> #include <sys/select.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <linux/pps.h>
>
> int main(int argc, char *argv[])
> {
> if(argc != 2) {
> fprintf(stderr, "usage: %s device\n", argv[0]);
> exit(1);
> }
> int fd = open(argv[1], O_RDWR);
> if(fd < 0) {
> fprintf(stderr, "error opening %s: %m\n", argv[1]);
> exit(1);
> }
> fd_set set;
> while(1) {
> struct timeval tv;
> tv.tv_sec = 2;
> tv.tv_usec = 0;
> FD_ZERO(&set);
> FD_SET(fd, &set);
> int sel = select(fd + 1, &set, NULL, NULL, &tv);
> printf("select returns %d\n", sel);
> if(FD_ISSET(fd, &set)) {
> struct pps_fdata fdata;
> fdata.timeout.sec = 0;
> fdata.timeout.nsec = 0;
> fdata.timeout.flags = PPS_TIME_INVALID; // or 0
> if(ioctl(fd, PPS_FETCH, &fdata) < 0) {
> fprintf(stderr, "no PPS : %m");
> exit(1);
> }
> printf("fetch returns\n");
> }
> }
> return 0;
> }
>
> _______________________________________________
> discussions mailing list
> discussions at linuxpps.org
> http://www.linuxpps.org/cgi-bin/mailman/listinfo/discussions
> Wiki: http://wiki.enneenne.com/index.php/LinuxPPS_support
>
More information about the discussions
mailing list