[vc_row][vc_column width=”1/1″][vc_column_text]
This demo will show you how to blink the led via Liner Base Mezzanine Card.
[/vc_column_text][vc_tour][vc_tab title=”Hardware list” tab_id=”1450923953-1-58″][vc_column_text]
- 96board
- Liner Base Mezzanine Card
- LED module of Linker kit
- 4-pin cable
[/vc_column_text][/vc_tab][vc_tab title=”Steps” tab_id=”1450923953-2-91″][vc_column_text]There are 8 available ports on Linker Base Mezzanine Card including:
- 2 x ADC port
- 1 x UART port
- 1 x I2C port
- 4 x GPIO port
Choose D2 port and connect LED module through a 4-pin cable, as shown in the following picture.
[/vc_column_text][/vc_tab][vc_tab title=”Program” tab_id=”1450923974346-2-1″][vc_column_text]
#include <stdio.h> #include <stdlib.h> #include "libsoc_gpio.h" #include "libsoc_debug.h" #define GPIO_CS 13 int main() { gpio *gpio_cs; libsoc_set_debug(1); gpio_cs = libsoc_gpio_request(GPIO_CS,LS_SHARED); if(gpio_cs == NULL) { goto fail; } libsoc_gpio_set_direction(gpio_cs,OUTPUT); if(libsoc_gpio_get_direction(gpio_cs) != OUTPUT) { printf("Failed to set direction to OUTPUT\n"); goto fail; } while(1) { libsoc_gpio_set_level(gpio_cs,HIGH); usleep(1000000); libsoc_gpio_set_level(gpio_cs,LOW); usleep(1000000); } fail: if(gpio_cs) { libsoc_gpio_free(gpio_cs); } return EXIT_SUCCESS; }
Introduce functions in source code
libsoc_set_debug(int level)
Parameters :int lever ,lever 1 means printing GPIO information on terminal,0 means not printing.
Function:Print GPIO information
gpio *libsoc_gpio_request(unsigned int gpio_id, enum gpio_mode mode);
Parameters: unsigned int gpio_id GPIO ID number,
gpio_mode mode can be used to set GPIO mode
LS_SHARED —— if the gpio is already exported then it will not unexport
the GPIO on free. If it is not exported, then it will unexport on free.
LS_GREEDY —— will succeed if the GPIO is already exported, but will
always unexport the GPIO on free.
LS_WEAK —— will fail if GPIO is already exported, will always unexport on free.
int libsoc_gpio_set_direction(gpio * current_gpio, gpio_direction direction);
Parameters:gpio * current_gpio is the current GPIO
gpio_direction direction have 2 values which are INPUT and OUTPUT
function:set the current GPIO as input or output port.
gpio_direction libsoc_gpio_get_direction(gpio * current_gpio);
Parameters:gpio * current_gpio is the current GPIO
Function:read the statusof GPIO
Return: INPUT(0)、OUTPUT(1)
int libsoc_gpio_set_level(gpio * current_gpio, gpio_level level);
Paramters:gpio * current_gpio is the current GPIO
gpio_level level is used to set GPIO voltage level, HIGH or LOW.
Function:to set GPIO voltage level,
libsoc_gpio_free(gpio_cs);
function:release the GPIO resource.
[/vc_column_text][/vc_tab][vc_tab title=”Compile and run” tab_id=”1450923975454-3-0″][vc_column_text]Compile the source using the following command:
gcc gpio_test.c -o gpio_test -lsoc
It will generate a gpio_test executable file. Then run it to check the status of LED.
Sudo ./gpio_test
The information is printed on the terminal:
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.