1、 简介
xadc是zynq芯片内部进行温度和电压检测的模块,通过(xilinx wiki - xadc.html)这篇wiki可以知道,xadc控制器有两种表现形式,一种是位于ps内部,即文档中提到的the ps-xadc interface for the ps software to control the xadc,另一种是位于pl内部,通过ip核的方式实现。目前常用的是第一种。
通过ug480_7series_xadc这篇文档得知,the adcs can access up to 17 external analog input channels,也就是除了内部原有的监测项外,xadc最多支持17路扩展通道,可以参看下图。
对硬件有了基本的了解后,就可以进行devicetree的设置了。
2、 devicetree配置
由于是在ps部分,xadc控制器设置就像其他控制器一样即可,system.hdf中给出了地址:
devicetree设置如下:
xadc@f8007100 {
compatible= xlnx,zynq-xadc-1.00.a;
reg =;
interrupts= ;
interrupt-parent = ;
clocks =;
xlnx,channels {
#address-cells = ;
#size-cells = ;
channel@0 {
reg= ;
};
channel@1 {
reg= ;
};
channel@8 {
reg= ;
};
};
};
这里只启用了三个channel,如果启用更多channel可以在devicetree中进行添加。
3、 kernel配置
内核中已经包含了xadc的驱动程序,位置是drivers\iio\adc,最后三个xilinx打头的文件。将驱动加入内核配置过程如下:
如果为了省事,也可以直接在defconfig文件中加入配置信息,这样默认是选中的。
4、 测试
加载devicetree,uimage,uramdisk后能在sys目录下找到检测信息:
打开in_temp0_raw能看到数字,注意,该数字是原始数字,需要转换才能得到正确的摄氏度。
该数字不断变化,表明温度在变化。其他电压信息类似。
为了更直观的展现监测信息,可以做一个用户app来打印,代码如下:
#define max_path_size 200
#define max_name_size 50
#define max_value_size 100
#define max_cmd_name_size 100
#define max_unit_name_size 50
#define sys_path_iio /sys/bus/iio/devices/iio:device0
#define vcc_int_cmd xadc_get_value_vccint
#define vcc_aux_cmd xadc_get_value_vccaux
#define vcc_bram_cmd xadc_get_value_vccbram
#define vcc_temp_cmd xadc_get_value_temp
#define vcc_ext_ch_cmd xadc_get_value_ext_ch
static const int mv_mul = 1000;
static const int multiplier = 1 << 12;
static char gnodename[max_name_size];
enum econvtype
{
econvtype_none,
econvtype_raw_to_scale,
econvtype_scale_to_raw,
econvtype_max
};
enum xadc_param
{
eparamvccint,
eparamvccaux,
eparamvccbram,
eparamtemp,
eparamvaux0,
eparammax
};
struct command
{
const enum xadc_param parameter_id;
const char cmd_name[max_cmd_name_size];
const char unit[max_unit_name_size];
};
struct command command_list[eparammax] = {
{eparamvccint, vcc_int_cmd, mv},
{eparamvccaux, vcc_aux_cmd, mv},
{eparamvccbram, vcc_bram_cmd, mv},
{eparamtemp, vcc_temp_cmd, degree celsius},
{eparamvaux0, vcc_ext_ch_cmd, mv}
};
struct xadcparameter
{
const char name[max_name_size];
float value;
float (* const conv_fn)(float,enum econvtype);
};
/*
struct xadcparameter gxadcdata[eparammax] = {
[eparamvccint] = { in_voltage0_vccint_raw, 0, conv_voltage},
[eparamvccaux] = { in_voltage4_vccpaux_raw, 0, conv_voltage},
[eparamvccbram]= { in_voltage2_vccbram_raw, 0, conv_voltage},
[eparamtemp] = { in_temp0_raw, 0, conv_temperature},
[eparamvaux0] = { in_voltage8_raw, 0, conv_voltage_ext_ch}
};
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include xadc_core.h
//utility functions
float conv_voltage(float input, enum econvtype conv_direction)
{
float result=0;
switch(conv_direction)
{
case econvtype_raw_to_scale:
result = ((input * 3.0 * mv_mul)/multiplier);
break;
case econvtype_scale_to_raw:
result = (input/(3.0 * mv_mul))*multiplier;
break;
default:
printf(convertion type incorrect... doing no conversion\n);
// intentional no break;
case econvtype_none:
result = input;
break;
}
return result;
}
float conv_voltage_ext_ch(float input, enum econvtype conv_direction)
{
float result=0;
switch(conv_direction)
{
case econvtype_raw_to_scale:
result = ((input * mv_mul)/multiplier);
break;
case econvtype_scale_to_raw:
result = (input/mv_mul)*multiplier;
break;
default:
printf(convertion type incorrect... doing no conversion\n);
// intentional no break;
case econvtype_none:
result = input;
break;
}
return result;
}
float conv_temperature(float input, enum econvtype conv_direction)
{
float result=0;
switch(conv_direction)
{
case econvtype_raw_to_scale:
result = ((input * 503.975)/multiplier) - 273.15;
break;
case econvtype_scale_to_raw:
result = (input + 273.15)*multiplier/503.975;
break;
default:
printf(conversion type incorrect... doing no conversion\n);
// intentional no break;
case econvtype_none:
result = input;
break;
}
return result;
}
void get_iio_node()
{
struct dirent **namelist;
int i,n;
char value=0;
int fd = -1;
char upset[20];
float raw_data=0;
float true_data=0;
int offset=0;
int currpos;
n = scandir(sys_path_iio, &namelist, 0, alphasort);
for (i=0; i d_name);
fd = open(gnodename, o_rdwr );
if(strstr(gnodename,temp))
{
if(strstr(gnodename,raw))
{
offset=0;
while(offsetd_name,true_data);
}
}
else if(strstr(gnodename,voltage))
{
if(strstr(gnodename,raw))
{
offset=0;
while(offsetd_name,true_data);
}
}
close(fd);
}
}
int main(int argc, char *argv[])
{
get_iio_node();
return 0;
}
在编写这段代码时遇到好几个问题,首先用read函数取值取到的其实是文件中ascii码字符,没有什么好办法只好改成一位一位读取存入字符串然后调用atoi函数转换为int数字。其次,用lseek函数获取文件大小时得到的值都为4096,但是这些文件并不是目录,不知道为何大小都显示的是linux最基本的文件块大小,最后只好投机取巧根据每个文件中的数字位数进行取值,例如temp和vcc这些文件只有4位,那么就从文件中读4位。最后输出结果如下:
上图中温度为39度,和实际情况差不多。至此xadc驱动告一段落。
ISM RF产品的无线链路预算表
利用开源平台即服务更快地部署作战人员应用
对三种最典型的电调滤波电路进行分析和研究
百度处于搜索引擎这一迄今为止人工智能规模最大的应用场景
11月力帆集团传统乘用车车产量为0辆,或将为吉利代工生产
基于Linux的XADC控制器模块的两种形式配置
人工智能涉及的领域有多广
腾讯优图推出名为DSFD(中文名为双分支人脸检测器)的全新算法
中国手机销量下滑28% 份额向华为OPPO五大品牌集中
共射-共基放大电路的仿真分析
西门子全交流变频驱动系统在电厂卸船机上应用及其速度同步与电流
盘点2019年五大未来技术趋势
一文详解外凸与内凸法规
荣耀V9好在哪里?有什么亮点?值不值得买?
西门子plc的crc校验程序
几种常用Reader输入流的使用方式
南方电网海南公司启动电网提升三年行动计划 加速推进海南电网“脱胎换骨”
2018电视机顶盒十大品牌,揭秘最值得入手的十大电视盒子
疫情之下医疗物资不够用,3D打印技术来帮忙
纸张表面瑕疵检测仪的详细介绍