简体   繁体   English

IIO Linux:如何知道缓冲区何时已满?

[英]IIO Linux : How to know when the buffer is full?

I am using IIO drivers from userspace to read the value of an ADC (AD7924). 我正在使用来自用户空间的IIO驱动程序来读取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). 我已经完成了触发采集工作的所有步骤(创建触发器,分配它,启用ADC通道,设置缓冲区的维度,并启用它)。 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). 我尝试在位于/ dev /中的文件iio:device0上使用poll或select函数来检查文件描述符中的更改,但我只能知道何时开始采集(通过检查POLLIN事件)。

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. 第二种解决方案更像是一种轮询方法。

Well, first of all such an approach does not scale. 嗯,首先这种方法不能扩展。 What if another IIO device is added to your system and device IDs change? 如果系统中添加了另一个IIO设备并且设备ID发生了变化,该怎么办? I would recommend using libiio . 我建议使用libiio

Regarding your question, ie, 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. 例如,ADC转换器可以提供与温度计不同速率的采样,更不用说更专业的设备。

I have never used it, but there is iio_buffer_get_poll_fd function in libiio . 我从未使用它,但在libiioiio_buffer_get_poll_fd函数。 Check out: http://analogdevicesinc.github.io/libiio/group__Buffer.html . 查看: http//analogdevicesinc.github.io/libiio/group__Buffer.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM