Following the documentation from here: http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:gpio-sysfs I am trying to read a GPIO input efficiently, but, in the code below, only the first read() call works (returns 2) ; further call to read() returns 0 (ie nothing to read):
unsigned int i = 1000;
fd = open("/sys/class/gpio/gpio19/value", O_RDONLY);
while(i > 0)
if(read(fd, c, 2) < 0) break;
printf("c = %c\n", c);
If I close and reopen "/sys/class/gpio/gpio19/value" between each read(), it works as expected, but that's not efficient at all. How to do fast read() on a GPIO?
Note: I am using new GPIO sysfs interface on a BF537 with uClinux 2009R1.1.
P.S. for writing a GPIO there is no such problem: the file descriptor can stay opened and any write() will be effective.