s5pv210开发板 sin210 linux 例程 LED 应用程序

来源:互联网 发布:知乎护肤品各经典产品 编辑:程序博客网 时间:2024/06/04 18:03

#include <stdio.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <linux/input.h>#define IOCTL_LED_ON    0#define IOCTL_LED_OFF   1void usage(char *exename){    printf("Usage:\n");    printf("    %s <led_no> <on/off>\n", exename);    printf("    led_no = 1, 2, 3, 4\n");}int main(int argc, char **argv){    unsigned int led_no;    int fd = -1;        if (argc != 3)        goto err;            fd = open("/dev/led", O_RDWR);    if (fd < 0) {        printf("Can't open /dev/leds\n");        return -1;    }        led_no = strtoul(argv[1], 0, 0) - 1;    if (led_no > 5)        goto err;        if (!strcmp(argv[2], "on")) {        ioctl(fd, IOCTL_LED_ON, led_no);    } else if (!strcmp(argv[2], "off")) {        ioctl(fd, IOCTL_LED_OFF, led_no);    } else {        goto err;    }printf("IOCTL no = [%d],[%s]\r\n", led_no,argv[2]);        close(fd);    return 0;    err:    if (fd > 0)         close(fd);    usage(argv[0]);    return -1;}


Makefile的代码

##  General MakefileExec := led_testObj := led_test.cCC := arm-linux-gcc$(Exec) : $(Obj)$(CC) -o $@ $(Obj) $(LDLIBS$(LDLIBS-$(@)))clean:rm -vf $(Exec) *.elf *.o


 

原创粉丝点击