上传一个AD的驱动程序,虽然简单,但可能给你启发的!
//下载地址http://www.hzlitai.com.cn/bbs/dispbbs.asp?boardid=11&Id=4687&page=2
作者:tymanium
它是一个采集ad的0号通道的驱动程序,将驱动程序和测试程序编译好之后,在2410开发板上加一个可调电阻产生分压,并将分压接到ain0上,这时运行sample &就可以采集ain0上的电压了.文件里有说明用法,如下:
/* ad.c
* copyright (c) by tymanium from china
* this is a device module file used for sbc2410
* it can drive ad convertor, yes it's very easy
*/
/*usage:
1. arm-linux-gcc -d__kernel__ -i/friendly-arm/kernel/include -
dkbuild_badename=test -dmodule -c -o ad.o ad.c
2. arm-linux-gcc -o sample sample.c
3. copy ad.o and sample to /lib/ and /bin/ respectively
4. power on sbc2410 ,and then active your bash
5. run #insmod /lib/ad.o and #mknod /dev/ad c 200 0
6. here run #sample &, now you can sample the ain0
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/poll.h>
#include <linux/spinlock.h>
#include <linux/irq.h>
#include <linux/delay.h>
#include <asm/hardware.h>
#define device_name "ad_test" //
#define ioport_major 200
/*this function is called whenever a process open the device file*/
static int ad_open(struct inode *inode, struct file *filp)
{
adccon=0x4c40; //
adctsc =0x58; //
adcdly=0x01;
return 0;
}
/*this function is called when a process call function ioctl( )*/
static int ad_ctl_ioctl(struct inode *inode, struct file *filp, unsigned int command, unsigned long arg)
{
switch(command){
case 0:
printk("the adccon register is %x \t", adccon);
return adcdat0; //get your sample code
case 1:
adccon |= 1; //start your ad
return 0;
}
return -einval;
}
/*this function is called when a process close our device file*/
static int ad_release(struct inode *inode, struct file *filp)
{
}
static struct file_operations ad_ctl_fops={
ioctl : ad_ctl_ioctl,
open : ad_open,
release : ad_release,
};
/*this function is called when you use insmod */
static int __init ad_init(void)
{
int ret;
unsigned long val=mpllcon;;
ret=register_chrdev(ioport_major, device_name, &ad_ctl_fops);
if (ret < 0) {
printk(device_name " can't register major number\n");
return ret;
}
printk("the val is %lx \n",val);
printk("the mpllcon register value is %lx \n",mpllcon);
printk("the clkdivn register value is %lx \n",clkdivn);
printk("the clkcon register value is %lx \n",clkcon);
return ret;
}
/*this function is called when you use rmmod*/
static void __exit ad_cleanup(void)
{
unregister_chrdev(ioport_major, device_name);
}
module_init(ad_init);
module_exit(ad_cleanup);
module_license("gpl");
下面是sample.c 文件
#include<stdio.h>
#include<stdlib.h>
#include<sys/ioctl.h>
#include<unistd.h>
#define device_adtest "/dev/ad"
int main( )
{
int fd,ret;
int val=-1;
float voltage;
if((fd=open(device_adtest,0))<0){
perror("can not open device");
exit(1);
}
while(1){
ioctl(fd,1,0);
sleep(1);
ret=ioctl(fd,0,0);
ret &= 0x3ff;
voltage=(float)ret;
voltage=(voltage-1023)*(-1)*3.3/1023;
printf("the sampling voltage is %f v\t \n",voltage);
}
close(fd);
return 0;
}
s3c2410板的linux下AD驱动程序
5星 · 超过95%的资源 需积分: 9 169 浏览量
2009-01-06
14:21:48
上传
评论 1
收藏 2KB RAR 举报
wode0713
- 粉丝: 1
- 资源: 22
最新资源
- tensorflow-2.9.3-cp39-cp39-win-amd64.whl
- tensorflow-2.9.3-cp37-cp37m-win-amd64.whl
- tensorflow-gpu-2.9.2-cp37-cp37m-win-amd64.whl
- matlab的低通,高通,带通滤波器代码设计
- 系统字体下载 字体文件-仿宋-黑体-楷体-楷体-GB2312-宋体-常规 文件.zip
- 演示设计-PPT模板-水墨风格-艺术与文化展示-水墨风格PPT模板:优雅设计,适合艺术与文化演示.zip
- view_video.php.html
- 涂个壁纸.apk
- hot-spicy pot.csv
- 二进制格式的BPSK中频数据,可以用来进行解调系统的开发
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈