?? led.c
字號:
#include <linux/config.h>#include <linux/init.h>#include <linux/module.h>#include <linux/fs.h>#include <linux/iobuf.h>#include <linux/kernel.h>#include <linux/major.h>#include <asm/uaccess.h>#include <asm/hardware.h>#include <asm-arm/arch-s3c2410/cpu_s3c2410.h>#include <asm/io.h>#include <linux/vmalloc.h>#define IOPORT_MAJOR 220 int gpio_open(struct inode*,struct file*);int gpio_release(struct inode*,struct file*);int gpio_ctl_ioctl(struct inode*,struct file*,unsigned int,unsigned long);static struct file_operations gpio_ctl_fops={ioctl: gpio_ctl_ioctl, open : gpio_open, release: gpio_release,}; #define LED1_ON() (GPFDAT &= ~0x10)#define LED2_ON() (GPFDAT &= ~0x20)#define LED3_ON() (GPFDAT &= ~0x40)#define LED4_ON() (GPFDAT &= ~0x80)#define LED1_OFF() (GPFDAT |= 0x10)#define LED2_OFF() (GPFDAT |= 0x20)#define LED3_OFF() (GPFDAT |= 0x40)#define LED4_OFF() (GPFDAT |= 0x80)static int LedStatus;void LedSet(int led){LedStatus = led;if(LedStatus&1) LED1_ON();elseLED1_OFF();if(LedStatus&2) LED2_ON();elseLED2_OFF();if(LedStatus&4) LED3_ON();elseLED3_OFF();if(LedStatus&8) LED4_ON();elseLED4_OFF();} void udelay(unsigned int time){unsigned int a,b;for(a=0;a<time;a++) for(b=0;b<a;b++);}void LedDisp(void){LedSet(0x08);udelay(0x500000);LedSet(0x04);udelay(0x500000);LedSet(0x02);udelay(0x500000);LedSet(0x01);udelay(0x500000);LedSet(0x02);udelay(0x500000);LedSet(0x04);udelay(0x500000);LedSet(0x08);udelay(0x500000);}static int __init gpio_init(void){int err=0;printk("gpio_init\n"); err=register_chrdev(IOPORT_MAJOR,"gpio",&gpio_ctl_fops); if(err){ printk("fail to register\n");return -1;} printk("success to register\n");return 0;}int gpio_open(struct inode *inode,struct file *fllp){GPFCON=0x5500;GPFUP=0xff;printk("open gpio devices\n");return 0;}int gpio_release(struct inode *inode,struct file *filp){printk("release this device\n");return 0;}int gpio_ctl_ioctl(struct inode *inode,struct file *flip,unsigned int command, unsigned long arg){int err=0;if(command==1){while(arg--){ LedDisp(); printk("...."); } printk("\n"); return 0;} return err;}module_init(gpio_init);module_exit(gpio_release);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -