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

📄 hello.c

📁 我自己写的2.4版本下的驱动程序
💻 C
字号:
#ifndef __KERNEL__   #define __KERNEL__#endif#ifndef MODULE   #define MODULE#endif#include <linux/kernel.h>#include <linux/module.h>#include <linux/compatmac.h>#include <linux/hdreg.h>#include <linux/vmalloc.h>#include <linux/fs.h>#include <linux/blkpg.h>#include <linux/slab.h>#include <linux/mm.h>#include <linux/wrapper.h>#include <linux/miscdevice.h>#include <asm/io.h>//#include <asm/system.h>#include <asm/dma.h>#include <asm/arch/gpio.h>#include "type.h"#include "mx2.h"#define open_hello  1#define open_hello2  2static int gMajor;static int hello_open(struct inode *inode, struct file *filp);static int hello_release(struct inode *inode, struct file *filp);static ssize_t hello_read(struct file *filp, char *buf, size_t count, loff_t *f_pos);static ssize_t hello_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos);static int hello_ioctl(struct inode * inode,		struct file *filp,		unsigned int cmd ,		unsigned long arg);static void Delay(int time);struct file_operations hello_fops = {	open: 	hello_open,	release:	hello_release,	read:	hello_read,	write:	hello_write,	ioctl:	hello_ioctl,};static void Delay(int time){	while(time--);	return;}void show_hello(void){	printk("hello my driver\n");}static int hello_open(struct inode *inode, struct file *filp){	MOD_INC_USE_COUNT;	printk("hello opening\n");    return 1;}static ssize_t  hello_read(struct file *filp, char *buf, size_t count, loff_t *f_pos){		return 1;}static ssize_t hello_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos){		return 1;}static int hello_ioctl(struct inode * inode,		struct file *filp,		unsigned int cmd ,		unsigned long arg){	switch(cmd)	{	case open_hello:		show_hello();		break;	case open_hello2:		break;	}	return 0;}static int hello_release(struct inode *inode, struct file *filp){	MOD_DEC_USE_COUNT;		return 0;}static devfs_handle_t devfs_handle;int init_module(){	int result;	printk("hello driver version 1.0  "__DATE__" / "__TIME__"\n");	result = devfs_register_chrdev(0, "hello", &hello_fops);	if ( result < 0 )	{		printk("hello error: Unable to register driver\n");				return -ENODEV;	}	devfs_handle =devfs_register(NULL, "hello", DEVFS_FL_DEFAULT,			      result, 0,			      S_IFCHR | S_IRUSR | S_IWUSR,			      &hello_fops, NULL);	gMajor = result;			return 0;}void cleanup_module(){	if(gMajor>0)	{		devfs_unregister_chrdev(gMajor,"hello");		devfs_unregister(devfs_handle);	}}

⌨️ 快捷键说明

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