admin 管理员组

文章数量: 887039

libiio

目录

参考资料

Ubuntu台机编译

交叉编译

libxml

libiio

CMakeLists.txt修改

编译

测试程序

iiod

iio_info

local方式

 IP方式

iio_attr

显示可用上下文

显示可用设备 

显示设备属性

 显示可用通道

显示通道属性

 IP方式显示可用设备

iio_readdev

local方式读取数据

IP方式显示读取数据

于libiio开发


参考资料

libiio

Ubuntu台机编译

Ubuntu 16.04.4 LTS系统, 使用cmake编译,禁用AIO、DNS_SD。

$ git clone .git
$ cd libiio
$ git log -1
commit 1e9e1647809bc0bdeab22753d7e61a22e4030d07
Author: Michael Hennerich <michael.hennerich@analog.com>
Date:   Thu Jul 22 13:37:57 2021 +0200bindings: python iio.py: find_device() also use labelWhen multiple devices with the same name exist, label is used todifferentiate them. Update find_device to also support labels.Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
$ mkdir build
$ cd build
$ cmake ../ -DWITH_AIO=OFF -DHAVE_DNS_SD=OFF
-- cmake version: 3.5.1
-- The C compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test HAS_WPEDANTIC
-- Performing Test HAS_WPEDANTIC - Success
-- Performing Test HAS_WSHADOW
-- Performing Test HAS_WSHADOW - Success
-- Looking for strdup
-- Looking for strdup - found
-- Looking for strndup
-- Looking for strndup - found
-- Looking for strerror_r
-- Looking for strerror_r - found
-- Looking for newlocale
-- Looking for newlocale - found
-- Looking for in6addr_any
-- Looking for in6addr_any - found
-- Looking for libusb-1.0 : Found
-- Looking for libusb_get_version
-- Looking for libusb_get_version - found
-- Found Git: /usr/bin/git (found version "2.7.4")
-- Building with Network back end support
-- Performing Test WITH_NETWORK_EVENTFD
-- Performing Test WITH_NETWORK_EVENTFD - Success
-- Building without DNS-SD (ZeroConf) support
-- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.3")
-- Found BISON: /usr/bin/bison (found version "3.0.4")
-- Found FLEX: /usr/bin/flex (found version "2.6.0")
-- Looking for pthread_setname_np
-- Looking for pthread_setname_np - found
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/work/libiio/build
$ make
Scanning dependencies of target iio
[  2%] Building C object CMakeFiles/iio.dir/backend.c.o
[  4%] Building C object CMakeFiles/iio.dir/channel.c.o
[  6%] Building C object CMakeFiles/iio.dir/device.c.o
[  9%] Building C object CMakeFiles/iio.dir/context.c.o
[ 11%] Building C object CMakeFiles/iio.dir/buffer.c.o
[ 13%] Building C object CMakeFiles/iio.dir/utilities.c.o
[ 15%] Building C object CMakeFiles/iio.dir/scan.c.o
[ 18%] Building C object CMakeFiles/iio.dir/sort.c.o
[ 20%] Building C object CMakeFiles/iio.dir/usb.c.o
[ 22%] Building C object CMakeFiles/iio.dir/local.c.o
[ 25%] Building C object CMakeFiles/iio.dir/libini/libini.c.o
[ 27%] Building C object CMakeFiles/iio.dir/network.c.o
[ 29%] Building C object CMakeFiles/iio.dir/network-unix.c.o
[ 31%] Building C object CMakeFiles/iio.dir/xml.c.o
[ 34%] Building C object CMakeFiles/iio.dir/lock.c.o
[ 36%] Building C object CMakeFiles/iio.dir/iiod-client.c.o
[ 38%] Linking C shared library libiio.so
[ 38%] Built target iio
Scanning dependencies of target iio_tests_helper
[ 40%] Building C object tests/CMakeFiles/iio_tests_helper.dir/iio_common.c.o
[ 43%] Building C object tests/CMakeFiles/iio_tests_helper.dir/gen_code.c.o
[ 45%] Linking C static library libiio_tests_helper.a
[ 45%] Built target iio_tests_helper
Scanning dependencies of target iio_attr
[ 47%] Building C object tests/CMakeFiles/iio_attr.dir/iio_attr.c.o
[ 50%] Linking C executable iio_attr
[ 50%] Built target iio_attr
Scanning dependencies of target iio_genxml
[ 52%] Building C object tests/CMakeFiles/iio_genxml.dir/iio_genxml.c.o
[ 54%] Linking C executable iio_genxml
[ 54%] Built target iio_genxml
Scanning dependencies of target iio_writedev
[ 56%] Building C object tests/CMakeFiles/iio_writedev.dir/iio_writedev.c.o
[ 59%] Linking C executable iio_writedev
[ 59%] Built target iio_writedev
Scanning dependencies of target iio_stresstest
[ 61%] Building C object tests/CMakeFiles/iio_stresstest.dir/iio_stresstest.c.o
[ 63%] Linking C executable iio_stresstest
[ 63%] Built target iio_stresstest
Scanning dependencies of target iio_info
[ 65%] Building C object tests/CMakeFiles/iio_info.dir/iio_info.c.o
[ 68%] Linking C executable iio_info
[ 68%] Built target iio_info
Scanning dependencies of target iio_readdev
[ 70%] Building C object tests/CMakeFiles/iio_readdev.dir/iio_readdev.c.o
[ 72%] Linking C executable iio_readdev
[ 72%] Built target iio_readdev
Scanning dependencies of target iio_reg
[ 75%] Building C object tests/CMakeFiles/iio_reg.dir/iio_reg.c.o
[ 77%] Linking C executable iio_reg
[ 77%] Built target iio_reg
Scanning dependencies of target iio_adi_xflow_check
[ 79%] Building C object tests/CMakeFiles/iio_adi_xflow_check.dir/iio_adi_xflow_check.c.o
[ 81%] Linking C executable iio_adi_xflow_check
[ 81%] Built target iio_adi_xflow_check
[ 84%] [FLEX][lexer] Building scanner with flex 2.6.0
[ 86%] [BISON][parser] Building parser with bison 3.0.4
Scanning dependencies of target iiod
[ 88%] Building C object iiod/CMakeFiles/iiod.dir/iiod.c.o
[ 90%] Building C object iiod/CMakeFiles/iiod.dir/ops.c.o
[ 93%] Building C object iiod/CMakeFiles/iiod.dir/thread-pool.c.o
[ 95%] Building C object iiod/CMakeFiles/iiod.dir/parser.c.o
[ 97%] Building C object iiod/CMakeFiles/iiod.dir/lexer.c.o
[100%] Linking C executable iiod
[100%] Built target iiod

交叉编译

libxml

$ ./configure CC=arm-linux-gnueabihf-gcc --host=arm-linux --with-lzma=no --with-zlib=no --with-python=no
$ make

libiio

CMakeLists.txt修改

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -379,6 +379,12 @@ if (WITH_XML_BACKEND)# on the CMake's FindLibXml2.cmake module (which can lack some definition, especially# in static build case).find_package(LibXml2 QUIET NO_MODULE)
+       set(LIBXML2_VERSION_STRING 2.9.7)
+       set(LIBXML2_FOUND yes)
+       set(LIBXML2_INCLUDE_DIR /opt/work/libxml2-2.9.7/include)
+       set(LIBXML2_LIBRARIES -lxml2)
+       link_directories("/opt/work/libxml2-2.9.7/.libs")
+if(DEFINED LIBXML2_VERSION_STRING)set(LIBXML2_FOUND ON)set(LIBXML2_INCLUDE_DIR ${LIBXML2_INCLUDE_DIRS})

编译

$ mkdir build
$ cd build
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake_toolchain -DWITH_USB_BACKEND=OFF -DHAVE_DNS_SD=OFF -DWITH_IIOD=OFF
-- cmake version: 3.5.1
-- The C compiler identification is GNU 6.3.1
-- Check for working C compiler: /opt/work/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /opt/work/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test HAS_WPEDANTIC
-- Performing Test HAS_WPEDANTIC - Success
-- Performing Test HAS_WSHADOW
-- Performing Test HAS_WSHADOW - Success
-- Looking for strdup
-- Looking for strdup - found
-- Looking for strndup
-- Looking for strndup - found
-- Looking for strerror_r
-- Looking for strerror_r - found
-- Looking for newlocale
-- Looking for newlocale - found
-- Looking for in6addr_any
-- Looking for in6addr_any - found
-- Found Git: /usr/bin/git (found version "2.7.4")
-- Building with Network back end support
-- Performing Test WITH_NETWORK_EVENTFD
-- Performing Test WITH_NETWORK_EVENTFD - Success
-- Building without DNS-SD (ZeroConf) support
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/work/libiio/build
$ make
Scanning dependencies of target iio
[  2%] Building C object CMakeFiles/iio.dir/backend.c.o
[  5%] Building C object CMakeFiles/iio.dir/channel.c.o
[  8%] Building C object CMakeFiles/iio.dir/device.c.o
[ 11%] Building C object CMakeFiles/iio.dir/context.c.o
[ 14%] Building C object CMakeFiles/iio.dir/buffer.c.o
[ 17%] Building C object CMakeFiles/iio.dir/utilities.c.o
[ 20%] Building C object CMakeFiles/iio.dir/scan.c.o
[ 22%] Building C object CMakeFiles/iio.dir/sort.c.o
[ 25%] Building C object CMakeFiles/iio.dir/local.c.o
[ 28%] Building C object CMakeFiles/iio.dir/libini/libini.c.o
[ 31%] Building C object CMakeFiles/iio.dir/network.c.o
[ 34%] Building C object CMakeFiles/iio.dir/network-unix.c.o
[ 37%] Building C object CMakeFiles/iio.dir/xml.c.o
[ 40%] Building C object CMakeFiles/iio.dir/lock.c.o
[ 42%] Building C object CMakeFiles/iio.dir/iiod-client.c.o
[ 45%] Linking C shared library libiio.so
[ 45%] Built target iio
Scanning dependencies of target iio_tests_helper
[ 48%] Building C object tests/CMakeFiles/iio_tests_helper.dir/iio_common.c.o
[ 51%] Building C object tests/CMakeFiles/iio_tests_helper.dir/gen_code.c.o
[ 54%] Linking C static library libiio_tests_helper.a
[ 54%] Built target iio_tests_helper
Scanning dependencies of target iio_attr
[ 57%] Building C object tests/CMakeFiles/iio_attr.dir/iio_attr.c.o
[ 60%] Linking C executable iio_attr
[ 60%] Built target iio_attr
Scanning dependencies of target iio_genxml
[ 62%] Building C object tests/CMakeFiles/iio_genxml.dir/iio_genxml.c.o
[ 65%] Linking C executable iio_genxml
[ 65%] Built target iio_genxml
Scanning dependencies of target iio_writedev
[ 68%] Building C object tests/CMakeFiles/iio_writedev.dir/iio_writedev.c.o
[ 71%] Linking C executable iio_writedev
[ 71%] Built target iio_writedev
Scanning dependencies of target iio_stresstest
[ 74%] Building C object tests/CMakeFiles/iio_stresstest.dir/iio_stresstest.c.o
[ 77%] Linking C executable iio_stresstest
[ 77%] Built target iio_stresstest
Scanning dependencies of target iio_info
[ 80%] Building C object tests/CMakeFiles/iio_info.dir/iio_info.c.o
[ 82%] Linking C executable iio_info
[ 82%] Built target iio_info
Scanning dependencies of target iio_readdev
[ 85%] Building C object tests/CMakeFiles/iio_readdev.dir/iio_readdev.c.o
[ 88%] Linking C executable iio_readdev
[ 88%] Built target iio_readdev
Scanning dependencies of target iio_reg
[ 91%] Building C object tests/CMakeFiles/iio_reg.dir/iio_reg.c.o
[ 94%] Linking C executable iio_reg
[ 94%] Built target iio_reg
Scanning dependencies of target iio_adi_xflow_check
[ 97%] Building C object tests/CMakeFiles/iio_adi_xflow_check.dir/iio_adi_xflow_check.c.o
[100%] Linking C executable iio_adi_xflow_check
[100%] Built target iio_adi_xflow_check

把相关文件上传至设备。

# ls -l|cut -c 58-iio_adi_xflow_check
iio_attr
iio_info
iio_readdev
iio_reg
iio_stresstest
iio_writedev
libiio.so -> libiio.so.0.21
libiio.so.0 -> libiio.so.0.21
libiio.so.0.21
libxml2.so -> libxml2.so.2.9.7
libxml2.so.2 -> libxml2.so.2.9.7
libxml2.so.2.9.7

测试程序

iiod

# ./iiod
Starting IIO Daemon version 0.21.1e9e164
New client connected from 192.168.1.2
New client connected from 192.168.1.2
WARNING: High-speed mode not enabled
Client exited
Client exited
New client connected from 192.168.1.109
New client connected from 192.168.1.109
WARNING: High-speed mode not enabled
Client exited
Client exited

iio_info

local方式

# ./iio_info
Library version: 0.21 (git tag: 1e9e164)
Compiled with backends: local xml ip
IIO context created with local backend.
Backend version: 0.21 (git tag: 1e9e164)
Backend description string: Linux ...
IIO context has 2 attributes:local,kernel: 4.19.111uri: local:
IIO context has 3 devices:...

 IP方式

# ./iio_info -u ip:127.0.0.1
Library version: 0.21 (git tag: 1e9e164)
Compiled with backends: local xml ip
IIO context created with network backend.
Backend version: 0.21 (git tag: 1e9e164)
Backend description string: 127.0.0.1 Linux RV1126_RV1109 4.19.111 #30 SMP PREEMPT Wed Jul 28 14:37:17 CST 2021 armv7l
IIO context has 3 attributes:local,kernel: 4.19.111uri: ip:127.0.0.1ip,ip-addr: 127.0.0.1
IIO context has 3 devices:...

iio_attr

显示可用上下文

# ./iio_attr -S
Available contexts:0: (lsm6dsl_accel, lsm6dsl_gyro, ff5e0000.saradc on Rockchip RV1126 EVB Board) [local:]

显示可用设备 

# ./iio_attr -d
IIO context has 3 devices:iio:device0, ff5e0000.saradc: found 0 device attributesiio:device1, lsm6dsl_accel: found 3 device attributesiio:device2, lsm6dsl_gyro: found 3 device attributes

显示设备属性

./iio_attr -d lsm6dsl_accel
dev 'lsm6dsl_accel', attr 'current_timestamp_clock', value :'realtime'
dev 'lsm6dsl_accel', attr 'sampling_frequency', value :'13'
dev 'lsm6dsl_accel', attr 'sampling_frequency_available', value :'13 26 52 104 208 416'

 显示可用通道

# ./iio_attr -c
IIO context has 3 devices:iio:device0, ff5e0000.saradc: found 6 channelsiio:device1, lsm6dsl_accel: found 4 channelsiio:device2, lsm6dsl_gyro: found 4 channels

显示通道属性

# ./iio_attr -c lsm6dsl_accel
dev 'lsm6dsl_accel', channel 'accel_x' (input, index: 0, format: le:S16/16>>0), found 3 channel-specific attributes
dev 'lsm6dsl_accel', channel 'accel_y' (input, index: 1, format: le:S16/16>>0), found 3 channel-specific attributes
dev 'lsm6dsl_accel', channel 'accel_z' (input, index: 2, format: le:S16/16>>0), found 3 channel-specific attributes
dev 'lsm6dsl_accel', channel 'timestamp' (input, index: 3, format: le:S64/64>>0), found 0 channel-specific attributes

 IP方式显示可用设备

# ./iio_attr -u ip:127.0.0.1 -d
IIO context has 3 devices:iio:device0, ff5e0000.saradc: found 0 device attributesiio:device1, lsm6dsl_accel: found 3 device attributesiio:device2, lsm6dsl_gyro: found 3 device attributes

iio_readdev

local方式读取数据

# ./iio_readdev -u local: lsm6dsl_accel
WARNING: High-speed mode not enabled
Unable to refill buffer: Connection timed out (110)# ./iio_readdev -b 8 lsm6dsl_accel
WARNING: High-speed mode not enabled

IP方式显示读取数据

#./iio_readdev -u ip:127.0.0.1 -b 4 lsm6dsl_accel | od -w16 -td2
0000000    581   -230  16188      0  -1555 -15158  -6320   5781
0000020    582   -242  16241      0  13117 -14009  -6320   5781
0000040    597   -245  16244      0   2789 -12861  -6320   5781

基于libiio开发

可参考exsamples、tests目录下的代码。

$ ls examples/
ad9361-iiostream.c  ad9371-iiostream.c  adrv9002-iiostream.c  adrv9009-iiostream.c  CMakeLists.txt  dummy-iiostream.c  iio-monitor.c  README.md
$ ls tests/
CMakeLists.txt  gen_code.h             iio_attr.c    iio_common.h  iio_info.c     iio_reg.c         iio_writedev.c
gen_code.c      iio_adi_xflow_check.c  iio_common.c  iio_genxml.c  iio_readdev.c  iio_stresstest.c

本文标签: libiio