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

Overview

Demonstrates usage of the AXI GPIO driver (XGpio) and hardware device.

This file contains a design example using the AXI GPIO driver (XGpio) and hardware device. It only uses channel 1 of a GPIO device. It assumes that bit 0 of the GPIO is connected to the LED on the hardware board.

MODIFICATION HISTORY:
Ver   Who  Date     Changes


1.00a rmm 03/13/02 First release 1.00a rpm 08/04/03 Removed second example and invalid macro calls 2.00a jhl 12/15/03 Added support for dual channels 2.00a sv 04/20/05 Minor changes to comply to Doxygen and coding guidelines 3.00a ktn 11/20/09 Minor changes as per coding guidelines. 4.1 lks 11/18/15 Updated to use canonical xparameters and clean up of the comments and code for CR 900381 4.3 sk 09/29/16 Modified the example to make it work when LED_bits are configured as an output. CR# 958644 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.5 sne 06/12/19 Fixed IAR compiler warning. 4.10 gm 07/11/23 Added SDT support. 4.14 vn 09/10/26 Align Doxygen comments with AMD standards

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

Macros

#define LED   0x01
 Assumes bit 0 of GPIO is connected to an LED. More...
 
#define LED_DELAY   10000000
 LED visibility delay count. More...
 
#define LED_CHANNEL   1
 LED channel selection. 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_AXI_BASEADDRESS   XPAR_XGPIO_0_BASEADDR
 Base address. More...
 

Functions

int main (void)
 Demonstrates turning on and off an LED using the GPIO driver. More...
 

Variables

XGpio Gpio
 Holds the global GPIO driver instance. More...
 

Macro Definition Documentation

#define LED   0x01

Assumes bit 0 of GPIO is connected to an LED.

Referenced by main().

#define LED_CHANNEL   1

LED channel selection.

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

Referenced by main().

#define LED_DELAY   10000000

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 main().

#define XGPIO_AXI_BASEADDRESS   XPAR_XGPIO_0_BASEADDR

Base address.

Referenced by main().

Function Documentation

int main ( void  )

Demonstrates turning on and off an LED using the GPIO driver.

Returns
XST_FAILURE if GPIO initialization fails.
Note
This function does not return if the test is running.

References LED, LED_CHANNEL, LED_DELAY, XGPIO_AXI_BASEADDRESS, XGpio_DiscreteClear(), XGpio_DiscreteWrite(), XGpio_Initialize(), and XGpio_SetDataDirection().

Variable Documentation

XGpio Gpio

Holds the global GPIO driver instance.

The instance is declared globally so it is zeroed and easily accessible from a debugger.