CODE_LINUX_DRV_ADC

主要用途:读取AD设备中数据。

能力分类:嵌入式

应用领域:电源电池,机器人,无人机,射频通信,健康医疗

交易方式: 定制

参考价格:50000.00 小贴士:当前佣金是0%

好评率:100%| 综合评分:5.0| 已购买:0次
联系我 收藏店铺
分享: 

 模块描述

1.1  原理及方式

该驱动实现ZYNQ平台下ADC(Analog-to-Digital Converter)驱动,提供读取AD。

1.2  主要功能

读取AD设备中数据。

 标准模块

根据Linux驱动架构设计。

 模块设计

3.1  结构体设计

1) xadc_ipcore

AD核心结构体,定义IO内存地址,驱动IO操作,IO锁等

struct xadc_ipcore {

void __iomem *base;

const struct xadc_ipcore_ops *ops;

 

uint16_t threshold[16];

unsigned int alarm_mask;

    enum xadc_external_mux_mode external_mux_mode;

uint16_t *data;

struct mutex mutex;

spinlock_t lock;

 

struct completion completion;

    };

 

2) xadc_ipcore_ops

AD驱动IO操作结构体,定义IO读写,中断等操作

struct xadc_ipcore_ops {

int (*read)(struct xadc_ipcore *, unsigned int, uint32_t *);

int (*write)(struct xadc_ipcore *, unsigned int, uint32_t);

int (*setup)(struct platform_device *pdev, struct iio_dev *indio_dev, int irq);

irqreturn_t (*interrupt_handler)(int, void *);

irqreturn_t (*threaded_interrupt_handler)(int, void *);

unsigned int flags;

};

 

 

3.2  主要函数说明

1) AD设备搜索函数

函数原型

static int xadc_ipcore_probe(struct platform_device *pdev)

功能描述

搜索AD设备,创建AD设备驱动资源,注册AD设备

输入参数

pDev,设备指针

输出参数

全局变量值的变化

返回值

0,成功;其他,失败

2) 读取AD设备数据函数

函数原型

static int xadc_ipcore_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info)

功能描述

读取AD中数据

输入参数

indio_dev,设备指针

chan,AD通道号

info,通道信息

输出参数

val,输出1,根据info信息决定最终输出内容

val2,输出2,根据info信息决定最终输出内容

全局变量值的变化

返回值

参看IIO设备返回值表

3) AD设备释放函数

函数原型

static int xadc_ipcore_remove(struct platform_device *pdev)

功能描述

取消注册AD设备,释放AD设备资源

输入参数

indio_dev,设备指针

输出参数

全局变量值的变化

返回值

0,成功;

 使用方法

1. xilinx-xadc-ipcore.h和xilinx-xadc-ipcore.c放置在Linux内核的drivers/iio/adc/目录下

2. 在该目录下的Makefile中增加

“obj-$(CONFIG_XILINX_XADC_IPCORE) += xilinx-xadc-ipcore.o”

3. 在该目录下的Kconfig文件中增加

config XILINX_XADC_IPCORE

tristate "Xilinx XADC IPCORE driver"

depends on ARCH_ZYNQ || ARCH_ZYNQMP || MICROBLAZE || COMPILE_TEST

depends on HAS_IOMEM

select IIO_BUFFER

select IIO_TRIGGERED_BUFFER

help

Say yes here to have support for the Xilinx XADC IPCORE. The driver does support both the ZYNQ interface to the XADC IPCORE.

 The driver can also be build as a module. If so, the module will be called xilinx-xadc-ipcore.

 应用举例

通过上层封装的ADC库中代码,可以读取AD中数据,从而计算当前电压,电流。

 其他


总体评价

好评率:100%

好评数量:0

总体评分

工作速度:5分

工作质量:5分

工作态度:5分

暂无评价

企业其他能力

More>