linux LED 驱动.docVIP

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
以下是扬创开发板给的led例程,将对应用程序和驱动程序进行详细注释和分析,并验证! /* * LED interface driver for utu2440 * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details. * bit.lili@ 2007-6 */ #include linux/types.h #include linux/ioport.h #include linux/fcntl.h #include linux/miscdevice.h #include linux/sched.h #include linux/spinlock.h #include linux/errno.h #include linux/kernel.h #include linux/module.h #include linux/slab.h #include linux/input.h #include linux/init.h #include linux/delay.h #include linux/interrupt.h #include linux/device.h #include asm/uaccess.h #include asm/system.h #include asm/io.h #include asm/irq.h #include asm/arch/regs-gpio.h #define LED_DRIVER utu2440 LED Driver v1.00 static unsigned long led_table [] = { S3C2410_GPF4, S3C2410_GPF5, S3C2410_GPF6, S3C2410_GPF7, }; static int led_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg); /*ioctl(fd, on, led_number); inode 和 filp 指针是对应应用程序传递的文件描述符 fd 的值, 和传递给 open 方法的相同参数*/ static int led_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { switch (cmd) { case 0: case 1: if (arg 4) { return -EINVAL; } s3c2410_gpio_setpin(led_table[arg], !cmd); /*给寄存器赋值,使某一位置1或0,led亮,给寄存器置0,因此对cmd取反*/ /*通过s3c2410_gpio_setpin()来做,此函数为驱动函数的核心操作*/ /*case 0和case 1操作一样*/ default: return -EINVAL; } return 0; } /*设备驱动文件操作结构体*/ static struct file_operations led_fops = { .ioctl = led_ioctl, }; static struct miscdevice led_dev = { MISC_DYNAMIC_MINOR, led, led_fops }; /* struct miscdevice { int minor; //MISC_DYNAMIC_MINOR const char *name;//led const struct file_operations *fops; //led_fops struct list_head list; struct device *parent; struct device *this_device; }; 此结构体是注册混合设备所需要的参数。主要有: minor:次设备号,所有的misc设备共用一个主设备号,所以注册misc设备时只要次设备号就可以了。利用次设备号来区分设备的。 name:misc设备名。 *fops:misc设备文件操作结构体。其它三个参数很少用 */ static int led_init(void) { pr

文档评论(0)

hong333666 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档