基于tq2440开发板,内核2.6.30
功能
能进中断了,而且通道2读出来的数据也正确。
点击触摸屏的时候可能会混淆。因为触摸屏用的也是 adc-irq .
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEVICE_NAME "driver_adc"
volatile unsigned long *adccon = NULL; //adc控制寄存器
volatile unsigned long *adctsc = NULL; //adc 触摸屏控制寄存器
volatile unsigned long *adcdly = NULL; //adc 起始延迟寄存器
volatile unsigned long *adcdat0 = NULL; //adc 转换数据寄存器
volatile unsigned long *adcdat1 = NULL; //adc 转换数据寄存器
volatile unsigned long *intmsk = NULL;
/
*adccon &=~1; //关adc
printk("----------------drive -----val=%d \n",val);
copy_to_user( buf,&val,sizeof(val) );
printk("---------------drive-close-ok-------------\n",val);
return val;
}
// ------------------- WRITE -----------------------
ssize_t drive_write (struct file * file ,const char * buf, size_t count, loff_t * f_ops)
{
printk("-----------------drive write ok----------------\n");
return 0;
}
// ------------------- IOCTL -----------------------
ssize_t drive_ioctl (struct inode * inode ,struct file * file, unsigned int cmd, unsigned long arg)
{
printk("-----------------drive ioctl ok----------------\n");
return 0;
}
// -------------------------------------------------
static struct file_operations drive_ops ={
.owner = THIS_MODULE,
.open = drive_open,
.read = drive_read,
.write = drive_write,
.ioctl = drive_ioctl,
.release = drive_release,
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &drive_ops,
};
static int __init init_drive(void)
{
int ret;
ret = misc_register(&misc);
adccon = (volatile unsigned long *)ioremap(0x58000000, 16);
adctsc = (volatile unsigned long *)ioremap(0x58000004, 8);
adcdly = (volatile unsigned long *)ioremap(0x58000008, 16);
adcdat0= (volatile unsigned long *)ioremap(0x5800000c, 16);
adcdat1= (volatile unsigned long *)ioremap(0x58000010, 16);
intmsk = (volatile unsigned long *)ioremap(0x4a000008, 32);
printk("-----------------drive button init ok----------------\n");
return 0;
}
static void __exit exit_drive(void)
{
misc_deregister(&misc);
printk("-----------------drive button exit ok----------------\n");
}
module_init(init_drive);
module_exit(exit_drive);
MODULE_LICENSE("GPL");
//-------------------------------------应用程序------------------------------------------------
#include
#include
#include
#include // open() close()
#include // read() write()
#define DEVICE_NAME "/dev/driver_adc"
//------------------------------------- main ---------------------------------------------
int main(int argc, char **argv)
{
int fd,ret;
int val;
fd = open(DEVICE_NAME, O_RDWR);
if (fd == -1)
{
printf("can't open device mknod %s c zhu ci \n",DEVICE_NAME);
return 0;
}
while(1)
{
read(fd,&val,sizeof(val));
printf("------------------app--------------------\n");
printf("val=%d\n",val);
sleep(3);
}
// close
ret = close(fd);
if (ret == -1)
{
printf("app close error!!!!!!!!!!\n");
return 0;
}
return 0;
}// end main
上一篇:TQ2440裸奔程序:EINT中断按键测试程序
下一篇:TQ2440上移植RT3070AP过程
推荐阅读最新更新时间:2024-03-16 16:18