• 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]);    /* 要执行的操作:打开或关闭 */获取

  • 相关阅读:
    贝叶斯与卡尔曼滤波(1)--三大概率
    Apache Doris 系列: 基础篇-Stream Load
    C++ 哈希表的总结与例题
    ES6之函数的扩展
    51单片机定时炸弹-准确计时-两根线随机一根触发中断可“拆弹“(AT89C52)
    全志A33使用主线U-Boot方法
    安利几个小技巧教会你ppt如何转pdf
    Flutter: Dart 参数,以及 @required 与 required
    简易绘图 DataFrame.plot
    javaweb部署web工程到tomcat中
  • 原文地址:https://blog.csdn.net/L1153413073/article/details/125500727