📄 switch.c
字号:
#include <asm/irq.h>#include <linux/sched.h>#include <linux/signal.h>#include <linux/major.h>#include <linux/string.h>#include <linux/fcntl.h>#include <linux/slab.h>#include <linux/timer.h>#include <linux/module.h>#include <asm/system.h>#include <linux/config.h>#include <linux/utsname.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/poll.h>#define SWITCH_MAJOR 50typedef unsigned int U32; /* unsigned 32 bit data */static void Switch_hand(){ U32 delay; disable_irq(16); /*全暗*/ *(unsigned char*)0xff000000 &= ~0xff; *(unsigned char*)0xff000001 &= ~0xff; for(delay=10000000;delay>0;delay--); /*从左到右依次亮*/ *(unsigned char*)0xff000001 |= 0x80; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x40; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x20; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x10; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x08; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x04; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x02; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x01; for(delay=1000000;delay>0;delay--); /***************************************/ *(unsigned char*)0xff000000 |= 0x80; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000000 |= 0x40; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000000 |= 0x20; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000000 |= 0x10; for(delay=1000000;delay>0;delay--); /***************************************/ /*全暗*/ *(unsigned char*)0xff000000 &= ~0xff; *(unsigned char*)0xff000001 &= ~0xff; for(delay=10000000;delay>0;delay--); /*从右到左依次亮*/ *(unsigned char*)0xff000000 |= 0x10; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000000 |= 0x20; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000000 |= 0x40; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000000 |= 0x80; for(delay=1000000;delay>0;delay--); /********************************/ *(unsigned char*)0xff000001 |= 0x01; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x02; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x04; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x08; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x10; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x20; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x40; for(delay=1000000;delay>0;delay--); *(unsigned char*)0xff000001 |= 0x80; for(delay=1000000;delay>0;delay--); /*Port A*/ *(unsigned char*)0xff000000 &= ~0xff; /*Port B*/ *(unsigned char*)0xff000001 &= ~0xff;}static int Switch_Close(struct inode * inode, struct file * file){ return 0;}static int Switch_Open(struct inode * inode, struct file * file){ return 0;}static int Switch_Read(struct file * file, char * buffer, size_t count, loff_t *ppos){ return 0;}static int Switch_Ioctl( struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ switch(cmd) { case 0: Switch_hand(); break; default: break; } return 0;}struct file_operations Switch_fops = { read: Switch_Read, open: Switch_Open, ioctl: Switch_Ioctl, release: Switch_Close,};int switch_init(void){ int rc; printk("Switch support \n "); rc = register_chrdev(SWITCH_MAJOR, "switch", &Switch_fops); if (rc < 0) { printk(KERN_WARNING "Switch: can't get Major %d\n", SWITCH_MAJOR); return rc; } /*Port A data direction register*/ *(unsigned char*)0xff000040 |=0xff; /*Port B data direction register*/ *(unsigned char*)0xff000041 |=0xff; return 0;}void switch_cleanup(void){ unregister_chrdev(SWITCH_MAJOR, "switch"); return;}module_init(switch_init);module_exit(switch_cleanup);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -