Beaglebone Black: Reading GPIO at High Frequencies

I would like to continuously read the status of an IO line on my Beaglebone black. The code I pasted below is a section of my software looking for rising and falling edges. Is there a way in Linux to read the status of that line without having to open and close the same file that is faster? The method I have below works, but only at really low frequencies.

I am trying to read the IO approx. 15kHz.

Thanks

while( buf[0]==‘0’ ) {
memset(adc_drdy, 0, sizeof(adc_drdy) );

if((j = fopen ( “/sys/class/gpio/gpio65/value”, “r” )) == NULL) {
//printSerial(“Unable to read input file”);
}
else {
fgets(adc_drdy, sizeof(adc_drdy), j);
strcpy(buf, adc_drdy);
//fprintf(j, “%s”, adc_drdy);
fclose(j);
}
system(“echo 0 > /sys/class/gpio/gpio61/value”);
printf("%c\n", buf[0]);
//if(ADC_DRDY==‘1’) break;
}

while( buf[0]==‘1’ ) {

memset(adc_drdy, 0, sizeof(adc_drdy) );
if((j = fopen ( “/sys/class/gpio/gpio65/value”, “r” )) == NULL) {
//printSerial(“Unable to read input file”);
}
else {
fgets(adc_drdy, sizeof(adc_drdy), j);
strcpy(buf, adc_drdy);
//fprintf(j, “%s”, adc_drdy);
fclose(j);
}
system(“echo 1 > /sys/class/gpio/gpio61/value”);
printf("%c\n", buf[0]);
//if(ADC_DRDY==‘0’) break;
}

I would like to continuously read the status of an IO line on my Beaglebone black. The code I pasted below is a section of my software looking for rising and falling edges. Is there a way in Linux to read the status of that line without having to open and close the same file that is faster? The method I have below works, but only at really low frequencies.

I am trying to read the IO approx. 15kHz.

Doing this from user space using the SYS filesystem is going to be slow. You have two options in Linux:

  1. Use mmap and read/write directly the GPIO registers
  2. Use a kernel module or device driver to read/write the GPIO registers
    However, even at 15KHz, the Linux kernel will be too slow because of scheduling and interrupt latency. I suggest you try to do the high speed stuff with the PRU and then interface with Linux for the high level data manipulations.

Regards,
John

Thanks for the quick response. I will definitely look into it

Check out libpruio. It’s designed for that purpose and contains a C wrapper.