×

AD5933 IIO阻抗转换器和网络分析仪Linux驱动程序

消耗积分:3 | 格式:pdf | 大小:190.95KB | 2021-04-14

分享资料个

This version (17 Jan 2018 13:40) was approved by Alexandru Ardelean.The Previously approved version (20 Nov 2015 11:01) is available.Diff

AD5933 IIO Impedance Converter and Network Analyzer Linux Driver

Supported Devices

Evaluation Boards

Reference Circuits

Description

This is a Linux industrial I/O (IIO) subsystem driver, targeting Impedance Converters and Network Analyzers. The industrial I/O subsystem provides a unified framework for drivers for many different types of converters and sensors using a number of different physical interfaces (i2c, spi, etc). See IIO for more information.

Source Code

Status

Source Mainlined?
git Yes

Files

Example platform device initialization

For compile time configuration, it’s common Linux practice to keep board- and application-specific configuration out of the main driver file, instead putting it into the board support file.

For devices on custom boards, as typical of embedded and SoC-(system-on-chip) based hardware, Linux uses platform_data to point to board-specific structures describing devices and how they are connected to the SoC. This can include available ports, chip variants, preferred modes, default initialization, additional pin roles, and so on. This shrinks the board-support packages (BSPs) and minimizes board and application specific #ifdefs in drivers.

21 Oct 2010 16:10

The reference voltage or external reference clock may vary between boards and models. The platform_data for the device's “struct device” holds this information.

File: drivers/staging/iio/impedance-analyzer/ad5933.h:ad5933_platform_data

/**
 * struct ad5933_platform_data - platform specific data
 * @ext_clk_Hz:		the external clock frequency in Hz, if not set
 *			the driver uses the internal clock (16.776 MHz)
 * @vref_mv:		the external reference voltage in millivolt
 */
 
struct ad5933_platform_data {
	unsigned long			ext_clk_Hz;
	unsigned short			vref_mv;
};
static struct ad5933_platform_data ad5933_pdata  = {
	.vref_mv = 3300,
};

In case platform_data is not present or set to NULL, the driver will use the AD5933 internal 16.776MHz reference clock.

Declaring I2C devices

Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each I2C bus segment, and what address these devices are using. For this reason, the kernel code must instantiate I2C devices explicitly. There are different ways to achieve this, depending on the context and requirements. However the most common method is to declare the I2C devices by bus number.

This method is appropriate when the I2C bus is a system bus, as in many embedded systems, wherein each I2C bus has a number which is known in advance. It is thus possible to pre-declare the I2C devices that inhabit this bus. This is done with an array of struct i2c_board_info, which is registered by calling i2c_register_board_info().

So, to enable such a driver one need only edit the board support file by adding an appropriate entry to i2c_board_info.

For more information see: Documentation/i2c/instantiating-devices

21 Oct 2010 16:10

Depending on the converter IC used, you may need to set the I2C_BOARD_INFO name accordingly, matching your part name.

ADI part number I2C_BOARD_INFO Name
AD5933 ad5933
AD5934 ad5934
static struct i2c_board_info __initdata board_i2c_board_info[] = {
#if defined(CONFIG_AD5933) || defi
ned(CONFIG_AD5933_MODULE)
	{
		I2C_BOARD_INFO("ad5933", 0x0D),
		.platform_data = (void *)&ad5933_pdata, /* optional */
	},
#endif
};
static int __init board_init(void)
{
	[--snip--]
 
	i2c_register_board_info(0, board_i2c_board_info,
				ARRAY_SIZE(board_i2c_board_info));
	[--snip--]
 
	return 0;
}
arch_initcall(board_init);

Adding Linux driver support

Configure kernel with “make menuconfig” (alternatively use “make xconfig” or “make qconfig”)

The driver depends on CONFIG_I2C

Linux Kernel Configuration
	Device Drivers  --->
		[*] Staging drivers  --->
			<*>     Industrial I/O support --->
			    --- Industrial I/O support
			    -*-   Enable ring buffer support within IIO
			    -*-     Industrial I/O lock free software ring
			    -*-   Enable triggered sampling support

			    [--snip--]

				*** Network Analyzer, Impedance Converters ***
			    <*>   Analog Devices AD5933, AD5934 driver

			    [--snip--]

Hardware configuration

Driver testing

Each and every IIO device, typically a hardware chip, has a device folder under /sys/bus/iio/devices/iio:deviceX. Where X is the IIO index of the device. Under every of these directory folders reside a set of files, depending on the characteristics and features of the hardware device in question. These files are consistently generalized and documented in the IIO ABI documentation. In order to determine which IIO deviceX corresponds to which hardware device, the user can read the name file /sys/bus/iio/devices/iio:deviceX/name. In case the sequence in which the iio device drivers are loaded/registered is constant, the numbering is constant and may be known in advance.

02 Mar 2011 15:16

This specifies any shell prompt running on the target

root:/> cd /sys/bus/iio/devices/
root:/sys/bus/iio/devices> ls
iio:device0
root:/sys/bus/iio/devices> cd iio:device0

root:/sys/bus/iio/devices/iio:deviceX> ls -l
drwxr-xr-x    4 root     root             0 Jan  1 21:48 buffer
-rw-r--r--    1 root     root          4096 Jan  1 21:48 in_voltage0_scale
-r--r--r--    1 root     root          4096 Jan  1 21:48 in_voltage0_scale_available
-r--r--r--    1 root     root          4096 Jan  1 21:48 name
-rw-r--r--    1 root     root          4096 Jan  1 21:48 out_voltage0_freq_increment
-rw-r--r--    1 root     root          4096 Jan  1 21:48 out_voltage0_freq_points
-rw-r--r--    1 root     root          4096 Jan  1 21:48 out_voltage0_freq_start
-rw-r--r--    1 root     root          4096 Jan  1 21:48 out_voltage0_scale
-r--r--r--    1 root     root          4096 Jan  1 21:48 out_voltage0_scale_available
-rw-r--r--    1 root     root          4096 Jan  1 21:48 out_voltage0_settling_cycles
drwxr-xr-x    2 root     root             0 Jan  1 21:48 power
lrwxrwxrwx    1 root     root             0 Jan  1 21:48 subsystem -> ../../../o
-r--r--r--    1 root     root          4096 Jan  1 21:48 in_temp0_raw
-rw-r--r--    1 root     root          4096 Jan  1 21:48 uevent 

Show device name

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX> cat name
ad5933

Set sweep start frequency

Description: /sys/bus/iio/devices/iio:deviceX/out_voltageY_freq_start

Frequency sweep start frequency in Hz.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX> echo 15000 > out_voltage0_freq_start
root:/sys/bus/iio/devices/iio:deviceX> cat out_voltage0_freq_start
14999 

Set frequency increment

Description: /sys/bus/iio/devices/iio:deviceX/out_voltageY_freq_increment
Frequency increment in Hz (step size) between consecutive frequency points along the sweep.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX> echo 200 > out_voltageY_freq_increment

Set number of frequency points

Description: /sys/bus/iio/devices/iio:deviceX/out_voltage0_freq_points
Number of frequency points (steps) in the frequency sweep. This value, in conjunction with the out_voltageY_freq_start and the out_voltageY_freq_increment, determines the frequency sweep range for the sweep operation.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX> echo 100 > out_voltage0_freq_points
root:/sys/bus/iio/devices/iio:deviceX> cat out_voltage0_freq_points
100

Set number of settling time cycles

Description: /sys/bus/iio/devices/iio:deviceX/out_voltage0_settling_cycles
Number of output excitation cycles (settling time cycles) that are allowed to pass through the unknown impedance, after each frequency increment, and before the ADC is triggered to perform a conversion sequence of the response signal.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX> echo 15 > out_voltage0_settling_cycles
root:/sys/bus/iio/devices/iio:deviceX> cat out_voltage0_settling_cycles
15

Show available output ranges

Description: /sys/bus/iio/devices/iio:deviceX/out_voltage0_scale_available
List available output scales/ranges in millivolt.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX> cat out_voltage0_scale_available
1980 970 383 198

Set output range

Description: /sys/bus/iio/devices/iio:deviceX/out_voltage0_scale
Sets output scale/range in millivolt.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX> echo 1980 > out_voltage0_scale
root:/sys/bus/iio/devices/iio:deviceX> cat out_voltage0_scale
1980

Show available input scales

Description: /sys/bus/iio/devices/iio:deviceX/in_voltage0_scale_available
List available input scales. Programmable gain amplifier (PGA) options.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX> cat in_voltage0_scale_available
1 0.2

Set input scale

Description: /sys/bus/iio/devices/iio:deviceX/in_voltage0_scale
Sets input scale. Controls programmable gain amplifier (PGA).

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX> echo 0.2 > in_voltage0_scale
root:/sys/bus/iio/devices/iio:deviceX> cat in_voltage0_scale
0.2
Show internal temperature

Description: /sys/bus/iio/devices/iio:deviceX/in_temp0_input
Shows temperature in milli degrees Celsius.

The on-chip temperature sensor allows an accurate measurement of the ambient device temperature. The measurement range of the sensor is −40°C to +125°C.

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX> cat in_temp0_input
27987

Buffer management

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX/buffer> ls
enable              length
root:/sys/bus/iio/devices/iio:deviceX/buffer>

The Industrial I/O subsystem provides support for various ring buffer based data acquisition methods. Apart from device specific hardware buffer support, the user can chose between two different software ring buffer implementations. One is the IIO lock free software ring, and the other is based on Linux kfifo. Devices with buffer support feature an additional sub-folder in the /sys/bus/iio/devices/deviceX/ folder hierarchy. Called deviceX:bufferY, where Y defaults to 0, for devices with a single buffer.

Every buffer implementation features a set of files:

length
Get/set the number of sample sets that may be held by the buffer.

enable
Enables/disables the buffer. This file should be written last, after length and selection of scan elements.

watermark
A single positive integer specifying the maximum number of scan elements to wait for. Poll will block until the watermark is reached. Blocking read will wait until the minimum between the requested read amount or the low water mark is available. Non-blocking read will retrieve the available samples from the buffer even if there are less samples then watermark level. This allows the application to block on poll with a timeout and read the available samples after the timeout expires and thus have a maximum delay guarantee.

data_available
A read-only value indicating the bytes of data available in the buffer. In the case of an output buffer, this indicates the amount of empty space available to write data to. In the case of an input buffer, this indicates the amount of data available for reading.

length_align_bytes
Using the high-speed interface. DMA buffers may have an alignment requirement for the buffer length. Newer versions of the kernel will report the alignment requirements associated with a device through the `length_align_bytes` property.

scan_elements
The scan_elements directory contains interfaces for elements that will be captured for a single triggered sample set in the buffer.

02 Mar 2011 15:16

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX/scan_elements> ls
in_voltage0_imag_en     in_voltage0_imag_type   in_voltage0_real_index
in_voltage0_imag_index  in_voltage0_real_en     in0_voltage_real_type 

in_voltageX_en / in_voltageX-voltageY_en / timestamp_en:
Scan element control for triggered data capture. Writing 1 will enable the scan element, writing 0 will disable it

in_voltageX_type / in_voltageX-voltageY_type / timestamp_type:
Description of the scan element data storage within the buffer and therefore in the form in which it is read from user-space. Form is [s|u]bits/storage-bits. s or u specifies if signed (2's complement) or unsigned. bits is the number of bits of data and storage-bits is the space (after padding) that it occupies in the buffer. Note that some devices will have additional information in the unused bits so to get a clean value, the bits value must be used to mask the buffer output value appropriately. The storage-bits value also specifies the data alignment. So u12/16 will be a unsigned 12 bit integer stored in a 16 bit location aligned to a 16 bit boundary. For other storage combinations this attribute will be extended appropriately.

in_voltageX_index / in_voltageX-voltageY_index / timestamp_index:
A single positive integer specifying the position of this scan element in the buffer. Note these are not dependent on what is enabled and may not be contiguous. Thus for user-space to establish the full layout these must be used in conjunction with all _en attributes to establish which channels are present, and the relevant _type attributes to establish the data storage format.

02 Mar 2011 15:16

This specifies any shell prompt running on the target

root:/sys/bus/iio/devices/iio:deviceX/scan_elements> grep “” *
in_voltage0_imag_en:	1
in_voltage0_imag_index:	1
in_voltage0_imag_type:	s16/16>>0
in_voltage0_real_en:	1
in_voltage0_real_index:	0
in_voltage0_real_type:	s16/16>>0 

Buffer Example

This specifies any shell prompt running on the target - Example command sequence

> cd /sys/bus/iio/devices/iio:device0
> echo 10000 > out_voltage0_freq_start
> echo 100 > out_voltage0_freq_increment
> echo 100 > out_voltage0_freq_points
> echo 512 > buffer/length
> echo 1 > buffer/enable

Data interpretation

index datum type
0 Real Sample f0 signed short 16-bit
1 Imag Sample f0 signed short 16-bit
[fn * 2] Real Sample fn signed short 16-bit
[fn * 2] + 1 Imag Sample fn signed short 16-bit

Z = in_voltage0_real + i * in_voltage0_imag

This specifies any shell prompt running on the target

root:> hexdump -d /dev/iio:device0*
0000000   09451   01627**   09541   01663   09622   01697   09708   01734
0000010   09799   01757   09889   01791   09985   01820   10079   01856
0000020   10172   01887   10264   01922   10357   01962   10451   02005
0000030   10543   02044   10628   02082   10714   02123   10798   02153
0000040   10889   02188   10983   02230   11069   02268   11157   02302
0000050   11246   02339   11335   02381   11429   02423   11514   02461
0000060   11603   02500   11688   02539   11782   02573   11871   02618
0000070   11955   02659   12045   02703   12135   02743   12221   02787
0000080   12307   02828   12393   02877   12481   02910   12567   02951
0000090   12659   02991   12750   03034   12840   03080   12927   03130
00000a0   13010   03173   13102   03220   13185   03268   13271   03313
00000b0   13356   03358   13443   03401   13525   03445   13612   03491
00000c0   13700   03536   13791   03584   13875   03630   13958   03684
00000d0   14047   03729   14135   03785   14216   03834   14302   03879
00000e0   14383   03930   14469   03982   14555   04028   14634   04084
00000f0   14722   04131   14805   04183   14890   04231   14972   04291
0000100   15052   04340   15136   04389   15216   04445   15301   04495
0000110   15377   04549   15455   04604   15526   04651   15595   04703
0000120   15661   04758   15731   04809   15782   04856   15836   04905
0000130   15885   04943   15939   04990   15993   05043   16035   05083
0000140   16077   05131   16118   05174   16165   05223   16198   05265
0000150   16241   05311   16275   05351   16300   05389   16336   05438
0000160   16373   05482   16405   05522   16441   05559   16470   05603
0000170   16498   05644   16534   05690   16554   05742   16577   05780
0000180   16601   05827   16621   05874   16640   05904   16668   05943
0000190   16686   05983
0000194 

More Information

resources/tools-software/linux-drivers/iio-impedance-analyzer/ad5933.txt · Last modified: 17 Jan 2018 13:40 by Alexandru Ardelean

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.obk20.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'AD5933 IIO阻抗转换器和网络分析仪Linux驱动程序',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"//www.obk20.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);