预览加载中,请您耐心等待几秒...
1/4
2/4
3/4
4/4

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

本人学嵌入式还未到火候,各位有什么好的建议留下,我在此表示感谢,希望多多交流啊。 内核:linux-2.6.23 驱动程序:通过gpio端口点亮at91rm9200开发板上的灯 #include<linux/kernel.h> #include<linux/module.h> #include<linux/ioport.h> #include<asm/io.h> #include<linux/init.h> #include<linux/fs.h> #include<linux/errno.h> #include<linux/device.h> #include<mach/gpio.h> //#include<linux/moduleparam.h> #include<linux/sched.h> MODULE_LICENSE("GPL"); #defineDEMO_MAJOR125 #defineCOMMAND11 #defineCOMMAND23 staticunsignedintiovaddr; staticintdemo_init(void); staticintdemo_open(structinode*inode,structfile*file); staticintdemo_close(structinode*inode,structfile*file); staticssize_tdemo_read(structfile*file,char*buf,size_tcount,loff_t*offset); staticintdemo_ioctl(structinode*inode,structfile*file,unsignedintcmd,unsignedintarg); staticvoiddemo_cleanup(void); intdemo_param=9; staticintdemo_initialized=0; staticvolatileintdemo_flag=0; staticstructfile_operationsdemo_fops={ owner: THIS_MODULE, llseek: NULL, read: demo_read, write: NULL, ioctl: demo_ioctl, open: demo_open, release: demo_close, }; staticintdemo_init(void) { inti; staticstructclass*my_class; //printk("1");在运行时,出现问题,可使用printk来检查 my_class=class_create(THIS_MODULE,"demo_drv"); device_create(my_class,NULL,MKDEV(125,0),NULL,"demo_drv"); if(demo_initialized==1) return0; //iovaddr=ioremap(0xfffff000,0x10); //printk("4"); i=register_chrdev(DEMO_MAJOR,"demo_drv",&demo_fops); //printk("5"); if(i<0) { printk(KERN_CRIT"DEMO:i=%d\n",i); return0; } printk(KERN_CRIT"DEMO:demo_drvregisterredsuccessfully:)=\n"); demo_initialized=1; return0; } staticintdemo_open(structinode*inode,structfile*file) { //printk("6\n");//必须加上\n,才能显示, at91_set_GPIO_periph(AT91_PIN_PC15,1); at91_set_GPIO_periph(AT91_PIN_PC14,1); at91_set_gpio_output(AT91_PIN_PC15,1); at91_set_gpio_output(AT91_PIN_PC14,1); at91_set_gpio_value(AT91_PIN_PC15,0); at91_set_gpio_value(AT91_PIN_PC14,0); //printk("7\n"); if(demo_flag==1) { return-1; } printk(KERN_CRIT"DEMO:demodeviceopen\n"); demo_flag