ubuntu 添加字符设备驱动程序

本文介绍如何在Ubuntu系统中从零开始制作一个简单的字符设备驱动,包括编写C语言驱动代码、创建Makefile、编译模块、加载及卸载驱动模块等步骤,并提供了测试驱动程序的方法。

ubuntu设备驱动是由装载模块的方式进行的

2.6.x核心模块在http://www.ibm.com/developerworks/cn/linux/l-module26/上可以下载

按照定义创建驱动文件

创建c文件 Drive.c

#include "linux/kernel.h"
#include "linux/module.h"
#include "linux/fs.h"
#include "linux/init.h"
#include "linux/types.h"
#include "linux/errno.h"
#include "linux/uaccess.h"
#include "linux/kdev_t.h"
 
#define MAX_SIZE 1024
 
int my_open(struct inode *inode, struct file *file);
int my_release(struct inode *inode, struct file *file);
ssize_t my_read(struct file *file, char __user *user, size_t t, loff_t *f);
ssize_t my_write(struct file *file, const char __user *user, size_t t, loff_t *f);
 
char message[MAX_SIZE] = "this is arafat(very shuai boy)'s Drive";  //打开设备时会显示的消息
int device_num;//设备号
char* devName = "arafatsDrive";//设备名
 
struct file_operations pStruct =
{ 
	open:my_open, 
	release:my_release, 
	read:my_read, 
	write:my_write, 
};
 
/* 注册 */
int init_module()
{
	int ret;
 
	ret = register_chrd
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值