Tiny6410下的第一个Linux驱动程序
Linux系统环境是照着友善之臂的教程搭建的
//Hello World驱动程序源文件
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h> #include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/ioctl.h>
#include <linux/cdev.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h> #include <mach/map.h>
#include <mach/regs-clock.h>
#include <mach/regs-gpio.h> #include <plat/gpio-cfg.h>
#include <mach/gpio-bank-e.h>
#include <mach/gpio-bank-k.h>
#include <asm/io.h>
#include <linux/device.h>
//驱动读函数
static int first_drv_open(struct inode *inode, struct file
*file)
{
printk("Hello Driver\n");
return
0;
}
//驱动写函数
static ssize_t first_drv_write(struct file *file,
const char __user *buf, size_t count, loff_t * ppos)
{
printk("Hello
World\n");
return 0;
}
//定义file_operations结构体
static struct
file_operations first_drv_fops =
{
.owner = THIS_MODULE,
//这是一个宏,推向编译模块时自动创建的__this_module变量
.open = first_drv_open,
.write = first_drv_write,
};
//驱动入口函数
static int
first_drv_init(void)
{
register_chrdev(111, "first_drv",
&first_drv_fops);//向内核注册驱动
return 0;
}
static void
first_drv_exit(void)
{
unregister_chrdev(111, "first_drv");
//卸载驱动
}
module_init(first_drv_init);//定义一个结构体,供内核调用入口函数(first_drv_init--函数指针)
module_exit(first_drv_exit);//
Makefile文件
obj-m += first_drv.o #制定目标名
KDIR = /opt/FriendlyARM/mini6410/linux/linux-2.6. #指定内核路径
all :
make -C $(KDIR) M=$(PWD) modules CROSS_COMPILE=arm-linux- ARCH=arm
clean :
rm -f *.ko *.o *.mod.o *.mod.c *.symvers *.bak *.order
//测试驱动的程序
//测试程序要用arm-linux-gcc来编译
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> int main(int argc, char **argv)
{
int fd;
int val = ;
fd = open("/dev/xxx", O_RDWR);
if (fd < )
{
printf("can't open!\n");
} write(fd, &val, );
return ;
}
加载内核步骤
1、将编译好的驱动文件--first_drv.ko 和测试程序--firstdevtest 发送到Tiny6410上。
2、执行命令 insmod first_drv.ko //加载内核驱动 使用 cat /proc/devices 命令查看加载的驱动
3、执行命令 mknod /dev/xxx c 111 0 //创建设备节点 在/dev目录下生成xxx文件 主设备号为111 次设备号为0
4、执行命令 ./firstdrvtest //执行测试程序 出现Hello Wrold 成功!
Tiny6410下的第一个Linux驱动程序的更多相关文章
- 第六章 第一个Linux驱动程序:统计单词个数
现在进入了实战阶段,使用统计单词个数的实例让我们了解开发和测试Linux驱动程序的完整过程.第一个Linux驱动程序是统计单词个数. 这个Linux驱动程序没有访问硬件,而是利用设备文件作为介质与应用 ...
- 第六章 第一个Linux驱动程序: 统计单词个数
一.编写Linux驱动程序的步骤 第1 步:建立Linux 驱动骨架(装载和卸载Linux 驱动) 骨架部分主要是Linux驱动的初始化和退出函数,代码如下: #include <linux/m ...
- 第6章 第一个Linux驱动程序:统计单词个数
编写一个Linux的一般步骤: 第1步:建立Linux驱动骨架(装载和卸载Linux驱动) 第2步:注册和注销设备文件 第3步:指定和驱动相关的信息 第4步:指定回调函数 第5步:编写业务逻辑 第6步 ...
- 【转】第一个Linux内核驱动程序
原文网址:http://blog.csdn.net/nexttake/article/details/8181008 刚看 O’REILLY 写的<LINUX 设备驱动程序>时.作者一再强 ...
- 推荐一个linux下的web压力测试工具神器webbench
推荐一个linux下的web压力测试工具神器webbench2014-04-30 09:35:29 来源: 评论:0 点击:880 用多了apache的ab工具之后你就会发现ab存在很多问题, ...
- 在linux下,查看一个运行中的程序, 占用了多少内存
1. 在linux下,查看一个运行中的程序, 占用了多少内存, 一般的命令有 (1). ps aux: 其中 VSZ(或VSS)列 表示,程序占用了多少虚拟内存. RSS列 表示, 程序占用了多少物 ...
- 一个linux下简单的纯C++实现Http请求类(GET,POST,上传,下载)
目录 一个linux下简单的纯C++实现Http请求类(GET,POST,上传,下载) Http协议简述 HttpRequest类设计 请求部分 接收部分 关于上传和下载 Cpp实现 关于源码中的Lo ...
- Remmina:一个 Linux 下功能丰富的远程桌面共享工具(转载)
Remmina:一个 Linux 下功能丰富的远程桌面共享工具 作者: Aaron Kili 译者: LCTT geekpi | 2017-05-10 09:05 评论: 2 收藏: 4 Remm ...
- Linux驱动程序学习【转】
本文转载自: 一直在学习驱动,对于下面这篇文章,本人觉得简洁明了,基本符合我们学习驱动的进度与过程,现转发到自己的博客,希望能与更多的朋友分享. 了解Linux驱动程序技巧学习的方法很重要,学习lin ...
随机推荐
- 以太访solidity常用的函数有哪些
以太坊:什么是ERC20标准? 不以规矩,不能成方圆 许多人应该都听过 代码即法律(Code Is Law),因为程序写完了,无论执行多少次都会得到同样的结果,除非有外界因素的干扰.在多人协作的过程中 ...
- Spring 笔记(三)Bean 装配
前言 Spring 有两大核心,也就分成两份笔记分别记录. 其一是管理应用中对象之间的协作关系,实现方式是依赖注入(DI),注入依赖的过程也被称为装配(Wiring). 基于 JavaConfig 的 ...
- poj1273 网络流入门题 dinic算法解决,可作模板使用
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 62078 Accepted: 2384 ...
- SheetJS & Error: Sheet names cannot exceed 31 chars
SheetJS Error: Sheet names cannot exceed 31 chars title + version https://github.com/SheetJS/js-xlsx ...
- 第八篇:python基础_8 面向对象与网络编程
本篇内容 接口与归一化设计 多态与多态性 封装 面向对象高级 异常处理 网络编程 一. 接口与归一化设计 1.定义 (1)归一化让使用者无需关心对象的类是什么,只需要知道这些对象都具备某些功能就可以了 ...
- [UOJ#131][BZOJ4199][NOI2015]品酒大会
[UOJ#131][BZOJ4199][NOI2015]品酒大会 试题描述 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品酒家”和“首席猎手”两个 ...
- [codeforces] 359D Pair of Numbers
原题 RMQ st表棵题 要想让一个区间里的所有数都可以整除其中一个数,那么他一定是这个区间内的最小值,并且同时是这个区间的gcd.然后这个问题就转化成了RMQ问题. 维护两个st表,分别是最小值和g ...
- BZOJ 1861: [Zjoi2006]Book 书架 | SPlay 板题
#include<cstdio> #include<algorithm> #include<cstring> #define N 80010 #define whi ...
- mysql慢查询工具
GeorgeHao 安装过程: [root@localhost-centos6 ~]# wget percona.com/get/pt-query-digest [root@localhost-cen ...
- 切换cmd的目录
http://jingyan.baidu.com/article/af9f5a2d20253343140a450f.html