4412应用编程

一、编写helloworld

#inlcude <stdio.h>
int main()
{
    printf("Hello World!\n");
    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\n");

    if(atoi(argv[1])>=led_c) {
        printf("argv[1] is 0 or 1\n");
        exit(1);
    }

    if(atoi(argv[2])>=led_c) {
        printf("argv2 is 0 or 1\n");
        exit(1);
    }

    fd = open(leds, O_RDWR|O_NOCTTY|O_NDELAY);
    if(fd < 0) {
        printf("open %s failed.\n, leds");
    } else {
        ioctl(fd, atoi(argv[1]), atoi(argv[2]));
        printf("io %s success\n", leds);
    }

    close(fd);
    return 0;
}

 

posted @ 2018-07-06 21:47  习惯就好233  阅读(221)  评论(0编辑  收藏  举报