linux驱动程序实例
本例是冯国进的 《嵌入式Linux 驱动程序设计从入门到精通》的第一个例子
感觉真是好书 强烈推荐
注释是deep_pro加的 转载请注明!我的特点是文不加点!
这个驱动是在内存中分配一个256字节的空间,供用户态应用程序读写。
先是头文件 demo.h
#ifndef _DEMO_H_
#define _DEMO_H_
#include <linux/ioctl.h> /* needed for the _IOW etc stuff used later */
/********************************************************
* Macros to help debugging
********************************************************/
#undef PDEBUG /* undef it, just in case */
#ifdef DEMO_DEBUG
#ifdef __KERNEL__
# define PDEBUG(fmt, args...) printk( KERN_DEBUG "DEMO: " fmt, ## args)
#else//usr space
# define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
#endif
#else
# define PDEBUG(fmt, args...) /* not debugging: nothing */
#endif
#undef PDEBUGG
#define PDEBUGG(fmt, args...) /* nothing: it's a placeholder */
//设备号
#define DEMO_MAJOR 224
#define DEMO_MINOR 0
#define COMMAND1 1
#define COMMAND2 2
//自己定义的设备结构
struct DEMO_dev
{
struct cdev cdev; /* Char device structure */
};
//函数申明 原来Linux驱动程序设计这么简单 只需要实现这么几个函数就可以了
ssize_t DEMO_read(struct file *filp, char __user *buf, size_t count,
loff_t *f_pos);
ssize_t DEMO_write(struct file *filp, const char __user *buf, size_t count,
loff_t *f_pos);
loff_t DEMO_llseek(struct file *filp, loff_t off, int whence);
int DEMO_ioctl(struct inode *inode, struct file *filp,
&nbs
相关文档:
随着硬件不断的发展,未来的智能手机将越来越接近PC的性能,一个强大的手机操作系统将是挖掘不断飞跃的手机硬件性能的关键,只有强大的操作系统才能支持各种不断发展的手机应用,如Linux系统对java的完美支持以及优越的多进程调度,摩托罗拉很早就推出基于Linux系统的手机,随着Google的Android操作系统的推出,另一个基于L ......
一、下载安装程序
1、 下载内核源码(linux-2.6.33.tar.bz2),位置:https://www.kernel.org
2、 下载最新版的module-init-tools(module-init-tools-3.8.tar.bz2)和modutils(modutils-2.4.26-1.src.rpm)的源码
位置:http://www.kernel.org/pub/linux/kernel/people/rusty/modules/
位置:http://www. ......
先用who命令查看所有登陆终端
#who -uH
输出如下:
NAME LINE TIME IDLE PID COMMENT
root :0 2010-03-01 19:13 ? & ......
在类unix
操作系统
中,驱动
加载
方式一般分为:动态加载和静态加载,下面分别对其详细论述。
一、动态加载
动态加载是将驱动模块加载到内核
中,而不能放入/lib/modules/下。
在2.4内核中,加载驱动命令
为:insmod ,删除模块为:rmmod;
在2 ......