资源简介
LINUX的驱动例子,能启动字符设备,很有试验价值, 详细的代码以及完整的MAKEFILE是学习试验的绝好资料

代码片段和文件信息
/**
* A demo driver for simple Character device.“
*
* simple_chrdev.c
*
* Author Tianze Sun
*
* E-mail stz@cic.tsinghua.edu.cn
*
* Fri Jun 2th 20:32:43 GMT 2006
*
* Current version: 1.1.0
*
* All rights reserved. Licensed under dual BSD/GPL license.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define SIMPLE_PHYS_ADDR 0x1FFFFF7C //Address
#define SIZE_OF_SIMPLE 2 //2 Bytes
#define SIMPLE_TIMER_DELAY 1 // 1 ms
#define SIMPLE_IOCTL_MAGIC ‘K‘ //Magic
#define CMD1 _IOW(SIMPLE_IOCTL_MAGIC3unsigned long)
#define CMD2 _IOW(SIMPLE_IOCTL_MAGIC4unsigned long)
#define CMDn _IOW(SIMPLE_IOCTL_MAGIC5unsigned long)
#define SIMPLE_NAME “Simple“
int SIMPLE_MAJOR = 0;
int SIMPLE_MINOR = 0;
int SIMPLE_NUMBER = 1;
void __iomem *simple_addr_virt = NULL;
struct cdev *simple_cdev;
dev_t simple_dev;
int simple_open(struct inode *inode struct file *filp);
int simple_release(struct inode *inode struct file *filp);
int simple_ioctl (struct inode *inode struct file *file unsigned int cmd unsigned long arg);
static ssize_t simple_read(struct file * file char __user *buf size_t count loff_t *ppos);
static ssize_t simple_write(struct file *file const char __user *buf size_t len loff_t *ppos);
loff_t simple_llseek(struct file *fileloff_t offset int origin);
static struct timer_list simple_timer;
static void simple_timer_handler(unsigned long data);
extern struct file_operations simple_fops;
struct file_operations simple_fops =
{
.owner = THIS_MODULE
.llseek = simple_llseek
.open = simple_open
.read = simple_read
.write = simple_write
.ioctl = simple_ioctl
.release = simple_release
};
/* Open */
int simple_open(struct inode *inode struct file *filp)
{
printk(“Simple Device is opened\n“);
try_module_get(THIS_MODULE) ;
return 0 ;
}
/* Release */
int simple_release(struct inode *inode struct file *filp)
{
printk(“Simple Device is released!\n“);
module_put(THIS_MODULE) ;
return 0 ;
}
static ssize_t simple_read(struct file *filechar __user *bufsize_t countloff_t *ppos)
{
int rv = 0; /* Return Value */
if (count <= 0)
return count;
printk(“Reading Data now...\n“);
if (file->f_flags & O_NONBLOCK) {
rv = -EAGAIN;
return rv;
}
//Get data from Kernel space.
return rv;
}
/* Write */
static ssize_t simple_write(struct file *fileconst char __user *bufsize_t lenloff_t *ppos)
{
int rv = 0;
printk(“Writing Data now...\n“);
//Get data from User space.
return rv;
}
/* Llseek */
loff_t simple_llseek(struct file *file loff_t offset int origin)
{
long long retval =
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 764 2006-08-27 22:19 Chapter07\Makefile
文件 660 2006-08-27 22:19 Chapter07\Makefile.x86
文件 5899 2006-08-27 22:22 Chapter07\simple_chrdev.final.c
目录 0 2009-03-07 14:28 Chapter07
----------- --------- ---------- ----- ----
7323 4
- 上一篇:用kmeans得到二值分割后,再用svm进行图像分割
- 下一篇:XC886配套程序
相关资源
- mgn-mqt82.exe
- 蓝牙源代码应用于LINUX
- Trojan-Qt5-Windows-0.0.4.rar
- 酒店管理系统基于Qt Creator5)
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- vtk QT做的三维地质可视化系统2of2
- Qt局域网聊天软件
- ubuntu9.10 可加载内核模块和字符设备驱
- Qt Creator opengl实现四元数鼠标控制轨迹
- QT局域网聊天系统(基于QT5.修改过)
- qt-电子点菜系统
- MP3文件ID3v2ID3v2APEv2标签读取
- C 餐厅叫号系统(QT平)
- QT 实现文件下载
- qt图像处理
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- QT,JPEG解码源代码(已完成)
- linux下用多进程同步方法解决生产者
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
评论
共有 条评论