linux mmap驱动内核共享内存模块以及用户态测试

本文介绍了一个基于Linux的虚拟字符设备驱动程序的实现,包括设备注册、内存分配、读写操作及内存映射等功能。通过具体代码示例,展示了如何使用mmap进行设备内存的映射,并提供了一个测试程序来验证驱动的功能。
//micros_mmap.c
#include 	<linux/kernel.h>
#include	<linux/module.h>
#include	<linux/init.h>
#include 	<linux/slab.h>        /* kmalloc() */
#include	<linux/fs.h>
#include	<linux/mm.h>
#include	<linux/cdev.h>
#include	<linux/errno.h>
#include	<linux/types.h>
#include	<linux/interrupt.h>
#include	<linux/delay.h>
#include    <linux/errno.h>
#include    <linux/sched.h>
#include    <linux/semaphore.h>
//#include    <linux/system.h>
#include	<linux/uaccess.h>
//#include	<asm/arch/irqs.h>
#include 	<linux/io.h>
#include 	<linux/version.h>
//#include    <asm/hardware.h>
#include    <linux/delay.h>

//#include    <asm/arch/sep4020_hal.h>

#define	DRIVE_MAJOR				165
#define	DRIVE_NAME				"Test drv"
typedef	struct
{
	dev_t			dev_num ;
	struct	cdev	cdev ;	
			
}code_dev ;

static code_dev	test_dev ;
unsigned char data_source;
unsigned char *testmap;
//unsigned char *kmalloc_area;
void *kmalloc_area;
unsigned long  msize;
static int	test_open(struct inode *inode , struct file *filp)
{
	printk("<MICROS_MMAP> : I come in test_open function. \n");
	return 0 ;
}
static int	test_close(struct inode *inode , struct file *filp)
{
	printk("<MICROS_MMAP> : I come in test_close function. \n");
	return 0 ;
}

static ssize_t test_write(struct file *filp, const char __user *buf,size_t count,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值