📄 4leds.c
字号:
#include <linux/kernel.h>
#include <linux/module.h>
//#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/devfs_fs_kernel.h> //增加一条2.6内核下的头文件,以支持文件系统;对于devfs_mk_cdev重要
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/hardware.h>
#include <asm/arch-s3c2410/map.h>
#include <asm/arch-s3c2410/regs-gpio.h>
#define LED_ON 0
#define LED_OFF 1
#define DEVICE_NAME "IO"
//#define IO_MAJOR 0
#define IO_MINOR 1 //次设备号
static int IO_MAJOR = 0;
int IO_ioctl(struct inode *inode, struct file *flip, unsigned int cmd,unsigned long arg)
{
__raw_writel(cmd,S3C2410_GPFDAT);
return 0;
}
int IO_open(struct inode *inode, struct file *flip)
{
// __raw_writel(0x5500,S3C2410_GPFCON);
// __raw_writel(0xf0,S3C2410_GPFUP);
// __raw_writel(0x00,S3C2410_GPFDAT);
printk( "IO device opened\n");
return 0;
}
int IO_release(struct inode *inode, struct file *flip)
{
printk("IO device closed \n");
return 0;
}
struct file_operations IO_fops=
{
.owner = THIS_MODULE,
.open = IO_open,
.ioctl = IO_ioctl,
.release = IO_release,
};
int IO_init(void)
{
int ret;
__raw_writel(0x5500,S3C2410_GPFCON);
__raw_writel(0xf0,S3C2410_GPFUP);
__raw_writel(0x00,S3C2410_GPFDAT);
//printk(DEVICE_NAME":init OK \n");
ret = register_chrdev(IO_MAJOR, DEVICE_NAME, &IO_fops);
if(ret<0)
{ printk(DEVICE_NAME " can't get major number\n");
return ret;
}
IO_MAJOR = ret;
devfs_mk_cdev(MKDEV(IO_MAJOR,IO_MINOR),S_IFCHR | S_IRUSR | S_IWUSR|S_IRGRP,"IO/0"); //devfs_mk_cdev创建设备节点
printk(DEVICE_NAME":init OK\n");
return 0;
}
void IO_exit(void)
{
printk("call IO_exit \n");
unregister_chrdev(IO_MAJOR,DEVICE_NAME);
}
module_init(IO_init);
module_exit(IO_exit);
MODULE_LICENSE("Dual BSD/GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -