通过编写简单的C语言程序调用已经加载的驱动程序,测试驱动程序的功能。
应用程序包含头文件有:
1.
#include <sys/types.h>
包含基本系统数据类型。系统的基本数据类型在32 编译环境中保持为32 位值,并会在64 编译环境中增长为64 位值
2.
头文件<sys/stat.h>包含系统调用文件的函数。可以调用普通文件、目录、管道、socket、字符、块的属性。
3.
<fcntl.h>定义了open 函数
4.
<unistd.h>定义了close 函数
5.
<sys/ioctl.h>定义了ioctl 函数
编写程序调用上一节注册的设备节点hello_ctl123
示例程序
#include<stdio.h>
#include<sys/type.h>
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/ioctl.h>
main(){
int fd;
char *hello_node = "/dev/hello_ctl123";
if((fd=open(hello_node,O_RDWR|O_NDELAY))<0){
printf("open %s failed",hello_node);
}
else{
printf("open %s success",hello_node);
ioctl(fd,1,6);
}
}
用ubuntu上的arm交叉编译器编译成执行文件,
通过tftp服务器下载到开发板上,加载上一节的设备节点hello_ctl123
,运行该程序,将打印
hello open
cmd is 1,arg is 6
hello release。
与驱动目标打印内容相同。