
HAN Pilot Platform
Demonstration Manual
52
www.terasic.com
September 6, 2019
gpio port, the linux system will create attribute files of the gpio port in the location
“/sys/class/gpio/gpioN/” (N is the gpio port’ number). There are two attribute files we need to know:
value and direction. The value file is used to read and write value to the gpio port (the value can
only be “0” or “1”); the direction file is used to set the gpio port’s data direction.
Figure 3-14 Function block diagram of HPS GPIO Header demonstration
Function Implement
In the c code project, we need to implement five functions, described as following:
int gpio_export(unsigned int gpio);
The gpio_export function is used to export the gpio port with the specified port number as
parameter.
int gpio_unexport(unsigned int gpio);
The gpio_unexport function is used to disable the exported gpio port with the specified port number
as parameter.
int gpio_set_dir(unsigned int gpio, unsigned int out_flag);
The gpio_set_dir function is used to set the gpio port’s data direction, the parameter “gpio” is the
port number you want to configure and the parameter “out_flag” is value to set. Number “1” for
data out, and “0” for data in. when you use this api, it will wirte “in” or “out” to the gpio port’s
direction file. The default value of direction file is “in”.
int gpio_set_value(unsigned int gpio, unsigned int value);
The gpio_set_value function is used to write data to the gpio port. The parameter “gpio” is the port
number you want to configure and then parameter “value” is the data you want to write. The value
can only be “0” or “1”. When you use the api, it will write data to the gpio port’s value file.
int gpio_get_value(unsigned int gpio, unsigned int *value);
The gpio_get_value function is used to read the gpio port’s data, and the parameter “value” is used
to store the value that you read. The parameter “gpio” is the gpio port that you want to read.
All the functions are implemented in the c code file, you can get more details from the c code file.