刚做完了内核的编译,便开始驱动的静态内核编译。郁闷了好几天终于实现了把驱动编译进内核,并做了相应的测试,驱动能正常工作。为和大家学习和交流,我把所做的工作以及源程序都写出来,希望大家能共同进步。
下面就开始我的字符驱动编译了:
字符驱动程序如下:
baovar.h文件:
#include
#define BAO_IOCTL 't'
#define IOCTL_READ _IOR(BAO_IOCTL, 0, int)
#define IOCTL_WRITE _IOW(BAO_IOCTL, 1, int)
#define BAO_IOCTL_MAXNR 1
baovar.c文件:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include"baovar.h"
MODULE_LICENSE("GPL");
static int MAJOR_NUM=250;//澶囧彿
static devfs_handle_t devfs_handle;
ssize_t bao_read (struct file*,char*,size_t,loff_t*);
ssize_t bao_write (struct file*,const char*,size_t,loff_t*);
int bao_ioctl(struct inode *inode,struct file*filp,unsigned int cmd,unsigned long args);
int bao_open(struct inode *inode,struct file *filp);
int bao_release(struct inode *inode,struct file *filp);
//鍒濆?鍖杅ile_operations
struct file_operations bao_fops=
{
read:bao_read,
write:bao_write,
ioctl:bao_ioctl,
open:bao_open,
release:bao_release,
};
static int bao_var=0;//baovar璁惧?鐨勫叏灞
阅读(1581) | 评论(0) | 转发(0) |