我正在使用来自用户空间的 IIO 驱动程序来读取 ADC (AD7924) 的值。我已经完成了触发采集工作的所有步骤(创建触发器、分配它、启用 ADC 通道、设置缓冲区的尺寸并启用它)。这是此的代码:
// 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");
像这样配置的系统将处理采集,并填充完整的缓冲区。一旦它已满,采集停止。
我的问题是:我怎么知道缓冲区何时已满?我尝试在/dev/中的文件iio:device0上使用 poll 或 select 函数来检查文件描述符的变化,但我只能知道采集何时开始(通过检查 POLLIN 事件)。