完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
要写pxa270上的GPIO中断,迟迟没有进展,无奈,从基础开始,先连个按键做简单的中断,但是因为中断号方面的问题,始终看不出效果,没办法,先做个简单的GPIO驱动吧,就让GPIO9号引脚隔两秒变成低电平,再隔两秒变成高电平,很快实现。 没什么难度,就是终于有一点可视的效果了(示波器),记录结果,做个基础的滚回点吧。代码如下: (1)驱动程序irq_driver.c #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define DEVICE_NAME "irq_270" #define IRQ_MAJOR 0 staticint irq_major=IRQ_MAJOR; staticvoid GPIO_init() { GPDR0|=(0x1<<9); //GPIO第9位置,表输出 GPSR0|=(0x1<<9); //置高 printk("GPIO_init ok!n"); } staticvoid GPIO_low() { GPCR0|=(0x1<<9); } staticvoid GPIO_heigh() { GPSR0|=(0x1<<9); } staticint irq_open(struct inode *inode ,struct file *file) { printk(DEVICE_NAME"open success!n"); return 0; } staticint irq_release(struct inode *inode ,struct file *filp) { printk(DEVICE_NAME "release!n"); return 0; } static ssize_t irq_read(struct file *filp, char *buff, size_t count, loff_t *ppos) { printk("user read data from drivern"); return count; } staticint gpio_ioctl(struct inode *inode,struct file *file,unsignedint cmd,unsignedlong arg) { switch(cmd){ case 0: { GPIO_low(); printk("GPIO to low level!n"); }break; case 1: { GPIO_heigh(); printk("GPIO to high level!n"); }break; default: printk("error cmd numbern");break; } return 0; } staticstruct file_operations irq_fops={ owner: THIS_MODULE, read: irq_read, ioctl: gpio_ioctl, open: irq_open, release: irq_release, }; staticint __init irq_init(void) { int ret=-1; int flags; ret=register_chrdev(irq_major,DEVICE_NAME,&irq_fops); if(ret<0) { printk("pxa270:init_irq failed with %d.n[--kernel--]",ret); return ret; } GPIO_init(); printk(DEVICE_NAME "initializedn"); return 0; } staticvoid __exit irq_exi(void) { unregister_chrdev(irq_major,"GPIO9"); printk(DEVICE_NAME "unload!n"); } module_init(irq_init); module_exit(irq_exi); MODULE_DESCRIPTION("IRQ module"); MODULE_LICENSE("GPL"); (2)测试程序irq_test.c #include #include #include #include #include int main() { int fd; int r_buf[1024]; fd=open("/dev/irq",O_RDONLY); if(fd !=-1); else printf("Device open failure!n"); while(1) { ioctl(fd,0,NULL); sleep(2); ioctl(fd,1,NULL); sleep(2); } close(fd); return 0; } (3)Makefile文件 PWD=$(shell pwd) KERNEL:= /up-techpxa270/kernel/linux-2.6.9 obj-m := irq_driver.o module-objs:=irq_driver.o all: $(MAKE) -C$(KERNEL) M=$(PWD) modules clean: rm *.mod.c rm *.ko rm *.o 运行: insmod irq_driver.ko mknod /dev/irq c 253 0 ./test 卸载: rmmod irq_driver.ko rm /dev/irq |
|
|
|
2136 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1970 浏览 3 评论
4566 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2116 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2629 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 01:22 , Processed in 0.545584 second(s), Total 65, Slave 47 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号