• arm-linux 应用层调用驱动函数


    需要调用头文件

    #include "stdio.h"

    #include "unistd.h" 

     /*

    unistd.h 是 C 和 C++ 程序设计语言中提供对 POSIX 操作系统 API 的访问功能的头文件的名称。该头文件由 POSIX.1 标准(单一UNIX规范的基础)提出,故所有遵循该标准的操作系统和编译器均应提供该头文件(如 Unix 的所有官方版本,包括 Mac OS X、Linux 等)。

    对于类 Unix 系统,unistd.h 中所定义的接口通常都是大量针对系统调用的封装(英语:wrapper functions),如 fork、pipe 以及各种 I/O 原语(read、write、close 等等)。
    */

    #include "sys/types.h" //数据类型

    #include "sys/stat.h"

    /*

    #include <sys/stat.h> 文件状态,是unix/linux系统定义文件状态所在的伪标准头文件。

    */

    #include "fcntl.h"

    //引用linux c头文件#include<sys/types.h>和#include<fcntl.h>头文件总结_码莎拉蒂 .的博客-CSDN博客

    #include "stdlib.h"

    #include "string.h"

    1. #include "stdio.h"
    2. #include "unistd.h"
    3. #include "sys/types.h"
    4. #include "sys/stat.h"
    5. #include "fcntl.h"
    6. #include "stdlib.h"
    7. #include "string.h"
    8. #define LEDOFF 0
    9. #define LEDON 1
    10. /*
    11. * @description : main主程序
    12. * @param - argc : argv数组元素个数
    13. * @param - argv : 具体参数
    14. * @return : 0 成功;其他 失败
    15. */
    16. int main(int argc, char *argv[])
    17. {
    18. int fd, retvalue;
    19. char *filename;
    20. unsigned char databuf[1];
    21. if(argc != 3){
    22. printf("Error Usage!\r\n");
    23. return -1;
    24. }
    25. filename = argv[1];
    26. /* 打开led驱动 */
    27. fd = open(filename, O_RDWR);
    28. if(fd < 0){
    29. printf("file %s open failed!\r\n", argv[1]);
    30. return -1;
    31. }
    32. databuf[0] = atoi(argv[2]); /* 要执行的操作:打开或关闭 */
    33. /* 向/dev/led文件写入数据 */
    34. retvalue = write(fd, databuf, sizeof(databuf));
    35. if(retvalue < 0){
    36. printf("LED Control Failed!\r\n");
    37. close(fd);
    38. return -1;
    39. }
    40. retvalue = close(fd); /* 关闭文件 */
    41. if(retvalue < 0){
    42. printf("file %s close failed!\r\n", argv[1]);
    43. return -1;
    44. }
    45. return 0;
    46. }

    在开发板运行/ledApp /dev/gpioled 1     gpioled为驱动的名字 通过filename = argv[1]获取;

                                    1位值 通过    databuf[0] = atoi(argv[2]);    /* 要执行的操作:打开或关闭 */获取

  • 相关阅读:
    3款超实用的电脑软件,免费又良心,内存满了也绝不卸载
    强化学习中值的迭代
    elementui table 合并列
    实用工具系列 - FileZilla安装下载与使用
    UDP协议
    Jolokia 笔记 (Kafka/start/stop)
    alibaba.fastjson的使用(二)-- jar包导入
    【开源】基于Vue和SpringBoot的网上药店系统
    阿里云物联网平台app端一直上线下线
    李沐_动手学深度学习第5章卷积神经网络_笔记
  • 原文地址:https://blog.csdn.net/L1153413073/article/details/125500727