【试用报告】创龙科技 TL335x-EVM-S评估板之LED流水 - AM335x - 嵌入式开发者社区 - 51ele.net
设为首页收藏本站

嵌入式开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2254|回复: 0

[已解决] 【试用报告】创龙科技 TL335x-EVM-S评估板之LED流水

[复制链接]

10

主题

10

帖子

111

积分

注册会员

Rank: 2

积分
111
发表于 2022-1-12 10:39:00 | 显示全部楼层 |阅读模式
本次继续测试创龙科技的TL335x-EVM-S评估板。


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 <stdio.h>
  • #include <stdlib.h>
  • #include <stdint.h>
  • #include <stdbool.h>
  • #include <string.h>
  • #include <getopt.h>
  • #include <signal.h>
  • #include <unistd.h>
  • #include <errno.h>
  • #include <libgen.h>
  • /* 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]\n\n"
  •             "Options:\n"
  •             " -n | --number        Number of LEDs, range of 1 to 4 \n"
  •             " -v | --version       display version information\n"
  •             " -h | --help          Show help content\n\n"
  •             "", 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 failed\n");
  •             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 help\n\n");
  •         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.0\n");
  •             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("%s\n",g_leds);
  •     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);
  •             if (system(cmd) != 0) {
  •                 fprintf(stderr, "Error: Failed to turn on %s\n", g_leds);
  •                 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);
  •             if (system(cmd) != 0) {
  •                 fprintf(stderr, "Error: Failed to turn off %s\n", g_leds);
  •                 exit(EXIT_FAILURE);
  •             }
  •         }
  •         /* Keep the LEDs off for 500 ms */
  •         usleep(500 * 1000);
  •     }
  •     printf("Exit\n");
  •     return 0;
  • }


[color=rgb(51, 102, 153) !important]复制代码


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)


[color=rgb(51, 102, 153) !important]复制代码


3、命令行下执行两条命令

  • source /home/tronlong/ti-processor-sdk-linux-rt-am335x-evm-04.03.00.05/linux-devkit/environment-setup

[color=rgb(51, 102, 153) !important]复制代码


  • make

[color=rgb(51, 102, 153) !important]复制代码


就会生成一个文件 tl_led_flash
4、开发板eth0接好网线,获得的IP是 192.168.31.40 通过OpenSSH进行文件传输 命令行命令



[color=rgb(51, 102, 153) !important]复制代码


5、这个时间,通过开发板串口进入开发板的命行,可以看见传递过来的文件,并能执行,让LED开始流水了



演示视频链接:https://www.bilibili.com/video/BV1ZY411x7rn/







回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|嵌入式开发者社区 ( 粤ICP备15055271号

GMT+8, 2024-3-29 20:56 , Processed in 0.046228 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2015 Comsenz Inc.

快速回复 返回顶部 返回列表