简单应用调用驱动
需要的用到的头文件 (在编译器内)
- <studio.h> 用于打印,
- <sys/types.h> 基本数据类型根据编译环境决定32 位还是64位
- <stat.h> 系统嗲用函数的头文件可以调用普通文件目录管道,socket,字符,块属性,
- <fcntl.h> 定义了open 函数 <unistd.h> 定义了close函数
- <sys/ioctl.h> 定义了ioctl 函数 往驱动发命令的函数
源码
#include <studio.h>;
#include <sys/types.h>;
#include <stat.h>;
#include <fcntl.h>;
#include <unistd.h>;
#include <sys/ioctl.h>;
int main()
{
int fd;
char *hello_node = "/dev/hello_ctl123";
//O_RDWR 只读打开 |O_NDELAY 非阻塞方式打开
fd = open(hello_node,O_RDWR|O_NDELAY);
if(fd < 0){
printk("APP_open %s failed",hello_node);
return 0;
}
printk("APP_open %s success",hello_node);
ioctl(fd,1,6);
close(fd);
}
编译demo
// 免依赖库编译
arm-none-linux-gnueabi-gcc -o invoke_hello invoke_hello.c -static
加载设备并执行应用程序可以看到相应的打印