tq2440 adc+中断 驱动
tq2440 adc+中断 驱动
天嵌科技 发表于2年前
tq2440 adc+中断 驱动
  • 发表于 2年前
  • 阅读 6
  • 收藏 0
  • 点赞 1
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

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

  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


共有 人打赏支持
粉丝 4
博文 135
码字总数 40355
×
天嵌科技
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: