4

I am using IIO drivers from userspace to read the value of an ADC (AD7924). I have all steps to get a triggered acquisition working ( create a trigger, assign it, enable the ADC channels, set the dimension of the buffer, and enable it). Here is the code for this :

// Create IIO trigger
system("echo 0 > /sys/devices/iio_sysfs_trigger/add_trigger");

// Assign IIO trigger "sysfstrig0" to IIO AD7923 driver
system("echo sysfstrig0 > /sys/bus/iio/devices/iio:device0/trigger/current_trigger");

// Enable scan of the first 3 channels for AD7924
system("echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage0_en");
system("echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage1_en");
system("echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage2_en");
system("echo 0 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage3_en");

// Dim IIO buffer and enable it
sprintf(CommandeADC, "echo %d > /sys/bus/iio/devices/iio:device0/buffer/length", NB_ECH);
system(CommandeADC);
system("echo 1 > /sys/bus/iio/devices/iio:device0/buffer/enable");
//Launch acquisition...
system("echo 1 > /sys/bus/iio/devices/trigger0/trigger_now");

The system configured like this will process acquisition, and fill the complete buffer. Once it is full the acquisition stops.

My question is : how can I know when the buffer is fully filled ? I tried using poll or select function on the file iio:device0 located in /dev/ to check changes in the file descriptor , but I was only able to know when the acquisition started (by checking for POLLIN event).

dudu721
  • 342
  • 1
  • 3
  • 13

2 Answers2

0

To whom it may help, I ended up using recursive non blocking reading of the buffer file to read measures while acquisition is in process. This way, when I have read the expected number of samples, program can safely process them.

Also, it seems that disabling the buffer kind of wait the acquisition to complete befe the system can proceed another command :

     system("echo 0 > /sys/bus/iio/devices/iio:device0/buffer/enable");

This second solution is more a polling approach.

dudu721
  • 342
  • 1
  • 3
  • 13
0

Well, first of all such an approach does not scale. What if another IIO device is added to your system and device IDs change? I would recommend using libiio.

Regarding your question, i.e., how can I know when the buffer is fully filled?. This may depend on characteristics of both the buffer size and the device you use. For example, ADC converters may provide samples at different rate than thermometers, let alone more specialised devices.

I have never used it, but there is iio_buffer_get_poll_fd function in libiio. Check out: http://analogdevicesinc.github.io/libiio/group__Buffer.html.

shycha
  • 440
  • 5
  • 13