From 9a293641b9abf9e4fca34f46a2de781f50847da9 Mon Sep 17 00:00:00 2001 From: "Westergreen, Dalon" Date: Wed, 29 Mar 2017 15:41:36 -0700 Subject: Initial commit of de10-nano recipes Please note that this is purely for development. Only superficial efforts have been made to resolve security concerns, and it should be noted that the board ships with an EMPTY ROOT PASSWORD and support for root login via ssh. This allows passwordless access to the board via ssh. recipes-bsp/u-boot: Contains the uboot 2017.03rc2 recipe and patches to support the de10-nano board recipes-connectivity/avahi: bbappend to remove unwanted packages recipes-connectivity/bluez: bbappend to add --compat to the bluetooth service to support legacy SDP APIs recipes-connectivity/openssh: bbappend to add a custom sshd_config recipes-core/base-files: bbappend to customize fstab and inputrc recipes-core/imagemagick: bbappend to change build configuration for the de10-nano board recipes-core/packagegroups: bbappend to remove an unwanted package recipes-core/webkit: bbappend to remove support for opengl recipes-demo: Various demo applications recipes-devtools: MRAA and UPM recipes recipes-images/angstrom/de10-nano-image.bb: DE10-Nano image definition recipes-kernel/de10-nano-linux-firmware: FPGA related firmware required for fpga configuration and devicetree overlay support recipes-kernel/linux: bbappend to customize configuration of linux kernel as well as patch in the de10-nano devicetree recipes-misc: various initialization and systemd scripts recipes-qt/qt5: bbappend to modify qt build options recipes-support/neon: bbappend to remove unwanted package recipes-support/upower: bbappend to remove unwanted package recipes-webserver: webserver configuration and webcontent for board hostedweb portal recipes-xfce/thunar-volman: bbappend to remove unwanted package recipes-xfce/xfce-pointers: add configuration so that xfce does not use the adxl input as a mouse recipes-xfce/xfce4-settings: bbappend to remove unwanted package Signed-off-by: Westergreen, Dalon --- .../de10-nano-gpio-apps/files/toggle_fpga_leds.c | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 recipes-demo/de10-nano-gpio-apps/files/toggle_fpga_leds.c (limited to 'recipes-demo/de10-nano-gpio-apps/files/toggle_fpga_leds.c') diff --git a/recipes-demo/de10-nano-gpio-apps/files/toggle_fpga_leds.c b/recipes-demo/de10-nano-gpio-apps/files/toggle_fpga_leds.c new file mode 100644 index 0000000..87493b7 --- /dev/null +++ b/recipes-demo/de10-nano-gpio-apps/files/toggle_fpga_leds.c @@ -0,0 +1,133 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main(void) { + + int i; + const char *leds_array[] = { + "fpga_led0", + "fpga_led1", + "fpga_led2", + "fpga_led3", + "fpga_led4", + "fpga_led5", + "fpga_led6", + "fpga_led7" + }; + int leds_array_count = (sizeof leds_array) / (sizeof *leds_array); + int led_fd; + char path[PATH_MAX]; + int path_length; + int result; + char brightness; + + // turn off all leds + for (i = 0 ; i < leds_array_count ; i++ ) { + // set trigger to none + path_length = snprintf(path, PATH_MAX, + "/sys/class/leds/%s/trigger", + leds_array[i]); + if(path_length < 0) + error(1, 0, "path output error"); + if(path_length >= PATH_MAX) + error(1, 0, "path length overflow"); + + led_fd = open(path, O_WRONLY | O_SYNC); + if(led_fd < 0) + error(1, errno, "could not open file '%s'", path); + + result = write(led_fd, "none", 4); + if(result < 0) + error(1, errno, "writing 'none' to '%s'", path); + if(result != 4) + error(1, 0, "did not write 4 bytes to '%s'", path); + + result = close(led_fd); + if(result < 0) + error(1, errno, "could not close file '%s'", path); + + // set brightness to 0 + path_length = snprintf(path, PATH_MAX, + "/sys/class/leds/%s/brightness", + leds_array[i]); + if(path_length < 0) + error(1, 0, "path output error"); + if(path_length >= PATH_MAX) + error(1, 0, "path length overflow"); + + led_fd = open(path, O_WRONLY | O_SYNC); + if(led_fd < 0) + error(1, errno, "could not open file '%s'", path); + + result = write(led_fd, "0", 1); + if(result < 0) + error(1, errno, "writing 'none' to '%s'", path); + if(result != 1) + + led_fd = open(path, O_WRONLY | O_SYNC); + if(led_fd < 0) + error(1, errno, "could not open file '%s'", path); + + result = write(led_fd, "0", 1); + if(result < 0) + error(1, errno, "writing '0' to '%s'", path); + if(result != 1) + error(1, 0, "did not write 1 byte to '%s'", path); + + result = close(led_fd); + if(result < 0) + error(1, errno, "could not close file '%s'", path); + } + + // toggle the leds individually + for (i = 0 ; i < (leds_array_count * 2) ; i++ ) { + // toggle the brightness + path_length = snprintf(path, PATH_MAX, + "/sys/class/leds/%s/brightness", + leds_array[i % leds_array_count]); + if(path_length < 0) + error(1, 0, "path output error"); + if(path_length >= PATH_MAX) + error(1, 0, "path length overflow"); + + led_fd = open(path, O_RDWR | O_SYNC); + if(led_fd < 0) + error(1, errno, "could not open file '%s'", path); + + result = read(led_fd, &brightness, 1); + if(result < 0) + error(1, errno, "reading 1 byte from '%s'", path); + if(result != 1) + error(1, 0, "did not read 1 byte from '%s'", path); + + if(brightness == '0') + brightness = '1'; + else if(brightness == '1') + brightness = '0'; + else + error(1, 0, "unexpected value for brightness"); + + result = write(led_fd, &brightness, 1); + if(result < 0) + error(1, errno, "writing brightness to '%s'", path); + if(result != 1) + error(1, 0, "did not write 1 byte to '%s'", path); + + result = close(led_fd); + if(result < 0) + error(1, errno, "could not close file '%s'", path); + + result = usleep(125000); + if(result < 0) + error(1, errno, "usleep error"); + } + + return 0; +} + -- cgit v1.1