iTOP-4412 调用驱动应用

设备注册:https://blog.csdn.net/u011425939/article/details/80546761

驱动注册:https://blog.csdn.net/u011425939/article/details/80636776

前面介绍完设备的注册和对应的驱动注册过程,现在来讲讲怎么表用驱动写运用程序。

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函数

2、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";
	char buf[10]={0};
/*O_RDWR只读打开,O_NDELAY非阻塞方式*/	
	if((fd = open(hello_node,O_RDWR|O_NDELAY))<0){
		printf("APP open %s failed\n",hello_node);
	}
	else{
		printf("APP open %s success\n",hello_node);
		ioctl(fd,1,6);
	}
	read(fd,buf,sizeof(buf));
	write(fd,buf,sizeof(buf));
	
	close(fd);
}

3、编译

arm-none-linux-gnueabi-gcc -o invoke_hello invoke_hello.c

4、运行

[root@iTOP-4412]# 
[root@iTOP-4412]# ./invoke_hello 
[ 6564.326699] hello open
[ 6564.327709] cmd is 1,arg is 6
[ 6564.331677] helo_read
[ 6564.332798] helo_write
[ 6564.335163] write :hello word
[ 6564.338089] ppos :0
[ 6564.340215] hello release
APP open /dev/hello success
[root@iTOP-4412]#




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值