⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leddrv.c

📁 基于AT91RM9200的led驱动及应用程序
💻 C
字号:
#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h>#include <asm/semaphore.h>#include <linux/pci.h>#include <linux/sched.h>#include <linux/fs.h>#include <linux/mm.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/irq.h>#include <linux/string.h>#include <linux/proc_fs.h>#include <asm/arch/pio.h>#include <asm/arch/AT91RM9200_SYS.h>#include <asm/arch/hardware.h>#include "leddrv.h"AT91PS_SYS sys= (AT91PS_SYS)AT91C_VA_BASE_SYS;static int led_open(struct inode *inode,struct file *filp){	printk("open led driver!\n");	return 0;}static int led_close(struct inode *inode,struct file *filp){      	printk("open close driver!\n");	return 0;}static int led_ioctl(struct inode * s_node,struct file * s_file,int cmd,unsigned long arg){             switch(cmd)       {        case CMD_LED_ON:		sys->PIOB_CODR |= (unsigned int)(1<<YELLOW)|(unsigned int)(1<<BLUE);    		printk("LED ON!\n");		break;        case CMD_LED_OFF:		sys->PIOB_SODR |= (unsigned int)(1<<YELLOW)|(unsigned int)(1<<BLUE);		printk("LED OFF!\n");		break;        case CMD_LED_CHANGE:		if (sys->PIOB_PDSR & ((unsigned int)(1<<YELLOW) | (unsigned int)(1<<BLUE)))			sys->PIOB_CODR |= (unsigned int)(1<<YELLOW) | (unsigned int)(1<<BLUE);		else			sys->PIOB_SODR |= (unsigned int)(1<<YELLOW) | (unsigned int)(1<<BLUE);		printk("LED CHANGE!\n");		break;        default:             break;       }      return 0;}/* ......................................................................... *///定义文件操作static struct file_operations led_fops={	open	:(void(*))led_open,	release	:(void(*))led_close,  	ioctl	:(void(*))led_ioctl,  };static int __init led_init_module(void){	int retv;	sys->PIOB_PER |= (unsigned int)(1<<YELLOW)|(unsigned int)(1<<BLUE);	sys->PIOB_OER |= (unsigned int)(1<<YELLOW)|(unsigned int)(1<<BLUE);	sys->PIOB_CODR |= (unsigned int)(1<<YELLOW)|(unsigned int)(1<<BLUE);		retv=register_chrdev(LED_MAJOR,led_name,&led_fops);	if(retv<0)	{		printk("Register Fail!\n");		return retv;	}	printk("LED driver OK!\n");	return 0;}static void __exit led_cleanup(void){	int retv;	retv=unregister_chrdev(LED_MAJOR, led_name);	if(retv<0)	{		printk("UnRegister Fail!\n");		return;	}      printk("LED driver bye!\n");}module_init(led_init_module);module_exit(led_cleanup);MODULE_LICENSE("GPL");MODULE_AUTHOR("CK ck@cugb.edu.cn");MODULE_DESCRIPTION("LED driver for MT-ARM");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -