• 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;
    }
    无欲速,无见小利。欲速,则不达;见小利,则大事不成。
  • 相关阅读:
    andrew ng 学习
    360一些笔试题
    安装visual studio2010提示“Windows Installer 服务不可用”的解决办法
    算法学习从赌钱游戏看PageRank算法
    jQuery Masonry 一个 jQuery动态网格布局的插件
    国内HTML5前端开发框架汇总
    Windows Performance Monitor 学习笔记
    ThinkPad预装win8系统机型安装win7系统的操作指导
    jQuery的Ajax的自动完成功能控件
    JavaScript的Forms验证Parsley.js
  • 原文地址:https://www.cnblogs.com/ch122633/p/9275679.html
Copyright © 2020-2023  润新知