linuxbufferiio

No output from IIO (character) device output - IIO buffer


I'm working on a Linux driver for ADC ADS1243 and use the IIO framework. I want to add a feature to read and store data from the ADC to the IIO buffer.

I added iio_triggered_buffer_setup() to probe the function of the driver.

ret = iio_triggered_buffer_setup(indio_dev, NULL, &ads1243_trigger_handler, NULL);

I'm using the sysfs trigger, and ads1243_trigger_handler is successfully called.

static irqreturn_t ads1243_trigger_handler(int irq, void *p)
{
    struct iio_poll_func *pf = p;
    struct iio_dev *indio_dev = pf->indio_dev;
    struct ads1243_state *st = iio_priv(indio_dev);
    u32 val[8];
    int ret;

    val[0] = 0x01;
    val[1] = 0x02;
    val[2] = 0x03;
    val[3] = 0x04;

    ret = iio_push_to_buffers_with_timestamp(indio_dev, val,
                                       iio_get_time_ns());
    /* iio_push_to_buffers(indio_dev, val); */

    iio_trigger_notify_done(indio_dev->trig);

    return IRQ_HANDLED;
}

In the handler, I use just some test data pushed to the iio buffer.

Then I set up the trigger:

echo 0 > iio_sysfs_trigger/add_trigger
cat /sys/bus/iio/devices/trigger0/name > /sys/bus/iio/devices/iio:device1/trigger/current_trigger

Enable some scan elements, set up and enable the buffer for the iio device:

echo 1 > scan_elements/in_voltage0-voltage1_en
echo 1 > scan_elements/in_voltage2-voltage3_en

echo 64 > buffer/length
echo 1 > buffer/enable

Fire the trigger

echo 1 > /sys/bus/iio/devices/trigger0/trigger_now

And then try to read the device (buffer):

cat /dev/iio\:device1

But I didn't get any output. Am I missing something important?


Solution

  • The code is correct and working. I didn't realize that the cat command won't print invisible characters!

    Rather use hexdump, for example:

    cat /dev/iio:device1 | hexdump