7.3-led-r.zip

  • PUDN用户
    了解作者
  • Unix_Linux
    开发工具
  • 13KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2012-10-21 19:29
    上传日期
led驱动与测试 包括led驱动源码和测试程序
7.3-led-r.zip
  • 7.3-led driver
  • 7.3.2-led driver test
  • led
  • main.c
    2.1KB
  • led
    13.7KB
  • main.o
    1.2KB
  • Makefile
    242B
  • 7.3.1-led drvier
  • leds
  • magic-leds.o
    2.8KB
  • leds.ko
    2.8KB
  • Makefile
    411B
  • magic-leds.c
    7.5KB
内容介绍
/* ****************************************Copyright (c)************************************************** ** Guangzhou Zhiyuan Electronic Co.,LTD. ** graduate school ** http://www.zyinside.com ** **------------------------------------- File Info ------------------------------------------------------ ** File name: magic-leds.c ** Last modified Date: 2005-12-28 ** Last Version: 1.0 ** Descriptions: Driver for LEDs and BEEP on MagicARM2410. ** Based on Linux 2.4.18. **------------------------------------------------------------------------------------------------------ ** Created by: Chenxibing ** Created date: 2005-12-27 ** Version: 1.0 ** Descriptions: Preliminary version. ** **------------------------------------------------------------------------------------------------------ ** Modified by: ** Modified date: ** Version: ** Descriptions: ** ******************************************************************************************************** */ #ifndef __KERNEL__ #define __KERNEL__ #endif #ifndef MODULE #define MODULE #endif #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/sched.h> //#include <linux/poll.h> //#include <linux/spinlock.h> //#include <linux/irq.h> //#include <linux/miscdevice.h> //#include <linux/delay.h> #include <asm/hardware.h rel='nofollow' onclick='return false;'> #define DEVICE_NAME "magic-leds" //#define LED_MAJOR 231 //can be 231~239 or 240~254 MODULE_LICENSE("Proprietary"); MODULE_DESCRIPTION("Guangzhou Zhiyuan Electronic Co.,LTD.\ngraduate school\nhttp://www.zyinside.com"); MODULE_SUPPORTED_DEVICE("Linux 2.4.18 & MagicARM2410"); MODULE_AUTHOR("Chenxibing"); /* ******************************************************************************************************* ** LEDs' informations. ******************************************************************************************************* */ static unsigned long leds_table [] = { GPIO_E11, GPIO_E12, GPIO_H4, GPIO_H6, GPIO_H10, }; /* ******************************************************************************************************* ** Function name: magic_leds_ioctl() ** Descriptions : IO control function ** Input: ** inode : information of device ** filp : pointer of file ** cmd : command ** arg : additive parameter ** Output: ** 0 : OK ** other : not OK ** Created by : Chenxibing ** Created Date : 2005-12-27 **----------------------------------------------------------------------------------------------------- ** Modified by : ** Modified Date: **----------------------------------------------------------------------------------------------------- ******************************************************************************************************* */ static int magic_leds_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { if (arg > 4) return -EINVAL; switch(cmd) { case 0: case 1: write_gpio_bit(leds_table[arg], cmd); default: return -EINVAL; } } /* ******************************************************************************************************* ** Function name: magic_leds_open() ** Descriptions : open leds ** Input: ** inode : information of device ** filp : pointer of file ** Output: ** 0 : OK ** other : not OK ** Created by : Chenxibing ** Created Date : 2005-12-27 **----------------------------------------------------------------------------------------------------- ** Modified by : ** Modified Date: **----------------------------------------------------------------------------------------------------- ******************************************************************************************************* */ static int magic_leds_open(struct inode *inode, struct file *filp) { int i; for (i = 0; i < 5; i++) { set_gpio_ctrl (leds_table[i] | GPIO_PULLUP_EN | GPIO_MODE_OUT); write_gpio_bit(leds_table[i], 1); } MOD_INC_USE_COUNT; printk(KERN_INFO DEVICE_NAME ": opened.\n"); return 0; } /* ******************************************************************************************************* ** Function name: magic_leds_release() ** Descriptions : release leds ** Input: ** inode : information of device ** filp : pointer of file ** Output: ** 0 : OK ** other : not OK ** Created by : Chenxibing ** Created Date : 2005-12-27 **----------------------------------------------------------------------------------------------------- ** Modified by : ** Modified Date: **----------------------------------------------------------------------------------------------------- ******************************************************************************************************* */ static int magic_leds_release(struct inode *inode, struct file *filp) { MOD_DEC_USE_COUNT; printk(KERN_INFO DEVICE_NAME ": released.\n"); return 0; } /* ******************************************************************************************************* ** operations of the driver ******************************************************************************************************* */ static struct file_operations magic_leds_fops = { owner: THIS_MODULE, ioctl: magic_leds_ioctl, open: magic_leds_open, release: magic_leds_release, }; /* ******************************************************************************************************* ** Function name: magic_leds_init() ** Descriptions : register driver ** Input: ** : NONE ** Output: ** 0 : OK ** other : not OK ** Created by : Chenxibing ** Created Date : 2005-12-27 **----------------------------------------------------------------------------------------------------- ** Modified by : ** Modified Date: **----------------------------------------------------------------------------------------------------- ******************************************************************************************************* */ static devfs_handle_t devfs_handle; static int __init magic_leds_init(void) { // int result; // result = register_chrdev(0, DEVICE_NAME, &magic_leds_fops); // if (result < 0) // { // printk(KERN_ERR DEVICE_NAME ": Failed to register major.\n"); // return result; // } devfs_handle = devfs_register(NULL, DEVICE_NAME, DEVFS_FL_AUTO_DEVNUM, 0, 0, S_IFCHR | S_IRUSR | S_IWUSR, &magic_leds_fops, NULL); printk(KERN_INFO DEVICE_NAME ": Initialize OK.\n"); return 0; } /* ******************************************************************************************************* ** Function name: magic_leds_exit() ** Descriptions : unregister driver ** Input: ** : NONE ** Output: ** 0 : OK ** other : not OK ** Created by : Chenxibing ** Created Date : 2005-12-27 **----------------------------------------------------------------------------------------------------- ** Modified by : ** Modified Date: **----------------------------------------------------------------------------------------------------- ******************************************************************************************************* */ static void __exit magic_leds_exit(void) { devfs_unregister(devfs_handle); // unregister_chrdev(0, DEVICE_NAME); } module_init(magic_leds_init); module_exit(magic_leds_exit); /* ******************************************************************************************************** ** End of File ******************************************************************************************************** */
评论
    相关推荐