1、尝试使用开发方式来进行流水灯的呈现,这次也要用到上次讲到的 通过 OpenSSH进行文件传输 方式
2、评估底板用户指示灯LED设备节点反复交替写入1、0数值,实现LED闪烁效果。LED点亮与熄灭时间均为0.5s。
在虚拟机的Ubuntut系统里,先建一个文件夹src,下面两个文件makefile和tl_led_flash.c
tl_led_flash.c脚本
- /* Copyright 2018 Tronlong Elec. Tech. Co. Ltd. All Rights Reserved. */
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- /* Get array size */
- #define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0])
- /* User-operable LEDs */
- static char *g_leds[] = {
- "/sys/class/leds/user-led0",
- "/sys/class/leds/user-led1",
- "/sys/class/leds/user-led2",
- "/sys/class/leds/user-led3"
- };
- /* Exit flag */
- volatile bool g_quit = false;
- /* Short option names */
- static const char g_shortopts [] = ":n:vh";
- /* Option names */
- static const struct option g_longopts [] = {
- { "number", required_argument, NULL, 'n' },
- { "version", no_argument, NULL, 'v' },
- { "help", no_argument, NULL, 'h' },
- { 0, 0, 0, 0 }
- };
- static void usage(FILE *fp, int argc, char **argv) {
- fprintf(fp,
- "Usage: %s [options]nn"
- "Options:n"
- " -n | --number Number of LEDs, range of 1 to 4 n"
- " -v | --version Display version informationn"
- " -h | --help Show help contentnn"
- "", basename(argv[0]));
- }
- static void opt_parsing_err_handle(int argc, char **argv, int flag) {
- /* Exit if no input parameters are entered */
- int state = 0;
- if (argc < 2) {
- printf("No input parameters are entered, please check the input.n");
- state = -1;
- } else {
- /* Feedback Error parameter information then exit */
- if (optind < argc || flag) {
- printf("Error: Parameter parsing failedn");
- if (flag)
- printf("tunrecognized option '%s'n", argv[optind-1]);
- while (optind < argc) {
- printf("tunrecognized option '%s'n", argv[optind++]);
- }
-
- state = -1;
- }
- }
- if (state == -1) {
- printf("Tips: '-h' or '--help' to get helpnn");
- exit(EXIT_FAILURE);
- }
- }
- void sig_handle(int arg) {
- g_quit = true;
- }
- int main(int argc, char **argv) {
- int i = 0;
- int c = 0;
- int num = 0;
- int flag = 0;
- char cmd[64] = {0};
- /* Parsing input parameters */
- while ((c = getopt_long(argc, argv, g_shortopts, g_longopts, NULL)) != -1) {
- switch (c) {
- case 'n':
- num = atoi(optarg);
- break;
- case 'v':
- /* Display the version */
- printf("version : 1.0n");
- exit(EXIT_SUCCESS);
- case 'h':
- usage(stdout, argc, argv);
- exit(EXIT_SUCCESS);
-
- default :
- flag = 1;
- break;
- }
- }
- opt_parsing_err_handle(argc, argv, flag);
- /* Check if the number of LEDs is out of preset range */
- if ((num > ARRAY_SIZE(g_leds)) || (num < 1)) {
- printf("Error: The number of LEDs entered exceeds the preset range(1-4)n");
- exit(EXIT_FAILURE);
- }
- /* Ctrl+c handler */
- signal(SIGINT, sig_handle);
- /* Print LEDs */
- printf("nSystem leds :n");
- system("find /sys/class/leds/*");
- printf("nFlashing leds :n");
- for (i = 0; i < num; i++)
- printf("%sn",g_leds[i]);
- while (!g_quit) {
- /* Turn on LEDs */
- for (i = 0; i < num; i++) {
- /* Set the LED brightness value to 1 to turn on the led */
- snprintf(cmd, 64, "echo 1 > %s/brightness", g_leds[i]);
- if (system(cmd) != 0) {
- fprintf(stderr, "Error: Failed to turn on %sn", g_leds[i]);
- exit(EXIT_FAILURE);
- }
- }
- /* Keep the LEDs on for 500 ms */
- usleep(500 * 1000);
- /* Turn off LEDs */
- for (i = 0; i < num; i++) {
- /* Set the LED brightness value to 0 to turn off the LED */
- snprintf(cmd, 64, "echo 0 > %s/brightness", g_leds[i]);
- if (system(cmd) != 0) {
- fprintf(stderr, "Error: Failed to turn off %sn", g_leds[i]);
- exit(EXIT_FAILURE);
- }
- }
- /* Keep the LEDs off for 500 ms */
- usleep(500 * 1000);
- }
- printf("Exitn");
- return 0;
- }
复制代码
makefile脚本
- tl_led_flash:tl_led_flash.c
- $(CC) -Wall [ DISCUZ_CODE_3003 ]lt; -o $@
- clean:
- rm -f tl_led_flash *.o *~
- install:
- cp tl_led_flash $(PREFIX)
复制代码
3、命令行下执行两条命令
- source /home/tronlong/ti-processor-sdk-linux-rt-am335x-evm-04.03.00.05/linux-devkit/environment-setup
复制代码
就会生成一个文件 tl_led_flash
4、 开发板eth0接好网线,获得的IP是 192.168.31.40 通过OpenSSH进行文件传输 命令行命令
- scp tl_led_flash root@192.168.31.40:/
复制代码
5、这个时间,通过开发板串口进入开发板的命行,可以看见传递过来的文件,并能执行,让LED开始流水了
|
|
|
|