AnsweredAssumed Answered

Verifying digital loopback on AD9361 (Zed Board)

Question asked by tgm on Aug 15, 2017
Latest reply on Aug 16, 2017 by larsc
I want to test the the digital loopback in AD9361. I have modified the example from the official repository on Github (examples/ad9361-iiostream.c) to allow turning the loopback on by adding:
   iio_device* dev = iio_context_find_device(ctx, "ad9361-phy");
   if(nullptr == dev) {
       std::cout <<"No device ad9361-phy!\n";
       shutdown();
   }

   int const result = iio_device_debug_attr_write_longlong(dev, "loopback", 1L);
   std::cout <<"Loop-back " <<(0 == result ? "successfully" : "not") <<" turned on!\n";
just before the main while loop and analogous code that turns the loopback off in the shutdown() function. Additionally I have changed the buffer size from 1 MB to only 48 B and added logging in both for loops related with received and transmitted samples, i.e.,
std::cout <<"(" <<i <<"," <<q <<") ";
The TX buffer is filled with numbers starting from 300 to 347 (obviously shifted four bits to the left). However, what I observed in the RX buffer does not fully correspond to what is sent. The first four reads from the RX buffer seem to contain a random data. But I think this is normal. Starting at the fifth read, I observe the following (I, Q) components:
RX: (326,326) (327,327) (328,328) (329,329) (330,330) (331,331) (332,332) (333,333) (334,334) (335,335) (336,336) (337,337) (338,338) (339,339) (340,340) (341,341) (342,342) (343,343) (344,344) (345,345) (346,346) (347,347) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) 
RX: (328,328) (329,329) (330,330) (331,331) (332,332) (333,333) (334,334) (335,335) (336,336) (337,337) (338,338) (339,339) (340,340) (341,341) (342,342) (343,343) (344,344) (345,345) (346,346) (347,347) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) 
RX: (318,318) (319,319) (320,320) (321,321) (322,322) (323,323) (324,324) (325,325) (326,326) (327,327) (328,328) (329,329) (330,330) (331,331) (332,332) (333,333) (334,334) (335,335) (336,336) (337,337) (338,338) (339,339) (340,340) (341,341) (342,342) (343,343) (344,344) (345,345) (346,346) (347,347) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) (340,340) (341,341) 
What (in my opinion) should be received is:
(300, 300) (301, 301) ... (347, 347)
or at least this is exactly how the TX buffer looks like before calling iio_buffer_push.
Is it possible to somehow assure that received (I, Q) samples/data match the transmitted ones?
I am interested in more "packet"-based communication.
Is it important that at the end of the main while loop I add: std::this_thread::sleep_for(std::chrono::milliseconds(100));?
Am I missing something?
Obviously, I start the modified example as a root, since as far as I know the access to the debugfs is limited to the root only and turning the loopback feature on requires access to that system.
Libiio version
-------------------------
v0.10 (commit: c95ff6ab1a8b3112595068ed47a35ca75f490e29)
Linux version
-------------------------
analog@analog:~$ uname -a
Linux analog 4.0.0-g5e6cec4 #35 SMP PREEMPT Tue Mar 15 15:27:20 GMT 2016 armv7l armv7l armv7l GNU/Linux

analog@analog:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Linaro
Description: Linaro 14.04
Release: 14.04
Codename: trusty
Devices available on ZedBoard
-----------------------------------------------------
Device ID: iio:device0 Channels: 9 Device name: ad7291
Device ID: iio:device1 Channels: 11 Device name: ad9361-phy
Device ID: iio:device2 Channels: 9 Device name: xadc
Device ID: iio:device3 Channels: 12 Device name: cf-ad9361-dds-core-lpc
Device ID: iio:device4 Channels: 4 Device name: cf-ad9361-lpc
Cross compiler version
----------------------------------
tgm@asus:/opt/src/libiio$ arm-linux-gnueabihf-g++-4.8 --version
arm-linux-gnueabihf-g++-4.8 (Ubuntu/Linaro 4.8.4-2ubuntu1~14.04.1) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Outcomes