AnsweredAssumed Answered

AD9361 iio_device_create_buffer fail on cyclic buffer error 22 : scan elements?

Question asked by HStoner on Aug 13, 2015
Latest reply on Aug 17, 2015 by pcercuei

The following simple libiio buffer creation is failing, apparently because the output scan elements haven't been enabled...



When I first initialize the AD9361 / SoCKit / ARRadio board, I'm trying to run a program that does a simple transmit of a cyclic waveform buffer.

Following the model of the 'ad9361-iiostream' program, the program creates an iio_context, gets the streaming device, configures some transmit parameters (frequency, sample rate, bandwidth, gain),  gets the streaming output channel, then enables the channel with:


   assert(get_ad9361_stream_ch(ctx, TX, tx, 0, &tx0_i) && "TX chan i not found");

   assert(get_ad9361_stream_ch(ctx, TX, tx, 1, &tx0_q) && "TX chan q not found");




After enabling the channel, it should then be able to create the cyclic output buffer, with :


   txbufCurr = iio_device_create_buffer(tx, BufNSamps, true);

   if (! txbufCurr) {

      printf("txbufCurr creation failed, errno = %d\n", errno);

      assert(txbufCurr && "TX buffer creation failed");



But this call to iio_device_create_buffer fails, with errno = 22 (invalid argument).


The strange thing is, that if I first run the program ad9361-iiostream, then run this test program, it works fine.

The difference I can see is that ad9361-iiostream is somehow enabling the scan element attributes in the scan_elements subdirectory...




When the test program above runs, it doesn't enable these files... but ad9361-iiostream does, for some reason... It looks like they get enabled if the buffer is NOT cyclic, but don't get enabled if it is?


I'm not 100% sure this is the problem, but I'm wondering if, in addition to calling iio_channel_enable() on the two output channels, I also have to force these two scan element attributes to the 'enabled' state, in order to have the iio_device_create_buffer() succeed when creating a cyclic buffer...  Is this required, and if so, why is it different for cyclic and non-cyclic buffers?