gpio
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Macros Groups Pages
GPIO APIs

Data Structures

struct  XGpio_Config
 Holds configuration information for the device. More...
 
struct  XGpio
 Holds the XGpio driver instance data. More...
 

Macros

#define XGPIO_CHAN_OFFSET   8
 Channel offset. More...
 
#define XGpio_In32   Xil_In32
 Input operations. More...
 
#define XGpio_Out32   Xil_Out32
 Output operations. More...
 
#define XGpio_WriteReg(BaseAddress, RegOffset, Data)   XGpio_Out32((BaseAddress) + (RegOffset), (u32)(Data))
 Writes a 32-bit value to a GPIO register. More...
 
#define XGpio_ReadReg(BaseAddress, RegOffset)   XGpio_In32((BaseAddress) + (RegOffset))
 Reads a value from a GPIO register. More...
 
#define XPAR_XGPIO_NUM_INSTANCES   0
 GPIO instances. More...
 

Functions

int XGpio_CfgInitialize (XGpio *InstancePtr, XGpio_Config *Config, UINTPTR EffectiveAddr)
 Initializes the XGpio instance based on the given configuration data. More...
 
void XGpio_SetDataDirection (XGpio *InstancePtr, unsigned Channel, u32 DirectionMask)
 Sets the I/O direction of all discrete signals for a GPIO channel. More...
 
u32 XGpio_GetDataDirection (XGpio *InstancePtr, unsigned Channel)
 Gets the I/O direction of all discrete signals for a GPIO channel. More...
 
u32 XGpio_DiscreteRead (XGpio *InstancePtr, unsigned Channel)
 Reads the state of the discretes for the specified GPIO channel. More...
 
void XGpio_DiscreteWrite (XGpio *InstancePtr, unsigned Channel, u32 Mask)
 Writes to the discretes register for the specified GPIO channel. More...
 
int XGpio_Initialize (XGpio *InstancePtr, UINTPTR BaseAddress)
 Initializes the XGpio instance by device ID or base address. More...
 
XGpio_Config * XGpio_LookupConfig (UINTPTR BaseAddress)
 Looks up the device configuration by device ID or base address. More...
 
void XGpio_DiscreteSet (XGpio *InstancePtr, unsigned Channel, u32 Mask)
 Sets output discretes to logic 1 for the specified GPIO channel. More...
 
void XGpio_DiscreteClear (XGpio *InstancePtr, unsigned Channel, u32 Mask)
 Sets output discretes to logic 0 for the specified GPIO channel. More...
 
int XGpio_SelfTest (XGpio *InstancePtr)
 Runs a self-test on the driver and device. More...
 
void XGpio_InterruptGlobalEnable (XGpio *InstancePtr)
 Enables the interrupt output signal. More...
 
void XGpio_InterruptGlobalDisable (XGpio *InstancePtr)
 Disables the interrupt output signal. More...
 
void XGpio_InterruptEnable (XGpio *InstancePtr, u32 Mask)
 Enables interrupts for the specified channels. More...
 
void XGpio_InterruptDisable (XGpio *InstancePtr, u32 Mask)
 Disables interrupts for the specified channels. More...
 
void XGpio_InterruptClear (XGpio *InstancePtr, u32 Mask)
 Clears pending interrupts with the provided mask. More...
 
u32 XGpio_InterruptGetEnabled (XGpio *InstancePtr)
 Returns the interrupt enable mask. More...
 
u32 XGpio_InterruptGetStatus (XGpio *InstancePtr)
 Returns the status of interrupt signals. More...
 

Variables

XGpio_Config XGpio_ConfigTable []
 Configuration table for GPIO devices in the system. More...
 
XGpio_Config XGpio_ConfigTable []
 Holds the configuration entry for each GPIO instance. More...
 

Registers

Register offsets for this device.

#define XGPIO_DATA_OFFSET   0x0
 Data register for first channel. More...
 
#define XGPIO_TRI_OFFSET   0x4
 I/O direction register for first channel. More...
 
#define XGPIO_DATA2_OFFSET   0x8
 Data register for second channel. More...
 
#define XGPIO_TRI2_OFFSET   0xC
 I/O direction register for second channel. More...
 
#define XGPIO_GIE_OFFSET   0x11C
 Global interrupt enable register. More...
 
#define XGPIO_ISR_OFFSET   0x120
 Interrupt status register. More...
 
#define XGPIO_IER_OFFSET   0x128
 Interrupt enable register. More...
 

Interrupt Status and Enable Register bitmaps and masks

Bit definitions for the interrupt status register and interrupt enable registers.

#define XGPIO_IR_MASK   0x3
 Mask of all bits. More...
 
#define XGPIO_IR_CH1_MASK   0x1
 Mask for the first channel. More...
 
#define XGPIO_IR_CH2_MASK   0x2
 Mask for the second channel. More...
 

Global Interrupt Enable Register bitmaps and masks

Bit definitions for the Global Interrupt Enable register.

#define XGPIO_GIE_GINTR_ENABLE_MASK   0x80000000
 Mask for Global Interrupt. More...
 

Macro Definition Documentation

#define XGPIO_CHAN_OFFSET   8

Channel offset.

The following constant describes the offset of each channel's data and tristate register from the base address.

Referenced by main(), XGpio_DiscreteClear(), XGpio_DiscreteRead(), XGpio_DiscreteSet(), XGpio_DiscreteWrite(), XGpio_GetDataDirection(), and XGpio_SetDataDirection().

#define XGPIO_DATA2_OFFSET   0x8

Data register for second channel.

#define XGPIO_DATA_OFFSET   0x0

Data register for first channel.

Referenced by main(), XGpio_DiscreteClear(), XGpio_DiscreteRead(), XGpio_DiscreteSet(), and XGpio_DiscreteWrite().

#define XGPIO_GIE_GINTR_ENABLE_MASK   0x80000000

Mask for Global Interrupt.

Referenced by XGpio_InterruptGlobalEnable().

#define XGPIO_GIE_OFFSET   0x11C

Global interrupt enable register.

Referenced by XGpio_InterruptGlobalDisable(), and XGpio_InterruptGlobalEnable().

#define XGPIO_IER_OFFSET   0x128

Interrupt enable register.

Referenced by XGpio_InterruptDisable(), XGpio_InterruptEnable(), and XGpio_InterruptGetEnabled().

#define XGpio_In32   Xil_In32

Input operations.

#define XGPIO_IR_CH1_MASK   0x1

Mask for the first channel.

#define XGPIO_IR_CH2_MASK   0x2

Mask for the second channel.

#define XGPIO_IR_MASK   0x3

Mask of all bits.

#define XGPIO_ISR_OFFSET   0x120

Interrupt status register.

Referenced by XGpio_InterruptClear(), and XGpio_InterruptGetStatus().

#define XGpio_Out32   Xil_Out32

Output operations.

#define XGpio_ReadReg (   BaseAddress,
  RegOffset 
)    XGpio_In32((BaseAddress) + (RegOffset))

Reads a value from a GPIO register.

A 32-bit read is performed. If the GPIO core is implemented in a smaller width, only the least significant data is read from the register. The most significant data reads as 0.

Parameters
[in]BaseAddressBase address of the GPIO device.
[in]RegOffsetRegister offset from the base to read from.
Returns
Data read from the register.
Note
C-style signature: u32 XGpio_ReadReg(u32 BaseAddress, u32 RegOffset)

Referenced by main(), XGpio_DiscreteClear(), XGpio_DiscreteRead(), XGpio_DiscreteSet(), XGpio_GetDataDirection(), XGpio_InterruptClear(), XGpio_InterruptDisable(), XGpio_InterruptEnable(), XGpio_InterruptGetEnabled(), and XGpio_InterruptGetStatus().

#define XGPIO_TRI2_OFFSET   0xC

I/O direction register for second channel.

#define XGPIO_TRI_OFFSET   0x4

I/O direction register for first channel.

Referenced by main(), XGpio_GetDataDirection(), and XGpio_SetDataDirection().

#define XGpio_WriteReg (   BaseAddress,
  RegOffset,
  Data 
)    XGpio_Out32((BaseAddress) + (RegOffset), (u32)(Data))

Writes a 32-bit value to a GPIO register.

If the GPIO core is implemented in a smaller width, only the least significant data is written.

Parameters
[in]BaseAddressBase address of the GPIO device.
[in]RegOffsetRegister offset from the base to write to.
[in]DataData written to the register.
Note
C-style signature: void XGpio_WriteReg(u32 BaseAddress, u32 RegOffset, u32 Data)

Referenced by main(), XGpio_DiscreteClear(), XGpio_DiscreteSet(), XGpio_DiscreteWrite(), XGpio_InterruptClear(), XGpio_InterruptDisable(), XGpio_InterruptEnable(), XGpio_InterruptGlobalDisable(), XGpio_InterruptGlobalEnable(), and XGpio_SetDataDirection().

#define XPAR_XGPIO_NUM_INSTANCES   0

GPIO instances.

Function Documentation

int XGpio_CfgInitialize ( XGpio *  InstancePtr,
XGpio_Config *  Config,
UINTPTR  EffectiveAddr 
)

Initializes the XGpio instance based on the given configuration data.

This function initializes only InstancePtr.

Parameters
[out]InstancePtrPointer to an XGpio instance. The memory the pointer references must be pre-allocated by the caller. Further calls to manipulate the driver through the XGpio API must be made with this pointer.
[in]ConfigPointer to a structure containing information about a specific GPIO device. This function initializes an InstancePtr object for a specific device specified by the contents of Config. This function can initialize multiple instance objects with the use of multiple calls giving different Config information on each call.
[in]EffectiveAddrDevice base address in the virtual memory address space. The caller is responsible for keeping the address mapping from EffectiveAddr to the device physical base address unchanged once this function is invoked. Unexpected errors may occur if the address mapping changes after this function is called. If address translation is not used, use Config->BaseAddress for this parameter, passing the physical address instead.
Returns
XST_SUCCESS if the initialization is successful.

References XGpio::BaseAddress, XGpio_Config::InterruptPresent, XGpio::InterruptPresent, XGpio_Config::IsDual, XGpio::IsDual, and XGpio::IsReady.

Referenced by XGpio_Initialize().

void XGpio_DiscreteClear ( XGpio *  InstancePtr,
unsigned  Channel,
u32  Mask 
)

Sets output discretes to logic 0 for the specified GPIO channel.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
[in]ChannelGPIO channel (1 or 2) to operate on.
[in]MaskSet of bits that are set to 0 in the discrete data register. All other bits in the data register are unaffected.
Note
The hardware must be built for dual channels if this function is used with any channel other than 1. If it is not, this function asserts.

This API can only be used if the GPIO_IO ports in the IP are used for connecting to the external output ports.

References XGpio::BaseAddress, XGpio::IsDual, XGpio::IsReady, XGPIO_CHAN_OFFSET, XGPIO_DATA_OFFSET, XGpio_ReadReg, and XGpio_WriteReg.

Referenced by GpioOutputExample(), and main().

u32 XGpio_DiscreteRead ( XGpio *  InstancePtr,
unsigned  Channel 
)

Reads the state of the discretes for the specified GPIO channel.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
[in]ChannelGPIO channel (1 or 2) to operate on.
Returns
Current copy of the discretes register.
Note
The hardware must be built for dual channels if this function is used with any channel other than 1. If it is not, this function asserts.

References XGpio::BaseAddress, XGpio::IsDual, XGpio::IsReady, XGPIO_CHAN_OFFSET, XGPIO_DATA_OFFSET, and XGpio_ReadReg.

Referenced by GpioInputExample(), and XGpio_SelfTest().

void XGpio_DiscreteSet ( XGpio *  InstancePtr,
unsigned  Channel,
u32  Mask 
)

Sets output discretes to logic 1 for the specified GPIO channel.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
[in]ChannelGPIO channel (1 or 2) to operate on.
[in]MaskSet of bits that are set to 1 in the discrete data register. All other bits in the data register are unaffected.
Note
The hardware must be built for dual channels if this function is used with any channel other than 1. If it is not, this function asserts.

This API can only be used if the GPIO_IO ports in the IP are used for connecting to the external output ports.

References XGpio::BaseAddress, XGpio::IsDual, XGpio::IsReady, XGPIO_CHAN_OFFSET, XGPIO_DATA_OFFSET, XGpio_ReadReg, and XGpio_WriteReg.

void XGpio_DiscreteWrite ( XGpio *  InstancePtr,
unsigned  Channel,
u32  Mask 
)

Writes to the discretes register for the specified GPIO channel.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
[in]ChannelGPIO channel (1 or 2) to operate on.
[in]MaskValue to be written to the discretes register.
Note
The hardware must be built for dual channels if this function is used with any channel other than 1. If it is not, this function asserts. See also XGpio_DiscreteSet() and XGpio_DiscreteClear().

References XGpio::BaseAddress, XGpio::IsDual, XGpio::IsReady, XGPIO_CHAN_OFFSET, XGPIO_DATA_OFFSET, and XGpio_WriteReg.

Referenced by GpioOutputExample(), and main().

u32 XGpio_GetDataDirection ( XGpio *  InstancePtr,
unsigned  Channel 
)

Gets the I/O direction of all discrete signals for a GPIO channel.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
[in]ChannelGPIO channel (1 or 2) to operate on.
Returns
Bitmask specifying which discretes are input and which are output. Bits set to 0 are output and bits set to 1 are input.
Note
The hardware must be built for dual channels if this function is used with any channel other than 1. If it is not, this function asserts.

References XGpio::BaseAddress, XGpio::IsDual, XGpio::IsReady, XGPIO_CHAN_OFFSET, XGpio_ReadReg, and XGPIO_TRI_OFFSET.

int XGpio_Initialize ( XGpio *  InstancePtr,
UINTPTR  BaseAddress 
)

Initializes the XGpio instance by device ID or base address.

This function initializes only InstancePtr.

Parameters
[out]InstancePtrPointer to an XGpio instance. The memory that the pointer references must be pre-allocated by the caller. Further calls to manipulate the instance/driver through the XGpio API must be made with this pointer.
[in]BaseAddressBase address of the device.
Returns
  • XST_SUCCESS if the initialization is successful.
  • XST_DEVICE_NOT_FOUND if the device configuration data was not found for a device with the supplied device ID/BaseAddress.
Note
In XSCT/classic flow, DeviceId is used to look up the device configuration.

References XGpio_Config::BaseAddress, XGpio::IsReady, XGpio_CfgInitialize(), and XGpio_LookupConfig().

Referenced by GpioInputExample(), GpioIntrExample(), GpioOutputExample(), and main().

void XGpio_InterruptClear ( XGpio *  InstancePtr,
u32  Mask 
)

Clears pending interrupts with the provided mask.

Call this function after the software has serviced the interrupts that are pending. This function asserts if the hardware device has not been built with interrupt capabilities.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
[in]MaskMask to clear pending interrupts. Bit positions of 1 are cleared. This mask is a bitwise OR of XGPIO_IR* bits, which are contained in xgpio_l.h.

References XGpio::BaseAddress, XGpio::InterruptPresent, XGpio::IsReady, XGPIO_ISR_OFFSET, XGpio_ReadReg, and XGpio_WriteReg.

Referenced by GpioHandler().

void XGpio_InterruptDisable ( XGpio *  InstancePtr,
u32  Mask 
)

Disables interrupts for the specified channels.

This function disables specific interrupts for each channel. This function asserts if the hardware device has not been built with interrupt capabilities.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
[in]MaskMask to disable. Bits set to 1 are disabled. This mask is a bitwise OR of XGPIO_IR* bits, which are contained in xgpio_l.h.

References XGpio::BaseAddress, XGpio::InterruptPresent, XGpio::IsReady, XGPIO_IER_OFFSET, XGpio_ReadReg, and XGpio_WriteReg.

void XGpio_InterruptEnable ( XGpio *  InstancePtr,
u32  Mask 
)

Enables interrupts for the specified channels.

Also call XGpio_InterruptGlobalEnable() to enable the global interrupt; otherwise, no interrupts occur. This function asserts if the hardware device has not been built with interrupt capabilities.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
[in]MaskMask to enable. Bit positions of 1 are enabled. This mask is a bitwise OR of XGPIO_IR* bits, which are contained in xgpio_l.h.

References XGpio::BaseAddress, XGpio::InterruptPresent, XGpio::IsReady, XGPIO_IER_OFFSET, XGpio_ReadReg, and XGpio_WriteReg.

Referenced by GpioIntrExample().

u32 XGpio_InterruptGetEnabled ( XGpio *  InstancePtr)

Returns the interrupt enable mask.

This function asserts if the hardware device has not been built with interrupt capabilities.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
Returns
A mask of bits made from XGPIO_IR* bits which are contained in xgpio_l.h.

References XGpio::BaseAddress, XGpio::InterruptPresent, XGpio::IsReady, XGPIO_IER_OFFSET, and XGpio_ReadReg.

u32 XGpio_InterruptGetStatus ( XGpio *  InstancePtr)

Returns the status of interrupt signals.

Any bit in the mask set to 1 indicates that the channel associated with the bit has asserted an interrupt condition. This function asserts if the hardware device has not been built with interrupt capabilities.

The interrupt status indicates the status of the device regardless of whether the interrupts from the devices have been enabled or not through XGpio_InterruptEnable().

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
Returns
Mask of bits made from XGPIO_IR* bits which are contained in xgpio_l.h.

References XGpio::BaseAddress, XGpio::InterruptPresent, XGpio::IsReady, XGPIO_ISR_OFFSET, and XGpio_ReadReg.

void XGpio_InterruptGlobalDisable ( XGpio *  InstancePtr)

Disables the interrupt output signal.

Interrupts enabled through XGpio_InterruptEnable() are no longer passed through until the global enable bit is set by XGpio_InterruptGlobalEnable(). This function is designed to allow all interrupts (both channels) to be disabled easily for entering a critical section. This function asserts if the hardware device has not been built with interrupt capabilities.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.

References XGpio::BaseAddress, XGpio::InterruptPresent, XGpio::IsReady, XGPIO_GIE_OFFSET, and XGpio_WriteReg.

void XGpio_InterruptGlobalEnable ( XGpio *  InstancePtr)

Enables the interrupt output signal.

Interrupts enabled through XGpio_InterruptEnable() are not passed through until the global enable bit is set by this function. This function is designed to allow all interrupts (both channels) to be enabled easily for exiting a critical section. This function asserts if the hardware device has not been built with interrupt capabilities.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.

References XGpio::BaseAddress, XGpio::InterruptPresent, XGpio::IsReady, XGPIO_GIE_GINTR_ENABLE_MASK, XGPIO_GIE_OFFSET, and XGpio_WriteReg.

Referenced by GpioIntrExample().

XGpio_Config * XGpio_LookupConfig ( UINTPTR  BaseAddress)

Looks up the device configuration by device ID or base address.

The XGpio_ConfigTable[] contains the configuration information for each device in the system.

Parameters
[in]BaseAddressBase address of the device.
Returns
A pointer to the configuration found or NULL if the specified device ID/BaseAddress was not found. See xgpio.h for the definition of XGpio_Config.
Note
In XSCT/classic flow, DeviceId is used to look up the device configuration.

References XGpio_Config::Name, and XGpio_ConfigTable.

Referenced by GpioIntrExample(), GpioOutputExample(), and XGpio_Initialize().

int XGpio_SelfTest ( XGpio *  InstancePtr)

Runs a self-test on the driver and device.

This function performs a minimal test in which the data register is read. It only does a read without any kind of test. The hardware may be parameterized as input only, and the state of the input is unknown.

All other hardware features of the device are not guaranteed to be in the hardware since they are parameterizable.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on. This parameter must be initialized with XGpio_Initialize().
Returns
XST_SUCCESS always. If the GPIO device is not present in the hardware a bus error is generated. Other indicators of a bus error, such as registers in bridges or buses, may be necessary to determine if this function caused a bus error.

References XGpio::IsReady, and XGpio_DiscreteRead().

void XGpio_SetDataDirection ( XGpio *  InstancePtr,
unsigned  Channel,
u32  DirectionMask 
)

Sets the I/O direction of all discrete signals for a GPIO channel.

Parameters
[in]InstancePtrPointer to the XGpio instance to operate on.
[in]ChannelGPIO channel (1 or 2) to operate on.
[in]DirectionMaskBitmask specifying which discretes are input and which are output. Bits set to 0 are output and bits set to 1 are input.
Note
The hardware must be built for dual channels if this function is used with any channel other than 1. If it is not, this function asserts.

References XGpio::BaseAddress, XGpio::IsDual, XGpio::IsReady, XGPIO_CHAN_OFFSET, XGPIO_TRI_OFFSET, and XGpio_WriteReg.

Referenced by GpioInputExample(), GpioOutputExample(), and main().

Variable Documentation

XGpio_Config XGpio_ConfigTable[]
Initial value:
= {
{
}
}

Configuration table for GPIO devices in the system.

Holds the configuration entry for each GPIO instance.

Referenced by XGpio_LookupConfig().

XGpio_Config XGpio_ConfigTable[]

Holds the configuration entry for each GPIO instance.

Holds the configuration entry for each GPIO instance.

Referenced by XGpio_LookupConfig().