Intel Embedded System Design Contest Technical Notes FPGA Peripheral Linux Driver Usage Notes Rev 0.00 Date: 2012/03/13 Technical Notes Document Information TYPE Key words Abstract FPGA, Peripherals, driver CONTENT This document describes how to use FPGA peripheral drivers www.zlg.cn Guangzhou ZHIYUAN Electronics Stock Co., Ltd.
Revision History Version Rev. Date Modifications 1.00 2012-3-13 Original version. i Revision History
Content Chapter 1: LED Driver... 1 1.1 Function... 1 1.2 How to use... 1 Chapter 2: Toggle Switch... 2 2.1 Function... 2 2.2 How to use... 2 Charter 3: 12-bit ADC... 3 3.1 Function... 3 3.2 How to use... 3 Charter 4: 8-bit ADC... 4 4.1 Function... 4 4.2 How to use... 4 Charter 5: 10-bit DAC... 5 5.1 Function... 5 5.2 How to use... 5 Charter 6: Buttons... 6 6.1 Function... 6 6.2 How to use... 6 ii Content
Chapter 1: LED Driver 1.1 Function The LED driver controls the states of 8 LEDs. 1.2 How to use The LED driver provides the operation interfaces to LEDs for user application; these interfaces are saved as files in the following directories: /sys/class/leds/zlge6x5c:red:0/ /sys/class/leds/zlge6x5c:red:1/ /sys/class/leds/zlge6x5c:red:2/ /sys/class/leds/zlge6x5c:red:3/ /sys/class/leds/zlge6x5c:red:4/ /sys/class/leds/zlge6x5c:red:5/ /sys/class/leds/zlge6x5c:red:6/ /sys/class/leds/zlge6x5c:red:7/ Each of these directories is corresponding to one LED, and each directory contains one file named brightness, writing a 0 to this file means to turn off the LED, writing a numerical string that more than 0 means to turn on the LED. For example: Turn off LED0: # echo 0 > /sys/class/leds/zlge6x5c:red:0/brightness Turn on LED0 # echo 1 > /sys/class/leds/zlge6x5c:red:0/brightness Notes: User should determine the actual state of the LED based on the test results; FPGA firmware does not provide a default state for each LED. 1 Chapter 1: LED Driver
Chapter 2: Toggle Switch 2.1 Function The Toggle Switch driver can indicate the status of the toggle switches. 2.2 How to use The Toggle Switch driver provides the operation interface to toggle switch for user application; this interface is saved as a file in the following directory: /sys/bus/pci/devices/0000:01:00.0/zlge6x5c-switch/ User can get the current status of the switch by reading the switch file. For the lowest four bits, each bit represents a status of a switch. For example: cat /sys/bus/pci/devices/0000:01:00.0/zlge6x5c-switch/switch 2 Chapter 2: Toggle switch
Charter 3: 12-bit ADC 3.1 Function The ADC can convert the analogue signal to digital signal, if a voltage is inputted to the related pin, the corresponding voltage value would read out by the device, the range of voltage is 0~3.3 V. 3.2 How to use User can get the A/D conversion value by reading the following file: /sys/bus/pci/devices/0000:01:00.0/zlge6x5c-adc12bit/value This value is not the voltage value. In order to get the actual voltage value, user should use the following equation: volt = value * 3.3 / 4095 With in the equation, the value is the AD conversion value obtained from the file. Notes: The accuracy of the data depends on the hardware specification. 3 Chapter 3: 12-bit ADC
Charter 4: 8-bit ADC 4.1 Function The ADC can convert the analogue signal to digital signal, if a voltage is inputted to the related pin, the corresponding voltage value would read out by the device, the range of voltage is 0~3.3 V. 4.2 How to use User can get the A/D conversion value by reading the following file: /sys/bus/pci/devices/0000:01:00.0/zlge6x5c-adc8bit/value This value is not the voltage value. In order to get the actual voltage value, user should use the following equation: volt = value * 3.3 / 255 With in the equation, the value is the AD conversion value obtained from the file. Notes: The accuracy of the data depends on the hardware specification. 4 Chapter 4: 8-bit ADC
Charter 5: 10-bit DAC 5.1 Function The DAC can convert the digital signal into analog signal. After calculation using a conversion equation, user can write the result value to the register of the DAC to let it output a required voltage. But the range of this voltage must be [-1, +1]V. 5.2 How to use User can write value to the following file to access the register: /sys/bus/pci/devices/0000:01:00.0/zlge6x5c-dac10bit/value The equation for voltage value conversion: value = ((volt * 1024) + 1023 ) / 2 after calculation, user should round in the result to get an integer value. The volt within the equation is the required output voltage, and its range should be between -1V and 1 V. Notes: The accuracy of the data depends on the hardware specification. 5 Chapter 5: 10-bit DAC
Charter 6: Buttons 6.1 Function The key value corresponding to each button is listed below: SW4 KEY_LEFT SW6 KEY_UP SW3 KEY_DOWN SW5 KEY_RIGHT Long press is supported. 6.2 How to use Since the return values of the buttons are configured to be the same with the arrow keys on a common computer keyboard, so if user presses a button, the same response to a corresponding arrow key would appear on the graphical user interface. User application can also get this key value by reading event device node. The name of event device node is generated dynamically. Following is the source codes for basic button operations. #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <linux/input.h> int main(int argc, char *argv[]) { char *dev; int fd, ret; struct input_event event; if (argc > 1) dev = argv[1]; else dev = "/dev/input/by-path/pci-0000:01:00.0-platform-zlge6x5c-button-event"; fd = open(dev, O_RDWR); if (fd < 0) { perror("open failed"); return -1; /* open the device node*/ 6 Chapter 6: Buttons
} } while (1) { ret = read(fd, &event, sizeof(event)); if (ret < 0) { perror("read failed"); close(fd); return -1; } switch (event.type) { case EV_SYN: printf("[%d.%d] ------------ Report Sync ------------\n", event.time.tv_sec, event.time.tv_usec); break; case EV_MSC: printf("[%d.%d] type %d (Misc), code %d (ScanCode), value %d\n", event.time.tv_sec, event.time.tv_usec, event.type, event.code, event.value); case EV_KEY: printf("[%d.%d] type = %d, code = %d, value = %d\n", event.time.tv_sec, event.time.tv_usec, event.type, event.code, event.value); } } return 0; To check the name of a device node: $ cd /dev/input/by-path $ ls l pci-0000:01:00.0-platform-zlge6x5c-button-event Then the name of device node for buttons will be listed out. 7 Chapter 6: Buttons