欢迎访问电子工程网!   登录 | 免费注册 ]   

Embedsky007的个人空间 http://www.eechina.com/space-uid-114045.html [收藏] [复制] [分享] [RSS]

博客

TQ2440 adc+中断 驱动

热度 6已有 300 次阅读2016-3-24 15:50 |个人分类:技术文章| 关键词: TQ2440, 嵌入式, 开发板, 天嵌, ADC

  TQ2440 是由广州天嵌计算机科技有限公司精心打造的一款开发板。以稳定的性能,过硬的质量,丰富的扩展接口,优质的售后服务和技术支持,赢得众多企业的青睐和支持。

  基于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;

  //*gpbdat &= ~((1<<5) );

  //ain2

  static DECLARE_WAIT_QUEUE_HEAD(adc_waitq);

  static volatile int val=0;

  static volatile int ev_press = 0;

  static irqreturn_t adc_irq(int irq, void *dev_id)

  {

  printk("-------------adc_irq is ok ------------\n");

  ev_press=1;

  //*adccon |= 0X1; //开始转换

  val=(*adcdat0&0x3ff);

  wake_up_interruptible(&adc_waitq);

  return IRQ_RETVAL(IRQ_HANDLED);

  }

  // ------------------- OPEN ------------------------

  ssize_t drive_open (struct inode * inode ,struct file * file)

  {

  printk("-----------------drive open ok----------------\n");

  request_irq(IRQ_ADC,adc_irq, IRQF_SAMPLE_RANDOM|IRQF_SHARED,"adc_irq",1);

  return 0;

  }

  // ------------------- RELEASE/CLOSE ---------------

  ssize_t drive_release (struct inode * inode ,struct file * file)

  {

  printk("-----------------drive close ok----------------\n");

  free_irq(IRQ_ADC, 1);

  return 0;

  }

  // ------------------- READ ------------------------

  ssize_t drive_read (struct file * file ,char * buf, size_t count, loff_t * f_ops)

  {

  printk("-----------------drive read ok----------------\n");

  *adccon |= (1<<14)|(0xff<<6)|(2<<3);//设置分频倍数0xff,设置输入通道为2

  //*intmsk |= (1<<31)| (1<<5)|(1<<8);

  *adccon |= 0X1; //开始转换

  wait_event_interruptible(adc_waitq, ev_press);

  ev_press = 0;

  /*

  while( !(*adccon & 0x8000) ) //等待转换结束

  ;

  val=(*adcdat0&0x3ff);

  */

  *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

  感谢chen4013874的分享!

  供货情况:

  天嵌科技提供专业嵌入式板卡和行业解决方案。如有需要,可以联系天嵌科技的销售人员。

  销售电话:020-38219416 38373101

  技术支持:020-38219416转807 820

  网址:http://www.embedsky.com


路过

鸡蛋
3

鲜花

握手

雷人

刚表态过的朋友 (3 人)

发表评论 评论 (7 个评论)

回复 sally_cheng 2016-3-25 15:35
多谢分享
回复 lzh8 2016-3-26 14:46
这么多的分享资料,继续的支持你们天嵌
回复 2851297573 2016-3-29 10:56
当初购买tq2440的板子,就是冲着资料够多来着!
回复 张晓然 2016-3-29 11:48
完全支持,资料实在是太强大了~
回复 Embedsky007 2016-3-30 16:01
2851297573: 当初购买tq2440的板子,就是冲着资料够多来着!
哈哈那必须滴,让你们用过不后悔
回复 想飞的猫星人 2016-3-30 16:39
天嵌的资料一直都挺多的
回复 adeechan36 2016-3-31 09:15
学习,还是用2440比较合适,资料比较多。谢谢楼主!

facelist

您需要登录后才可以评论 登录 | 立即注册

回顶部