?? 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 + -