欢迎来到天天文库
浏览记录
ID:37728677
大小:278.63 KB
页数:7页
时间:2019-05-29
《linux移植五GPIO驱动开发》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、调试完pcDuino的led裸板程序,再调pcDuino基于linux内核的gpio驱动开发,以前的问题迎刃而解。本文是在pcDuino的linux移植四简单驱动开发的基础上,做GPIO驱动开发。然后写一个应用测试程序,通过敲命令控制pcduino的TXled亮、灭。同时如果你GPIO4、GPIO5接个LED,也会跟着亮、灭。开发环境:系统:ubuntu10.04.4单板:pcDuino编译器:arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2目标:敲命令控制pcDuino上的TX_LED
2、亮、灭一、硬件介绍仔细看pcDuino上的原理图和pcDuino的手册,发现二者不是完全对应的,还是以原理图为准。根据原理图知道TX_LED是接到PH15上,可以当做普通IO口用,不需要连跳线二、编写GPIO驱动代码主要包括2部分,驱动代码first_drv.c和应用测试程序firstdrvtest.c以及Makefile。驱动代码first_drv.c[plain]viewplaincopy1.#include2.#include3.#include4.#include3、inux/init.h>5.#include6.#include7.#include8.#include9.#include10.#include11.#include12.13.staticstructclass*firstdrv_class;14.staticstructclass_device*firstdrv_class_dev;15.16.volatileuns4、ignedlong*gphcfg1;//0x100ph9[6:4]00117.volatileunsignedlong*gphdat;//0x10c18.staticintfirst_drv_open(structinode*inode,structfile*file)19.{20.printk("first_drv_open");21./*配置GPh9为输出引脚gpio4*/22.*gphcfg15、=((0x1<<4)6、(0x1<<8)7、(0X1<<28));23.return0;24.}25.26.staticssize_tfirst_drv_write8、(structfile*file,constchar__user*buf,size_tcount,loff_t*ppos)27.{28.intval;29.printk("first_drv_write");30.copy_from_user(&val,buf,count);//copy_to_user();31.32.if(val==1)33.{34.//点灯35.*gphdat&=~((0X1<<9)9、(0X1<<10)10、(1<<15));36.}37.else38.{39.//灭灯40.*gphdat11、=((0X1<<9)12、(0X1<<10)13、(1<<14、15));41.}42.43.return0;44.}45.46.staticstructfile_operationsfirst_drv_fops={47..owner=THIS_MODULE,48..open=first_drv_open,49..write=first_drv_write,50.};51.52.intmajor;53.staticintfirst_drv_init(void)54.{55.major=register_chrdev(0,"first_drv",&first_drv_fops);56.firstdrv_class=class_15、create(THIS_MODULE,"firstdrv");57.firstdrv_class_dev=device_create(firstdrv_class,NULL,MKDEV(major,0),NULL,"xyz");58.gphcfg1=(volatileunsignedlong*)ioremap(0x01c20900,16);59.gphdat=(volatileunsignedlong*)ioremap(0x01c2090c,16);//gphcfg1+3;60.return0;61.}62.63.staticvoidfirst_drv_exit16、(void)64.{65
3、inux/init.h>5.#include6.#include7.#include8.#include9.#include10.#include11.#include12.13.staticstructclass*firstdrv_class;14.staticstructclass_device*firstdrv_class_dev;15.16.volatileuns
4、ignedlong*gphcfg1;//0x100ph9[6:4]00117.volatileunsignedlong*gphdat;//0x10c18.staticintfirst_drv_open(structinode*inode,structfile*file)19.{20.printk("first_drv_open");21./*配置GPh9为输出引脚gpio4*/22.*gphcfg1
5、=((0x1<<4)
6、(0x1<<8)
7、(0X1<<28));23.return0;24.}25.26.staticssize_tfirst_drv_write
8、(structfile*file,constchar__user*buf,size_tcount,loff_t*ppos)27.{28.intval;29.printk("first_drv_write");30.copy_from_user(&val,buf,count);//copy_to_user();31.32.if(val==1)33.{34.//点灯35.*gphdat&=~((0X1<<9)
9、(0X1<<10)
10、(1<<15));36.}37.else38.{39.//灭灯40.*gphdat
11、=((0X1<<9)
12、(0X1<<10)
13、(1<<
14、15));41.}42.43.return0;44.}45.46.staticstructfile_operationsfirst_drv_fops={47..owner=THIS_MODULE,48..open=first_drv_open,49..write=first_drv_write,50.};51.52.intmajor;53.staticintfirst_drv_init(void)54.{55.major=register_chrdev(0,"first_drv",&first_drv_fops);56.firstdrv_class=class_
15、create(THIS_MODULE,"firstdrv");57.firstdrv_class_dev=device_create(firstdrv_class,NULL,MKDEV(major,0),NULL,"xyz");58.gphcfg1=(volatileunsignedlong*)ioremap(0x01c20900,16);59.gphdat=(volatileunsignedlong*)ioremap(0x01c2090c,16);//gphcfg1+3;60.return0;61.}62.63.staticvoidfirst_drv_exit
16、(void)64.{65
此文档下载收益归作者所有