ARM-Linux自动创建设备结点
内核版本: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
- #include
- #include
- #include
- #include
/*创建设备节点*/ - #include
- #include
/*定义DECLARE_WAIT_QUEUE_HEAD*/ - #include
/*定义了irqreturn_t等*/ - #include
interrupt.h>/*request_irqdisable_irqenable_irq*/ - #include
- #include
- #include/*其中包含了#include"mach/irqs.h"*/
- #include
adc.h> - #include
- #defineADC_MAJOR102
- #defineADC_NAME"my_adc"
- #defineSUCCESS0
- staticintadc_open(structinode*,structfile*);
- staticintadc_release(structinode*,structfile*);
- staticint__initadc_init(void);
- staticint__exitadc_exit(void);
- staticssize_tadc_read(structfile*,char*,size_t,loff_t*);
- volatileunsignedlongadc_con;
- unsignedlongadc_dat0;
- intflag;//等待任务完成标志
- unsignedlongbuf;//存放转换完成的数据
- //声明等待队列
- DECLARE_WAIT_QUEUE_HEAD(adc_wait);
- structclk*adc_clk;
- staticirqreturn_tadc_interrupt(intirq,void*dev_id)//中断处理程序
- {
- if(flag==0)
- {
- buf=(readw(adc_dat0)&0x3ff);//读取转换完成的数据
- flag=1;
- wake_up_interruptible(&adc_wait);//唤醒等待其上的进程
- printk("Readvalueis%ld\n",buf);
- }
- returnIRQ_HANDLED;
- }
- staticstructfile_operationsadc_ops=
- {
- .owner=THIS_MODULE,
- .read=adc_read,
- .open=adc_open,
- .release=adc_release,
- };
- staticstructmiscdeviceadc_misc=
- {
- .name=ADC_NAME,
- .minor=ADC_MAJOR,
- .fops=&adc_ops,
- };
- staticint__initadc_init(void)
- {
- intret;
- adc_clk=clk_get(NULL,"adc");//获取时钟
- clk_enable(adc_clk);//使能时钟
- ret=misc_register(&adc_misc);//注册设备
- if(ret<0)
- {
- printk("registerdevicefail\n");
- returnret;
- }
- adc_con=(unsignedlong)ioremap(0x58000000,4);
- adc_dat0=(volatileunsignedlong)ioremap(0x58000000+S3C2410_ADCDAT0,4);
- if(!(adc_con&adc_dat0))
- {
- printk("Failedtoioremap\n");
- gotohandle;
- }
- printk("Initialized...\n");
- returnSUCCESS;
- handle:
- misc_deregister(&adc_misc);
- return-1;
- }
- staticintadc_open(structinode*inode,structfile*file)//打开设备函数
- {
- //注册中断
- intret;
- //disable_irq(IRQ_ADC);
- //enable_irq(IRQ_ADC);
- ret=request_irq(IRQ_ADC,adc_interrupt,IRQF_SHARED,ADC_NAME,1);//注册中断IRQ_ADC在mach/irqs.h中定义
- if(ret<0)
- {
- printk("IRQ%dcannotrequest\n",IRQ_ADC);
- returnret;
- }
- returnSUCCESS;
- }
- staticintadc_release(structinode*inode,structfile*file)//关闭设备函数
- {
- free_irq(IRQ_ADC,1);//释放中断
- returnSUCCESS;
- }
- staticssize_tadc_read(structfile*file,
- char*buffer,
- size_tlength,
- loff_t*offset)//设备读取函数
- {
- writew((1<14)|(0x31<6),adc_con);//设置ADCCON
- writew((readw(adc_con)|0x1),adc_con);//启动AD转换
- wait_event_interruptible(adc_wait,flag);
- flag=0;
- }
- staticint__exitadc_exit(void)//驱动卸载函数
- {
- iounmap(adc_con);
- iounmap(adc_dat0);
- misc_deregister(&adc_misc);
- clk_disable(adc_clk);
- clk_put(adc_clk);
- printk("Theadcisunintialized\n");
- returnSUCCESS;
- }
- module_init(adc_ini
ARMLinux自动创建设备结 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)