![]() |
gpio
Vitis Drivers API Documentation
|
Demonstrates usage of the GPIO driver (XGpio) in interrupt-driven mode.
This file contains a design example using the GPIO driver (XGpio) in an interrupt-driven mode of operation. This example assumes that there is an interrupt controller in the hardware system and the GPIO device is connected to the interrupt controller.
This file is used in the Peripheral Tests Application in SDK to include a simplified test for GPIO interrupts.
The buttons and LEDs are on two separate channels of the GPIO. This separation prevents interrupts when the LEDs turn on and off.
MODIFICATION HISTORY:
Ver Who Date Changes
2.01a sn 05/09/06 Modified to be used by TestAppGen to include test for interrupts. 3.00a ktn 11/21/09 Updated to use HAL Processor APIs and minor changes as per coding guidelines. 3.00a sdm 02/16/11 Updated to support ARM Generic Interrupt Controller 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 Modified 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.11 gm 12/06/23 Added IER and GIER calls in SDT flow. 4.13 vlt 12/02/25 Added GlobalIntrMask initialization for SDT flow. 4.13 vlt 12/12/25 Update Doxygen comments to include SDT flow details. 4.14 vn 07/30/26 Fix Doxygen warnings 4.14 vn 09/10/26 Align Doxygen comments with AMD standards
Macros | |
| #define | INTERRUPT_CONTROL_VALUE 0x7 |
| Interrupt control value. More... | |
| #define | LED_DELAY 1000000 |
| LED visibility delay count. More... | |
| #define | INTR_DELAY 0x00FFFFFF |
| Interrupt delay count. 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... | |
| #define | GPIO_CHANNEL1 1 |
| GPIO channel 1. More... | |
Button and LED masks | |
The following constants define the positions of the buttons and LEDs in each channel of the GPIO. | |
| #define | GPIO_ALL_LEDS 0xFFFF |
| All LED bits mask. More... | |
| #define | GPIO_ALL_BUTTONS 0xFFFF |
| All button bits mask. More... | |
Channel definitions | |
The following constants define the GPIO channel that is used for the buttons and the LEDs. They allow the channels to be reversed easily. | |
| #define | BUTTON_CHANNEL 1 |
| Channel 1 of the GPIO device. More... | |
| #define | LED_CHANNEL 2 |
| Channel 2 of the GPIO device. More... | |
| #define | BUTTON_INTERRUPT XGPIO_IR_CH1_MASK |
| Channel 1 interrupt mask. More... | |
Functions | |
| void | GpioHandler (void *CallbackRef) |
| Handles GPIO interrupts. More... | |
| int | GpioIntrExample (XGpio *InstancePtr, UINTPTR BaseAddress, u16 IntrMask, u32 *DataRead) |
| Tests GPIO interrupts when enabled. More... | |
| int | main (void) |
| Runs the GPIO interrupt example. More... | |
Variables | |
| XGpio | Gpio |
| Holds the global GPIO driver instance. More... | |
| #define BUTTON_CHANNEL 1 |
Channel 1 of the GPIO device.
| #define BUTTON_INTERRUPT XGPIO_IR_CH1_MASK |
Channel 1 interrupt mask.
| #define GPIO_ALL_BUTTONS 0xFFFF |
All button bits mask.
| #define GPIO_ALL_LEDS 0xFFFF |
All LED bits mask.
| #define GPIO_CHANNEL1 1 |
GPIO channel 1.
Referenced by main().
| #define INTERRUPT_CONTROL_VALUE 0x7 |
Interrupt control value.
The following constant determines which buttons must be pressed at the same time to cause interrupt processing to stop and start.
| #define INTR_DELAY 0x00FFFFFF |
Interrupt delay count.
Referenced by GpioIntrExample().
| #define LED_CHANNEL 2 |
Channel 2 of the GPIO device.
| #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.
| #define XGPIO_AXI_BASEADDRESS XPAR_XGPIO_0_BASEADDR |
Base address.
Referenced by main().
| void GpioHandler | ( | void * | CallbackRef | ) |
Handles GPIO interrupts.
| [in] | CallbackRef | Callback reference for the handler. |
References XGpio_InterruptClear().
Referenced by GpioIntrExample().
| int GpioIntrExample | ( | XGpio * | InstancePtr, |
| UINTPTR | BaseAddress, | ||
| u16 | IntrMask, | ||
| u32 * | DataRead | ||
| ) |
Tests GPIO interrupts when enabled.
This is the entry function from the TestAppGen tool generated application, which tests the interrupts when enabled in the GPIO.
| [out] | InstancePtr | Pointer to the GPIO driver instance. |
| [in] | BaseAddress | Base address of the device. |
| [in] | IntrMask | GPIO channel mask. |
| [out] | DataRead | Pointer where the data read from the GPIO input is returned. |
References GpioHandler(), INTR_DELAY, XGpio_Config::IntrId, XGpio_Config::IntrParent, XGpio_Initialize(), XGpio_InterruptEnable(), XGpio_InterruptGlobalEnable(), and XGpio_LookupConfig().
Referenced by main().
| int main | ( | void | ) |
Runs the GPIO interrupt example.
This is the main function of the GPIO example. It is responsible for initializing the GPIO device, setting up interrupts, and providing a foreground loop so that interrupts can occur in the background.
References GPIO_CHANNEL1, GpioIntrExample(), and XGPIO_AXI_BASEADDRESS.
| XGpio Gpio |
Holds the global GPIO driver instance.
The instance is declared globally so it is zeroed and easily accessible from a debugger.