zoukankan      html  css  js  c++  java
  • 4412应用编程

    一、编写helloworld

    #inlcude <stdio.h>
    int main()
    {
        printf("Hello World!
    ");
        return 0;    
    }

    然后编译

    arm-none-linux-gnueabi-gcc helloworld.c -o helloworld -static

    然后复制到U盘中,插到开发板中后,插上会有信息是如sda1:

    mount /dev/sda1 /mnt/udisk/

    然后运行

    ./mnt/udisk/helloworld

    二、TF卡方式运行helloworld

    如果用读卡器插U盘,那过程和上面的一样。

    如果直接插TF卡卡槽,先建个文件夹

    cd /mnt
    mkdir
    udisk1

    然后插入TF卡,有一些信息打印出来

    mount /dev/mmcblklp1 /mnt/udisk1

    然后就可以运行了

    ./helloworld

    如果提示没有权限的话,chmod 777

    三、helloworld编译进最小文件系统

    先复制helloworld到最小文件中的bin目录

    cp -r helloworld /home/minilinux/system/bin/

    然后再次编译system.img

    ../system
    make_ext4fs -s -l 314572800 -a root -L linux system.img system

    然后重新烧写

    fastboot
    fastboot.exe flash system system.img
    fastboot -w
    fastboot reboot

    二、字符设备控制LED灯

    ioctl函数

    int ioctl( int fd, int request, int cmd);
    – 参数fd,函数open 返回的句柄
    – 参数request 和参数cmd,由内核驱动决定具体操作,例如request 可以
    代表那个IO 口
    – 参数cmd:代表对IO 进行什么样的操作,也可以反过来。具体的含义由
    驱动工程师在驱动中switch决定
    – 返回值:返回0 成功;返回-1,出错

    引脚拉高电平,电路就发光。拉低就断开

    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <string.h>
    #include <stdlib.h>
    
    #define LED_NUM 2
    #define LED_C   2
    
    // cmd is 0, led off
    // cmd is 1, led on
    // io is 0, close to beep   led
    // io is 1, close to button led
    int main(int argc, char *argv[])
    {
        int fd, led_num, led_c;
        char *leds = "/dev/leds";
    
        led_num = LED_NUM;
        led_c = LED_C;
        printf("argv1 is cmd; argv2 is io
    ");
    
        if(atoi(argv[1])>=led_c) {
            printf("argv[1] is 0 or 1
    ");
            exit(1);
        }
    
        if(atoi(argv[2])>=led_c) {
            printf("argv2 is 0 or 1
    ");
            exit(1);
        }
    
        fd = open(leds, O_RDWR|O_NOCTTY|O_NDELAY);
        if(fd < 0) {
            printf("open %s failed.
    , leds");
        } else {
            ioctl(fd, atoi(argv[1]), atoi(argv[2]));
            printf("io %s success
    ", leds);
        }
    
        close(fd);
        return 0;
    }
    无欲速,无见小利。欲速,则不达;见小利,则大事不成。
  • 相关阅读:
    多维数据查询OLAP及MDX语言笔记整理
    家庭记账本第三次开发
    家庭记账本第二次
    家庭记账本第一次
    使用Postman工具做接口测试(四)——参数化、执行用例与生成测试报告(完结篇)
    使用Postman工具做接口测试(三)——断言与参数提取
    使用Postman工具做基本测试(二)环境变量和请求参数格式
    使用Postman工具做接口测试(一)安装基本功能介绍和简单使用
    <unittest>
    $(document).on和$('#idname').on和$(function(){ })区别
  • 原文地址:https://www.cnblogs.com/ch122633/p/9275679.html
Copyright © 2011-2022 走看看