#define LED_MODERE 0X50006000
#define LED_MODERF 0X50007000
#define LED_ODRE 0X50006014
#define LED_ODRF 0X50007014
#define LED_RCC 0X50000A28
int main(int argc, const char *argv[])
int fd=open("/dev/mychrdev",O_RDWR);
fgets(buf,sizeof(buf),stdin);
write(fd,buf,sizeof(buf));
memset(buf,0,sizeof(buf));
read(fd,buf,sizeof(buf));
#include <linux/module.h>
#include <linux/uaccess.h>
#include <linux/compiler.h>
unsigned int *vir_modere;
unsigned int *vir_moderf;
int mycdev_open(struct inode *inode,struct file *file)
printk("%s:%s:%d\n",__FILE__,__func__,__LINE__);
ssize_t mycdev_read(struct file *file,char *ubuf,size_t size,loff_t *lof)
ret=copy_to_user(ubuf,kbuf,size);
printk("copy_from_user err\n");
printk("%s:%s:%d\n",__FILE__,__func__,__LINE__);
ssize_t mycdev_write(struct file *file,const char *ubuf,size_t size,loff_t *lof)
ret=copy_from_user(kbuf,ubuf,size);
printk("copy_from_user err\n");
(*vir_odre) |= (0x1<<10);
(*vir_odrf) |= (0x1<<10);
printk("开灯-->%d\n",*kbuf);
(*vir_odre) &= (~(0x1<<10));
(*vir_odrf) &= (~(0x1<<10));
(*vir_odre) &= (~(0x1<<8));
printk("关灯-->%d\n",*kbuf);
printk("%s:%s:%d\n",__FILE__,__func__,__LINE__);
int mycdev_close(struct inode *inode,struct file *file)
printk("%s:%s:%d\n",__FILE__,__func__,__LINE__);
struct file_operations fops = {
static int __init mycdev_init(void)
major = register_chrdev(0,"mychrdev",&fops);
printk("字符设备驱动注册成功%d\n",major);
vir_rcc=ioremap(LED_RCC,4);
printk("物理映射失败%d\n",__LINE__);
vir_modere=ioremap(LED_MODERE,4);
printk("物理映射失败%d\n",__LINE__);
vir_moderf=ioremap(LED_MODERF,4);
printk("物理映射失败%d\n",__LINE__);
vir_odre=ioremap(LED_ODRE,4);
printk("物理映射失败%d\n",__LINE__);
vir_odrf=ioremap(LED_ODRF,4);
printk("物理映射失败%d\n",__LINE__);
(*vir_modere) &= (~(0x3<<20));
(*vir_modere) |= (0x1<<20);
(*vir_moderf) &= (~(0x3<<20));
(*vir_moderf) |= (0x1<<20);
(*vir_modere) &= (~(0x3<<16));
(*vir_modere) |= (0x1<<16);
(*vir_odre) &= (~(0x1<<10));
(*vir_odrf) &= (~(0x1<<10));
(*vir_odre) &= (~(0x1<<8));
static void __exit mycdev_exit(void)
unregister_chrdev(major,"mychrdev");
module_init(mycdev_init);
module_exit(mycdev_exit);