目标:编写应用程序调用驱动-调用HELLO_CTL123设备节点
头文件
1.打印头文件
**include<stdio.h>**调用打印函数 printf
应用中调用文件需要的头文件
**#include<sys/types.h>**基本系统数据类型。系统的基本数据类型。系统的基本数据类型在32编译环境中保持为32位值,并会在64编译环境中增长为64位值。
**#include<sys/stat.h>**系统调用函数头文件。可以调用普通文件,目录,管道,socket字符,块的属性
**#include<fcntl.h>**定义了open函数
**#include<unistd.h>**定义了close函数
**#include<sys/ioctl.h>**定义了ioctl函数
编写应用调用驱动
一、调用函数
open函数是返回文件描述符
ioctl函数是应用向驱动传值
close函数是关闭打开的文件
二、编写应用程序的代码,编译
arm-none-linux-gnueabi-gcc -o iinvoke_hello invoke_hello.c -static
三、开发板中加载devicenode_linux_module驱动,运行应用
1.新建invoke_hello.c文件
root@ubuntu:/home/topeet/android4.0/Code/invoke_hello# vim invoke_hello.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
main(){
int fd;
char *hello_node = "/dev/hello_ctl123";
/*O_RDWR只读打开,O_NDELAY非阻塞方式*/
if((fd = open(hello_node,O_RDWR|O_NDELAY))<0){
printf("APP open %s failed",hello_node);
}
else{
printf("APP open %s success",hello_node);
ioctl(fd,1,6);
}
close(fd);
}
2.执行编译
root@ubuntu:/home/topeet/android4.0/Code/invoke_hello# arm-none-linux-gnueabi-gcc -o invoke_hello invoke_hello.c -static
3.4412开发板执行
telnet 192.168.1.230
root
mount /dev/udisk /mnt/usb1
cp invoke_hello /
./invoke_hello