您的位置 首页 ADAS

ARM-Linux主动创立设备结点

硬件平台:FL2440内核版本:2.6.28主机平台:Ubuntu11.04内核版本:2.6.391、首先配置busyboxbusyboxLinuxSystemUtilities—>[*..

硬件渠道:FL2440

内核版别:2.6.28

主机渠道:Ubuntu 11.04

内核版别:2.6.39

1、首要装备busybox

busybox
Linux System Utilities —>
[*] mdev
[*] Support /etc/mdev.conf
[*] Support command execution at device addition/removal

2、装备内核

3、修正文件体系里的/etc/init.d/rcS

#!/bin/sh
/bin/mount -a
/sbin/ifconfig eth0 192.168.0.3 up
#exec /usr/etc/rc.mouse

4、修正文件体系中/linuxrc文件

#!/bin/sh
#echo “mount /etc as ramfs”
#/bin/mount -n -t ramfs ramfs /etc
#/bin/cp -a /mnt/etc/* /etc

#/bin/mount -n -t ramfs ramfs /var/state/dhcp
#/bin/mount -n -t ramfs ramfs /var/log/boa
#/bin/mount -n -t ramfs ramfs /usr/Setting
#/bin/cp -a /mnt/Setting/* /usr/Setting

#/bin/mount -n -t ramfs ramfs /tmp
#/bin/cp -a /mnt/etc/* /etc

/bin/mount -t proc proc /proc
/bin/mount -t sysfs sysfs /sys
/bin/mount -t tmpfs tmpfs /dev
mkdir /dev/pts
mkdir /dev/shm

/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
/sbin/mdev -s

exec /sbin/init

4、修正/etcfstab

vi ./etc/fstab
#device mount-point type options dump fsck order
none /dev/pts devpts mode=0622 0 0
tmpfs /dev/shm tmpfs defaults 0 0

这样编写驱动时不必手动创立设备结点文件了

下面是改写的运用稠浊设备的ADC驱动程序,这样能够主动创立和删去设备结点了

[cpp]view plaincopy

  1. #include
  2. #include
  3. #include
  4. #include/*创立设备节点*/
  5. #include
  6. #include/*界说DECLARE_WAIT_QUEUE_HEAD*/
  7. #include/*界说了irqreturn_t等*/
  8. #includeinterrupt.h>/*request_irqdisable_irqenable_irq*/
  9. #include
  10. #include
  11. #include/*其间包含了#include”mach/irqs.h”*/
  12. #includeadc.h>
  13. #include
  14. #defineADC_MAJOR102
  15. #defineADC_NAME”my_adc”
  16. #defineSUCCESS0
  17. staticintadc_open(structinode*,structfile*);
  18. staticintadc_release(structinode*,structfile*);
  19. staticint__initadc_init(void);
  20. staticint__exitadc_exit(void);
  21. staticssize_tadc_read(structfile*,char*,size_t,loff_t*);
  22. volatileunsignedlongadc_con;
  23. unsignedlongadc_dat0;
  24. intflag;//等候使命完结标志
  25. unsignedlongbuf;//寄存转化完结的数据
  26. //声明等候行列
  27. DECLARE_WAIT_QUEUE_HEAD(adc_wait);
  28. structclk*adc_clk;
  29. staticirqreturn_tadc_interrupt(intirq,void*dev_id)//中止处理程序
  30. {
  31. if(flag==0)
  32. {
  33. buf=(readw(adc_dat0)&0x3ff);//读取转化完结的数据
  34. flag=1;
  35. wake_up_interruptible(&adc_wait);//唤醒等候其上的进程
  36. printk(“Readvalueis%ld\n”,buf);
  37. }
  38. returnIRQ_HANDLED;
  39. }
  40. staticstructfile_operationsadc_ops=
  41. {
  42. .owner=THIS_MODULE,
  43. .read=adc_read,
  44. .open=adc_open,
  45. .release=adc_release,
  46. };
  47. staticstructmiscdeviceadc_misc=
  48. {
  49. .name=ADC_NAME,
  50. .minor=ADC_MAJOR,
  51. .fops=&adc_ops,
  52. };
  53. staticint__initadc_init(void)
  54. {
  55. intret;
  56. adc_clk=clk_get(NULL,”adc”);//获取时钟
  57. clk_enable(adc_clk);//使能时钟
  58. ret=misc_register(&adc_misc);//注册设备
  59. if(ret<0)
  60. {
  61. printk(“registerdevicefail\n”);
  62. returnret;
  63. }
  64. adc_con=(unsignedlong)ioremap(0x58000000,4);
  65. adc_dat0=(volatileunsignedlong)ioremap(0x58000000+S3C2410_ADCDAT0,4);
  66. if(!(adc_con&adc_dat0))
  67. {
  68. printk(“Failedtoioremap\n”);
  69. gotohandle;
  70. }
  71. printk(“Initialized…\n”);
  72. returnSUCCESS;
  73. handle:
  74. misc_deregister(&adc_misc);
  75. return-1;
  76. }
  77. staticintadc_open(structinode*inode,structfile*file)//翻开设备函数
  78. {
  79. //注册中止
  80. intret;
  81. //disable_irq(IRQ_ADC);
  82. //enable_irq(IRQ_ADC);
  83. ret=request_irq(IRQ_ADC,adc_interrupt,IRQF_SHARED,ADC_NAME,1);//注册中止IRQ_ADC在mach/irqs.h中界说
  84. if(ret<0)
  85. {
  86. printk(“IRQ%dcannotrequest\n”,IRQ_ADC);
  87. returnret;
  88. }
  89. returnSUCCESS;
  90. }
  91. staticintadc_release(structinode*inode,structfile*file)//封闭设备函数
  92. {
  93. free_irq(IRQ_ADC,1);//开释中止
  94. returnSUCCESS;
  95. }
  96. staticssize_tadc_read(structfile*file,
  97. char*buffer,
  98. size_tlength,
  99. loff_t*offset)//设备读取函数
  100. {
  101. writew((1<<14)|(0x31<<6),adc_con);//设置ADCCON
  102. writew((readw(adc_con)|0x1),adc_con);//发动AD转化
  103. wait_event_interruptible(adc_wait,flag);
  104. flag=0;
  105. }
  106. staticint__exitadc_exit(void)//驱动卸载函数
  107. {
  108. iounmap(adc_con);
  109. iounmap(adc_dat0);
  110. misc_deregister(&adc_misc);
  111. clk_disable(adc_clk);
  112. clk_put(adc_clk);
  113. printk(“Theadcisunintialized\n”);
  114. returnSUCCESS;
  115. }
  116. module_init(adc_init);
  117. module_exit(adc_exit);
  118. MODULE_L%&&&&&%ENSE(“GPL”);

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/adas/264319.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部