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

📄 gpio_drv.c

📁 s3c2410 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/arch/cpu_s3c2410.h>
#include <asm/io.h>
#include <linux/vmalloc.h>





MODULE_LICENSE("GPL");

#define GPIO_MAJOR 220	/* 定义主设备号*/
#define gpio_name "gpio"
#define initial()     (GPFDAT=0xFF)
#define LED1_ON()	(GPFDAT &= ~0x50)
#define LED2_ON()	(GPFDAT &= ~0xA0)


#define LED1_OFF()	(GPFDAT |=0x50)
#define LED2_OFF()	(GPFDAT |=0xA0)


void LedDisp(void)
{
	LED1_ON();	
	udelay(0xf00000);       udelay(0xf00000);
	LED1_OFF();
	udelay(0xf00000);       udelay(0xf00000);
	LED2_ON();	
	udelay(0xf00000);       udelay(0xf00000);
	LED2_OFF();
	udelay(0xf00000);       udelay(0xf00000);       LED1_ON();	
	udelay(0xf00000);       udelay(0xf00000);
	LED1_OFF();
	udelay(0xf00000);       udelay(0xf00000);
	LED2_ON();	
	udelay(0xf00000);       udelay(0xf00000);
	LED2_OFF();
	udelay(0xf00000);       udelay(0xf00000);       LED1_ON();	
	udelay(0xf00000);       udelay(0xf00000);
	LED1_OFF();
	udelay(0xf00000);       udelay(0xf00000);
	LED2_ON();	
	udelay(0xf00000);       udelay(0xf00000);
	LED2_OFF();
	udelay(0xf00000);       udelay(0xf00000);
	
	
}

static ssize_t gpio_read(struct file *filp,char *buf,size_t count,loff_t *l)
{
	return count;
}

static ssize_t gpio_write(struct file *filp,const char *buf,size_t count,loff_t *f_ops)
{
	return count;
}

static int gpio_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
	int err=0;
	if(cmd ==1){                initial();
		while(arg--)
		{
			LedDisp();
			printk("...");
		}
		printk("\n");
		return 0;
	}
	return err;
	  
}

static int gpio_open(struct inode *inode, struct file *filp)
{
	GPFCON = 0x5500;
	GPFUP = 0xff;
	printk("open gpio devices\n");
	return 0;
}
static int gpio_release(struct inode *inode, struct file *filp)
{
	printk("device release!\n");
	return 0;
}

static struct file_operations gpio_fops = 
{
	owner:	 THIS_MODULE,
	read	:	gpio_read,
	write	:	gpio_write,
	ioctl	:	gpio_ioctl,
	open	:	gpio_open,
	release	:	gpio_release,
};

static int __init gpio_init(void)
{
	int retval;
	printk("gpio_init\n");
	retval = register_chrdev(GPIO_MAJOR,gpio_name,&gpio_fops);
	if(retval < 0)
	{
		printk(KERN_WARNING"Can't get major %d\n",GPIO_MAJOR);
		return retval;
	}
	printk("GPIO driver register success!\n");
	return 0;
}
static void __exit gpio_exit(void)
{
	unregister_chrdev(GPIO_MAJOR,"GPIO");
	printk("GPIO driver release success!\n");

}
module_init(gpio_init);
module_exit(gpio_exit);


⌨️ 快捷键说明

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