gpio
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Macros Groups Pages
xgpio_tapp_example.c File Reference

Overview

Demonstrates usage of AXI GPIO hardware and driver.

This file contains an example for using AXI GPIO hardware and driver. This example assumes that there is a UART Device or STDIO Device in the hardware system.

MODIFICATION HISTORY:
Ver     Who  Date         Changes


1.00a sv 04/15/05 Initial release for TestApp integration. 3.00a sv 11/21/09 Updated to use HAL Processor APIs. 3.01a bss 04/18/13 Removed incorrect Documentation lines.(CR #701641) 4.1 lks 11/18/15 Updated to use canonical xparameters and clean up of the comments and code for CR 900381 4.3 ms 01/23/17 Added xil_printf statement in main function to ensure that "Successfully ran" and "Failed" strings are available in all examples. This is a fix for CR-965028. 4.10 gm 07/11/23 Added SDT support. 4.10 gm 08/28/23 Update example to support peripheral tests. 4.13 vlt 12/17/25 Update Doxygen comments to include SDT flow details. 4.14 vn 09/10/26 Align Doxygen comments with AMD standards

#include "xparameters.h"
#include "xgpio.h"
#include "stdio.h"
#include "xstatus.h"
#include "xil_printf.h"

Macros

#define LED_DELAY   1000000
 LED visibility delay count. More...
 
#define LED_CHANNEL   1
 LED channel selection. More...
 
#define LED_MAX_BLINK   0x1
 Number of times the LED blinks. More...
 
#define GPIO_BITWIDTH   16
 Width of the GPIO. More...
 
#define printf   xil_printf
 Smaller footprint printf. More...
 
Device parameters

The following constants map to the XPAR parameters created in the xparameters.h file.

They are defined here so that all the needed parameters can be easily changed in one place.

#define XGPIO_BASEADDRESS   XPAR_XGPIO_0_BASEADDR
 Base address. More...
 

Functions

int GpioOutputExample (XGpio *GpioOutputPtr, UINTPTR BaseAddress)
 Runs a minimal test on the GPIO device configured as output. More...
 
int GpioInputExample (UINTPTR BaseAddress, u32 *DataRead)
 Tests the GPIO device configured as input. More...
 
int main (void)
 Runs the GPIO output and input examples. More...
 

Variables

Global GPIO driver instances

The following are declared globally so they are zeroed and so they are easily accessible from a debugger.

XGpio GpioOutput
 Driver instance for the GPIO device used as output. More...
 
XGpio GpioInput
 Driver instance for the GPIO device used as input. More...
 

Macro Definition Documentation

#define GPIO_BITWIDTH   16

Width of the GPIO.

Referenced by main().

#define LED_CHANNEL   1

LED channel selection.

The following constant is used to determine which channel of the GPIO is used if there are two channels supported in the GPIO.

Referenced by GpioInputExample(), and GpioOutputExample().

#define LED_DELAY   1000000

LED visibility delay count.

The following constant is used to wait after an LED is turned on to make sure that it is visible to the human eye. This constant might need to be tuned for faster or slower processor speeds.

Referenced by GpioOutputExample().

#define LED_MAX_BLINK   0x1

Number of times the LED blinks.

Referenced by GpioOutputExample().

#define printf   xil_printf

Smaller footprint printf.

Referenced by main().

#define XGPIO_BASEADDRESS   XPAR_XGPIO_0_BASEADDR

Base address.

Referenced by main().

Function Documentation

int GpioInputExample ( UINTPTR  BaseAddress,
u32 *  DataRead 
)

Tests the GPIO device configured as input.

Parameters
[in]BaseAddressBase address of the device.
[out]DataReadPointer where the data read from the GPIO input is returned.
Returns
  • XST_SUCCESS if the test is successful.
  • XST_FAILURE if the test is not successful.
Note
In XSCT/classic flow, DeviceId is used to look up the device configuration.

References LED_CHANNEL, XGpio_DiscreteRead(), XGpio_Initialize(), and XGpio_SetDataDirection().

Referenced by main().

int GpioOutputExample ( XGpio *  GpioOutputPtr,
UINTPTR  BaseAddress 
)

Runs a minimal test on the GPIO device configured as output.

Parameters
[in]GpioOutputPtrPointer to the GPIO driver instance.
[in]BaseAddressBase address of the device.
Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE if unsuccessful.
Note
In XSCT/classic flow, DeviceId is used to look up the device configuration.

References LED_CHANNEL, LED_DELAY, LED_MAX_BLINK, XGpio_Config::Width, XGpio_DiscreteClear(), XGpio_DiscreteWrite(), XGpio_Initialize(), XGpio_LookupConfig(), and XGpio_SetDataDirection().

Referenced by main().

int main ( void  )

Runs the GPIO output and input examples.

This function is not included if the example is generated from the Peripheral Tests in SDK.

Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE if unsuccessful.

References GPIO_BITWIDTH, GpioInputExample(), GpioOutputExample(), printf, and XGPIO_BASEADDRESS.

Variable Documentation

XGpio GpioInput

Driver instance for the GPIO device used as input.

XGpio GpioOutput

Driver instance for the GPIO device used as output.