具体ADC硬件知识及裸机驱动请看: Exynos4412裸机开发 —— A/D转换器

1、原理图如下:

2、相关寄存器信息

ADC_BASE      0x126C0000
ADCCON        0x0000               1<<0 | 1<<14 | 0X1<<16 | 0XFF<<6
ADCDLY          0x0008               
ADCDAT         0x000C              &0XFFF
CLRINTADC    0x0018
ADCMUX        0x001C

3、大体驱动编写流程如下

read()
{
1、向adc设备发送要读取的命令
          ADCCON    1<<0 | 1<<14 | 0X1<<16 | 0XFF<<6
       2、读取不到数据就休眠
            wait_event_interruptible();
       3、等待被唤醒读数据
          havedata = 0;
}
adc_handler()
{
1、清中断 ADC使用中断来通知转换数据完毕的
       2、状态位置位;
            havedata=1;
       3、唤醒阻塞进程
wake_up()
}
probe()
{
1、 读取中断号,注册中断处理函数
2、读取寄存器的地址,ioremap
3、字符设备的操作
}

4、设备树中的节点编写

[java] view plaincopy
  1. fs4412-adc{
  2. compatible = "fs4412,adc";
  3. reg = <0x126C0000 0x20>;
  4. interrupt-parent = <&combiner>;
  5. interrupts = <10 3>;
  6. };

5、驱动编写

driver.c

[cpp] view plaincopy
  1. #include <linux/module.h>
  2. #include <linux/device.h>
  3. #include <linux/platform_device.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/fs.h>
  6. #include <linux/wait.h>
  7. #include <linux/sched.h>
  8. #include <asm/uaccess.h>
  9. #include <asm/io.h>
  10. static int major = 250;
  11. static wait_queue_head_t wq;
  12. static int have_data = 0;
  13. static int adc;
  14. static struct resource *res1;
  15. static struct resource *res2;
  16. static void *adc_base;
  17. #define ADCCON 0x0000
  18. #define ADCDLY 0x0008
  19. #define ADCDAT 0x000C
  20. #define CLRINTADC 0x0018
  21. #define ADCMUX 0x001C
  22. static  irqreturn_t adc_handler(int irqno, void *dev)
  23. {
  24. have_data = 1;
  25. printk("11111\n");
  26. /*清中断*/
  27. writel(0x12,adc_base + CLRINTADC);
  28. wake_up_interruptible(&wq);
  29. return IRQ_HANDLED;
  30. }
  31. static int adc_open (struct inode *inod, struct file *filep)
  32. {
  33. return 0;
  34. }
  35. static ssize_t adc_read(struct file *filep, char __user *buf, size_t len, loff_t *pos)
  36. {
  37. writel(0x3,adc_base + ADCMUX);
  38. writel(1<<0 | 1<<14 | 0X1<<16 | 0XFF<<6 ,adc_base +ADCCON );
  39. wait_event_interruptible(wq, have_data==1);
  40. /*read data*/
  41. adc = readl(adc_base+ADCDAT)&0xfff;
  42. if(copy_to_user(buf,&adc,sizeof(int)))
  43. {
  44. return -EFAULT;
  45. }
  46. have_data = 0;
  47. return len;
  48. }
  49. static  int adc_release(struct inode *inode, struct file *filep)
  50. {
  51. return 0;
  52. }
  53. static struct file_operations  adc_ops =
  54. {
  55. .open = adc_open,
  56. .release = adc_release,
  57. .read = adc_read,
  58. };
  59. static int hello_probe(struct platform_device *pdev)
  60. {
  61. int ret;
  62. printk("match 0k \n");
  63. res1 = platform_get_resource(pdev,IORESOURCE_IRQ, 0);
  64. res2 = platform_get_resource(pdev,IORESOURCE_MEM, 0);
  65. ret = request_irq(res1->start,adc_handler,IRQF_DISABLED,"adc1",NULL);
  66. adc_base = ioremap(res2->start,res2->end-res2->start);
  67. register_chrdev( major, "adc", &adc_ops);
  68. init_waitqueue_head(&wq);
  69. return 0;
  70. }
  71. static int hello_remove(struct platform_device *pdev)
  72. {
  73. free_irq(res1->start,NULL);
  74. free_irq(res2->start,NULL);
  75. unregister_chrdev( major, "adc");
  76. return 0;
  77. }
  78. static struct of_device_id adc_id[]=
  79. {
  80. {.compatible = "fs4412,adc" },
  81. };
  82. static struct platform_driver hello_driver=
  83. {
  84. .probe = hello_probe,
  85. .remove = hello_remove,
  86. .driver ={
  87. .name = "bigbang",
  88. .of_match_table = adc_id,
  89. },
  90. };
  91. static int hello_init(void)
  92. {
  93. printk("hello_init");
  94. return platform_driver_register(&hello_driver);
  95. }
  96. static void hello_exit(void)
  97. {
  98. platform_driver_unregister(&hello_driver);
  99. printk("hello_exit \n");
  100. return;
  101. }
  102. MODULE_LICENSE("GPL");
  103. module_init(hello_init);
  104. module_exit(hello_exit);

test.c

[cpp] view plaincopy
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <stdio.h>
  5. main()
  6. {
  7. int fd,len;
  8. int adc;
  9. fd = open("/dev/hello",O_RDWR);
  10. if(fd<0)
  11. {
  12. perror("open fail \n");
  13. return ;
  14. }
  15. while(1)
  16. {
  17. read(fd,&adc,4);
  18. printf("adc%0.2f V \n",(1.8*adc)/4096);
  19. }
  20. close(fd);
  21. }

Exynos4412 ADC 设备驱动开发相关推荐

  1. linux设备驱动开发之环境搭建(基于exynos4412)

    第一章 linux设备驱动开发之环境搭建(基于exynos4412) 目录 第一章 linux设备驱动开发之环境搭建(基于exynos4412) 1.搭建开发板运行环境 1.1.交叉开发模式 安装交叉 ...

  2. Linux 设备驱动开发 —— 设备树在platform设备驱动中的使用

    关与设备树的概念,我们在Exynos4412 内核移植(六)-- 设备树解析 里面已经学习过,下面看一下设备树在设备驱动开发中起到的作用 Device Tree是一种描述硬件的数据结构,设备树源(De ...

  3. Exynos4412 IIC总线驱动开发(二)—— IIC 驱动开发

    前面在Exynos4412 IIC总线驱动开发(一)-- IIC 基础概念及驱动架构分析 中学习了IIC驱动的架构,下面进入我们的驱动开发过程 首先看一张代码层次图,有助于我们的理解 上面这些代码的展 ...

  4. Linux下按键设备驱动开发以及对中断的上半部分和下半部分详细介绍

    文章目录 一.编写并且加载设备树插件 (1)检测管脚是否占用 (2)添加设备树插件 (3)加载设备树插件 二.中断相关函数 (1)request_irq中断注册函数 (2)free_irq中断注销函数 ...

  5. 【致敬未来的攻城狮计划】第2期定向赠书《RT-Thread设备驱动开发指南》+ 《GD32 MCU原理及固件库开发指南》

    开启攻城狮的成长之旅!这是我参与的由 CSDN博客专家 架构师李肯(超链接:http://yyds.recan-li.cn)和 瑞萨MCU (超链接:瑞萨电子 (Renesas Electronics ...

  6. 《Linux设备驱动开发详解 A》一一2.3 接口与总线

    本节书摘来华章计算机出版社<Linux设备驱动开发详解 A>一书中的第2章,第2.3节,作者:宋宝华 更多章节内容可以访问云栖社区"华章计算机"公众号查看.1 2.3 ...

  7. Windows CE设备驱动开发之电源管理

    4.7电源管理 电源管理模块管理设备电源,从而全面改进操作系统的电源使用效率:它所有设备的电源使用,同时能与不支持电源管理的应用程序及驱动程序共存. 使用电源管理可以有效的减少目标设备的电源消耗,同时 ...

  8. linux 块设备驱动 (三)块设备驱动开发

    linux 块设备驱动 (三)块设备驱动开发 一: 块设备驱动注册与注销 块设备驱动中的第1个工作通常是注册它们自己到内核,完成这个任务的函数是 register_blkdev(),其原型为: int ...

  9. Linux设备驱动开发概述

    作者:宋宝华 email:author@linuxdriver.cn 在过去这些年,Linux已经成功应用于服务器和桌面系统,而近年来,随着嵌入式系统应用的持续升温,Linux也开始广泛应用于嵌入式领 ...

最新文章

  1. CIKM 2021 | Google出品:将对比学习用于解决推荐系统长尾问题
  2. react-native项目打包速度优化
  3. Spring Boot入门到牛X
  4. jQuery end()函数示例
  5. jersey tomcat MySQL_IDEA+Jersey+Tomcat搭建RESTful API
  6. 饮冰三年-人工智能-Python-11之HelloWorld
  7. MESYS-轴和轴承的设计制造软件
  8. 詹姆斯titan_再见,詹姆斯!
  9. 处理打开网站出现网站的安全证书有问题的方法
  10. Chrome浏览器安装vue插件(附插件下载地址)
  11. 2020-08-18 前端html与css学习笔记总结篇(超详细)
  12. webstorm加载webpack
  13. vscode远程连接服务器,编写python代码无法补全
  14. linux下测试硬盘读写速度
  15. Docker配置mc服务器
  16. Watering Grass——UVA10382
  17. mysql questions_mysql常用参数监控
  18. java 字体选择器_字体选择器
  19. 用c语言实现图的基本存储,图的邻接矩阵存储(C语言实现)
  20. VirtualBox 官网下载+安装(win7)

热门文章

  1. Portal-Basic Java Web 应用开发框架:应用篇(十四) —— 异步 Action
  2. Linux DHCP Server 配置给FIT AP 使用的option
  3. leetcode 1707. 与数组中元素的最大异或值
  4. leetcode剑指 Offer 53 - II. 0~n-1中缺失的数字(二分查找)
  5. 用原生js封装get方法
  6. Powershell-创建Module
  7. Python开发利器之UliPad
  8. mysql 数据库定时备份 增量/全备份
  9. [转]jQuery Validate使用说明
  10. 【BZOJ3036】绿豆蛙的归宿 拓补排序+概率