Post Go back to editing

iio_buffer_push and iio_buffer_refill not behaving correctly.

Category: Software
Product Number: AD9361
Software Version: v0.35


I am working with the ADALM PLUTO, rev C, which reports to have an AD9361 chip. I am operating in 2R2T mode. I am writing a C program to control the SDR, running directly on the ZC7010 chip on board the pluto, cross-compiled from my dev machine, but I am having some trouble getting the data buffers to work in ways I expect them to. Low latency is imperative for my application, so I am working with relatively small buffers, say 10000 or 1000 samples at a time. I have a separate thread running that constantly submits buffers to the hardware using:

while (app_running){
int num = iio_buffer_push(root.tx.buf);
if (num <= 0) {printf("(tx_thread) Couldn't push buffer.\n");}
void *start = iio_buffer_start(root.tx.buf);
memcpy(iio_buffer_start(root.tx.buf), *buffer_pointer_pointer, iio_buffer_end(root.tx.buf) - start);

This will repeatedly perform a buffer push and then copy a previously created user-space buffer to the tx buffer before starting again.
Currently, I have the sample rate set to 5MHz and the buffer size to 5000 samples, so by my reasoning there should be one buffer submission per millisecond at most.
I read that the iio_buffer_push function is blocking if the kernel buffers are all queued to be read into the hardware. (I have set number of kernel buffers to 4).
However, if I time the loop, the loop is executed once every 120us or so, ie. almost 10 times quicker than it should.
1. what is happening to the data that I am submitting?
2. If the buffer submission isn't blocking, what can I do to make sure I am not overflowing the buffers?
When reading buffers from the rx device, I have the same issue - I can refill the buffer 20 times in succession all in less that a millisecond, but every time the number of bytes refilled is returned at the full buffer length.
3. How can I trust that the buffer refill is actually full of new samples?
4. What data is it giving me? How am I able to pull more data than is generated?
5. Maybe there's something wrong with the iio implementation? or the required HDL is not running on the PLUTO? How can I set that up to be correct?

I am running on the latest firmware release (v0.35), HDL untouched as far as I am aware, all I did was flash the boot image by dragging the entire zip folder provided over to to the usb mass storage device that the pluto exposes.
I have enabled 2R2T mode, as well as persistent ssh keys, if that is relevant.

This all would't be an issue if it weren't that I get gibberish values from the data buffers - between +- 5 for the entire buffer, despite transmitting strong signals. (currently simply connected RX to TX in a physical loopback).