完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
一、硬件信息配置
#include #include #include /*定义结构体对象,用于保存LED灯硬件信息 phy_addr :用于保存寄存器的物理地址 gpio :用于保存LED灯所在的GPIO编号 */ struct led_phy_struct { unsigned long phy_addr; int gpio; }; struct led_phy_struct led_phy_obj[] ={ { .phy_addr = 0XC001B000, .gpio = 26 }, { .phy_addr = 0XC001C000, .gpio = 11 }, { .phy_addr = 0XC001C000, .gpio = 7 }, { .phy_addr = 0XC001C000, .gpio = 12 }, { .phy_addr = 0,//做为数组结束标志 .gpio = 0 } }; void dd_close(struct device *dev){};//用于消除警告 struct platform_device pd_myled_struct = { .name = "LED_", .id = 1, .dev = { .platform_data = led_phy_obj, .release = dd_close } }; static int myled_init(void){ platform_device_register(&pd_myled_struct); return 0; } static void myled_exit(void){ platform_device_unregister(&pd_myled_struct); } module_init(myled_init); module_exit(myled_exit); MODULE_LICENSE("GPL"); 二 、软件驱动代码: #include #include #include #include /* 定义和硬件信息匹配的结构体对象,用于获取硬件信息 */ struct led_phy_struct { unsigned long phy_addr ; int gpio; }; struct led_phy_struct *led_phy_obj; int myled_probe(struct platform_device * pd){ int i = 0; void * void_addr; unsigned long *base,*outenb,*altfn; led_phy_obj = (struct led_phy_struct *)pd->dev.platform_data; while(led_phy_obj.phy_addr != 0){//当phy_addr == 0时,为硬件信息结构体结束标志 void_addr = ioremap(led_phy_obj.phy_addr,0x24); base = (unsigned long *)void_addr; outenb = (unsigned long *)(void_addr+0x4); altfn = (unsigned long *)(void_addr + 0x20); *base &= ~(0x1 << led_phy_obj.gpio); *outenb |= (0x1 << led_phy_obj.gpio); if(led_phy_obj.gpio < 15){ altfn = (unsigned long *)(void_addr + 0x20); *altfn &= ~(0x3 << (led_phy_obj.gpio * 2)); *altfn |= (0x1 << (led_phy_obj.gpio * 2)); } else { altfn = (unsigned long *)(void_addr + 0x24); *altfn &= ~(0x3 << ((led_phy_obj.gpio- 16) * 2)); *altfn |= (0x1 << ((led_phy_obj.gpio- 16) * 2)); } iounmap(void_addr); i ++ ; } return 0; } static int myled_remove(struct platform_device *pd){ int i = 0; void * void_addr; unsigned long *base; led_phy_obj = (struct led_phy_struct *)pd->dev.platform_data; while(led_phy_obj.phy_addr != 0){ void_addr = ioremap(led_phy_obj.phy_addr,0x24); base = (unsigned long *)void_addr; *base |= (0x1 << led_phy_obj.gpio); iounmap(void_addr); i ++; } return 0; } struct platform_driver pd_myled_struct = { .probe = myled_probe, .remove = myled_remove, .driver = { .name = "LED_" } }; static int myled_drv_init(void){ platform_driver_register(&pd_myled_struct); return 0; } static void myled_drv_exit(void){ platform_driver_unregister(&pd_myled_struct); } module_init(myled_drv_init); module_exit(myled_drv_exit); MODULE_LICENSE("GPL"); |
|
|
|
只有小组成员才能发言,加入小组>>
680 浏览 0 评论
1099 浏览 1 评论
2463 浏览 5 评论
2797 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2634 浏览 6 评论
使用eim外接fpga可是端口一点反应都没有有没有大哥指点一下啊
645浏览 9评论
641浏览 7评论
请教大神怎样去解决iMX6Q在linux3.0.35内核上做AP失败的问题呢
772浏览 6评论
618浏览 5评论
660浏览 5评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-17 18:15 , Processed in 0.973944 second(s), Total 51, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号