Software Drivers

xgpiops.h File Reference

#include "xstatus.h"
#include "xgpiops_hw.h"

Classes

struct  XGpioPs_Config
struct  XGpioPs

Defines

#define XGPIOPS_H
#define XGPIOPS_BANK0   0
#define XGPIOPS_BANK1   1
#define XGPIOPS_BANK2   2
#define XGPIOPS_BANK3   3
#define XGPIOPS_MAX_BANKS   4
#define XGPIOPS_BANK_MAX_PINS   32
#define XGPIOPS_DEVICE_MAX_PIN_NUM   118
Interrupt types

The following constants define the interrupt types that can be set for each GPIO pin.



#define XGPIOPS_IRQ_TYPE_EDGE_RISING   0
#define XGPIOPS_IRQ_TYPE_EDGE_FALLING   1
#define XGPIOPS_IRQ_TYPE_EDGE_BOTH   2
#define XGPIOPS_IRQ_TYPE_LEVEL_HIGH   3
#define XGPIOPS_IRQ_TYPE_LEVEL_LOW   4

Typedefs

typedef void(* XGpioPs_Handler )(void *CallBackRef, int Bank, u32 Status)

Functions

int XGpioPs_CfgInitialize (XGpioPs *InstancePtr, XGpioPs_Config *ConfigPtr, u32 EffectiveAddr)
u32 XGpioPs_Read (XGpioPs *InstancePtr, u8 Bank)
void XGpioPs_Write (XGpioPs *InstancePtr, u8 Bank, u32 Data)
void XGpioPs_SetDirection (XGpioPs *InstancePtr, u8 Bank, u32 Direction)
u32 XGpioPs_GetDirection (XGpioPs *InstancePtr, u8 Bank)
void XGpioPs_SetOutputEnable (XGpioPs *InstancePtr, u8 Bank, u32 Enable)
u32 XGpioPs_GetOutputEnable (XGpioPs *InstancePtr, u8 Bank)
void XGpioPs_GetBankPin (u8 PinNumber, u8 *BankNumber, u8 *PinNumberInBank)
int XGpioPs_ReadPin (XGpioPs *InstancePtr, int Pin)
void XGpioPs_WritePin (XGpioPs *InstancePtr, int Pin, int Data)
void XGpioPs_SetDirectionPin (XGpioPs *InstancePtr, int Pin, int Direction)
int XGpioPs_GetDirectionPin (XGpioPs *InstancePtr, int Pin)
void XGpioPs_SetOutputEnablePin (XGpioPs *InstancePtr, int Pin, int Enable)
int XGpioPs_GetOutputEnablePin (XGpioPs *InstancePtr, int Pin)
int XGpioPs_SelfTest (XGpioPs *InstancePtr)
void XGpioPs_IntrEnable (XGpioPs *InstancePtr, u8 Bank, u32 Mask)
void XGpioPs_IntrDisable (XGpioPs *InstancePtr, u8 Bank, u32 Mask)
u32 XGpioPs_IntrGetEnabled (XGpioPs *InstancePtr, u8 Bank)
u32 XGpioPs_IntrGetStatus (XGpioPs *InstancePtr, u8 Bank)
void XGpioPs_IntrClear (XGpioPs *InstancePtr, u8 Bank, u32 Mask)
void XGpioPs_SetIntrType (XGpioPs *InstancePtr, u8 Bank, u32 IntrType, u32 IntrPolarity, u32 IntrOnAny)
void XGpioPs_GetIntrType (XGpioPs *InstancePtr, u8 Bank, u32 *IntrType, u32 *IntrPolarity, u32 *IntrOnAny)
void XGpioPs_SetCallbackHandler (XGpioPs *InstancePtr, void *CallBackRef, XGpioPs_Handler FuncPtr)
void XGpioPs_IntrHandler (XGpioPs *InstancePtr)
void XGpioPs_SetIntrTypePin (XGpioPs *InstancePtr, int Pin, u8 IrqType)
u8 XGpioPs_GetIntrTypePin (XGpioPs *InstancePtr, int Pin)
void XGpioPs_IntrEnablePin (XGpioPs *InstancePtr, int Pin)
void XGpioPs_IntrDisablePin (XGpioPs *InstancePtr, int Pin)
int XGpioPs_IntrGetEnabledPin (XGpioPs *InstancePtr, int Pin)
int XGpioPs_IntrGetStatusPin (XGpioPs *InstancePtr, int Pin)
void XGpioPs_IntrClearPin (XGpioPs *InstancePtr, int Pin)
XGpioPs_ConfigXGpioPs_LookupConfig (u16 DeviceId)

Detailed Description


Define Documentation

#define XGPIOPS_BANK0   0

GPIO Bank 0

#define XGPIOPS_BANK1   1

GPIO Bank 1

#define XGPIOPS_BANK2   2

GPIO Bank 2

#define XGPIOPS_BANK3   3

GPIO Bank 3

#define XGPIOPS_BANK_MAX_PINS   32

Max pins in a GPIO bank

#define XGPIOPS_DEVICE_MAX_PIN_NUM   118
#define XGPIOPS_H
#define XGPIOPS_IRQ_TYPE_EDGE_BOTH   2

Interrupt on both edges

#define XGPIOPS_IRQ_TYPE_EDGE_FALLING   1

Interrupt Falling edge

#define XGPIOPS_IRQ_TYPE_EDGE_RISING   0

Interrupt on Rising edge

#define XGPIOPS_IRQ_TYPE_LEVEL_HIGH   3

Interrupt on high level

#define XGPIOPS_IRQ_TYPE_LEVEL_LOW   4

Interrupt on low level

#define XGPIOPS_MAX_BANKS   4

Max banks in a GPIO device


Typedef Documentation

typedef void(* XGpioPs_Handler)(void *CallBackRef, int Bank, u32 Status)

This handler data type allows the user to define a callback function to handle the interrupts for the GPIO device. The application using this driver is expected to define a handler of this type, to support interrupt driven mode. The handler executes in an interrupt context such that minimal processing should be performed.

Parameters:
CallBackRef is a callback reference passed in by the upper layer when setting the callback functions for a GPIO bank. It is passed back to the upper layer when the callback is invoked. Its type is not important to the driver component, so it is a void pointer.
Bank is the bank for which the interrupt status has changed.
Status is the Interrupt status of the GPIO bank.

Function Documentation

int XGpioPs_CfgInitialize ( XGpioPs InstancePtr,
XGpioPs_Config ConfigPtr,
u32  EffectiveAddr 
)
void XGpioPs_GetBankPin ( u8  PinNumber,
u8 *  BankNumber,
u8 *  PinNumberInBank 
)
u32 XGpioPs_GetDirection ( XGpioPs InstancePtr,
u8  Bank 
)

Get the Direction of the pins of the specified GPIO Bank.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.

return Returns a 32 bit mask of the Direction register. Bits with 0 are in Input mode, bits with 1 are in Output Mode.

Note:
None.
int XGpioPs_GetDirectionPin ( XGpioPs InstancePtr,
int  Pin 
)

Get the Direction of the specified pin.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number for which the Direction is to be retrieved. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
Returns:
Direction of the specified pin.
  • 0 for Input Direction
  • 1 for Output Direction
Note:
None.
void XGpioPs_GetIntrType ( XGpioPs InstancePtr,
u8  Bank,
u32 *  IntrType,
u32 *  IntrPolarity,
u32 *  IntrOnAny 
)

This function is used for getting the Interrupt Type, Interrupt Polarity and Interrupt On Any for the specified GPIO Bank pins.

Parameters:
InstancePtr is a pointer to an XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
IntrType returns the 32 bit mask of the interrupt type. 0 means Level Sensitive and 1 means Edge Sensitive.
IntrPolarity returns the 32 bit mask of the interrupt polarity. 0 means Active Low or Falling Edge and 1 means Active High or Rising Edge.
IntrOnAny returns the 32 bit mask of the interrupt trigger for edge triggered interrupts. 0 means trigger on single edge using the configured interrupt polarity and 1 means trigger on both edges.
Returns:
None.
Note:
None.
u8 XGpioPs_GetIntrTypePin ( XGpioPs InstancePtr,
int  Pin 
)

This function returns the IRQ Type of a given GPIO pin.

Parameters:
InstancePtr is a pointer to an XGpioPs instance.
Pin is the pin number whose IRQ type is to be obtained. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
Returns:
None.
Note:
Use XGPIOPS_IRQ_TYPE_* defined in xgpiops.h for the IRQ type returned by this function.
u32 XGpioPs_GetOutputEnable ( XGpioPs InstancePtr,
u8  Bank 
)

Get the Output Enable status of the pins of the specified GPIO Bank.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.

return Returns a a 32 bit mask of the Output Enable register. Bits with 0 are in Disabled state, bits with 1 are in Enabled State.

Note:
None.
int XGpioPs_GetOutputEnablePin ( XGpioPs InstancePtr,
int  Pin 
)

Get the Output Enable status of the specified pin.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number for which the Output Enable status is to be retrieved. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
Returns:
Output Enable of the specified pin.
  • 0 if Output Enable is disabled for this pin
  • 1 if Output Enable is enabled for this pin
Note:
None.
void XGpioPs_IntrClear ( XGpioPs InstancePtr,
u8  Bank,
u32  Mask 
)

This function clears pending interrupt(s) with the provided mask. This function should be called after the software has serviced the interrupts that are pending.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
Mask is the mask of the interrupts to be cleared. Bit positions of 1 will be cleared. Bit positions of 0 will not change the previous interrupt status.
Note:
None.
void XGpioPs_IntrClearPin ( XGpioPs InstancePtr,
int  Pin 
)

This function clears the specified pending interrupt. This function should be called after the software has serviced the interrupts that are pending.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number for which the interrupt status is to be cleared. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
Note:
None.
void XGpioPs_IntrDisable ( XGpioPs InstancePtr,
u8  Bank,
u32  Mask 
)

This function disables the interrupts for the specified pins in the specified bank.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
Mask is the bit mask of the pins for which interrupts are to be disabled. Bit positions of 1 will be disabled. Bit positions of 0 will keep the previous setting.
Returns:
None.
Note:
None.
void XGpioPs_IntrDisablePin ( XGpioPs InstancePtr,
int  Pin 
)

This function disables the interrupts for the specified pin.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number for which the interrupt is to be disabled. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
Returns:
None.
Note:
None.
void XGpioPs_IntrEnable ( XGpioPs InstancePtr,
u8  Bank,
u32  Mask 
)

This function enables the interrupts for the specified pins in the specified bank.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
Mask is the bit mask of the pins for which interrupts are to be enabled. Bit positions of 1 will be enabled. Bit positions of 0 will keep the previous setting.
Returns:
None.
Note:
None.
void XGpioPs_IntrEnablePin ( XGpioPs InstancePtr,
int  Pin 
)

This function enables the interrupt for the specified pin.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number for which the interrupt is to be enabled. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
Returns:
None.
Note:
None.
u32 XGpioPs_IntrGetEnabled ( XGpioPs InstancePtr,
u8  Bank 
)

This function returns the interrupt enable status for a bank.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
Returns:
Enabled interrupt(s) in a 32-bit format. Bit positions with 1 indicate that the interrupt for that pin is enabled, bit positions with 0 indicate that the interrupt for that pin is disabled.
Note:
None.
int XGpioPs_IntrGetEnabledPin ( XGpioPs InstancePtr,
int  Pin 
)

This function returns whether interrupts are enabled for the specified pin.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number for which the interrupt enable status is to be known. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
Returns:
  • TRUE if the interrupt is enabled.
  • FALSE if the interrupt is disabled.
Note:
None.
u32 XGpioPs_IntrGetStatus ( XGpioPs InstancePtr,
u8  Bank 
)

This function returns interrupt status read from Interrupt Status Register.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
Returns:
The value read from Interrupt Status Register.
Note:
None.
int XGpioPs_IntrGetStatusPin ( XGpioPs InstancePtr,
int  Pin 
)

This function returns interrupt enable status of the specified pin.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number for which the interrupt enable status is to be known. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
Returns:
  • TRUE if the interrupt has occurred.
  • FALSE if the interrupt has not occurred.
Note:
None.
void XGpioPs_IntrHandler ( XGpioPs InstancePtr  ) 

This function is the interrupt handler for GPIO interrupts.It checks the interrupt status registers of all the banks to determine the actual bank in which an interrupt has been triggered. It then calls the upper layer callback handler set by the function XGpioPs_SetBankHandler(). The callback is called when an interrupt

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Returns:
None.
Note:
This function does not save and restore the processor context such that the user must provide this processing.
XGpioPs_Config* XGpioPs_LookupConfig ( u16  DeviceId  ) 

This function looks for the device configuration based on the unique device ID. The table XGpioPs_ConfigTable[] contains the configuration information for each device in the system.

Parameters:
DeviceId is the unique device ID of the device being looked up.
Returns:
A pointer to the configuration table entry corresponding to the given device ID, or NULL if no match is found.
Note:
None.
u32 XGpioPs_Read ( XGpioPs InstancePtr,
u8  Bank 
)

Read the Data register of the specified GPIO bank.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
Returns:
Current value of the Data register.
Note:
This function is used for reading the state of all the GPIO pins of specified bank.
int XGpioPs_ReadPin ( XGpioPs InstancePtr,
int  Pin 
)

Read Data from the specified pin.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number for which the data has to be read. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1. See xgpiops.h for the mapping of the pin numbers in the banks.
Returns:
Current value of the Pin (0 or 1).
Note:
This function is used for reading the state of the specified GPIO pin.
int XGpioPs_SelfTest ( XGpioPs InstancePtr  ) 

This function runs a self-test on the GPIO driver/device. This function does a register read/write test on some of the Interrupt Registers.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Returns:
  • XST_SUCCESS if the self-test passed.
  • XST_FAILURE otherwise.
void XGpioPs_SetCallbackHandler ( XGpioPs InstancePtr,
void *  CallBackRef,
XGpioPs_Handler  FuncPtr 
)

This function sets the status callback function. The callback function is called by the XGpioPs_IntrHandler when an interrupt occurs.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
CallBackRef is the upper layer callback reference passed back when the callback function is invoked.
FuncPtr is the pointer to the callback function.
Returns:
None.
Note:
The handler is called within interrupt context, so it should do its work quickly and queue potentially time-consuming work to a task-level thread.
void XGpioPs_SetDirection ( XGpioPs InstancePtr,
u8  Bank,
u32  Direction 
)

Set the Direction of the pins of the specified GPIO Bank.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
Direction is the 32 bit mask of the Pin direction to be set for all the pins in the Bank. Bits with 0 are set to Input mode, bits with 1 are set to Output Mode.
Returns:
None.
Note:
This function is used for setting the direction of all the pins in the specified bank. The previous state of the pins is not maintained.
void XGpioPs_SetDirectionPin ( XGpioPs InstancePtr,
int  Pin,
int  Direction 
)

Set the Direction of the specified pin.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number to which the Data is to be written. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
Direction is the direction to be set for the specified pin. Valid values are 0 for Input Direction, 1 for Output Direction.
Returns:
None.
void XGpioPs_SetIntrType ( XGpioPs InstancePtr,
u8  Bank,
u32  IntrType,
u32  IntrPolarity,
u32  IntrOnAny 
)

This function is used for setting the Interrupt Type, Interrupt Polarity and Interrupt On Any for the specified GPIO Bank pins.

Parameters:
InstancePtr is a pointer to an XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
IntrType is the 32 bit mask of the interrupt type. 0 means Level Sensitive and 1 means Edge Sensitive.
IntrPolarity is the 32 bit mask of the interrupt polarity. 0 means Active Low or Falling Edge and 1 means Active High or Rising Edge.
IntrOnAny is the 32 bit mask of the interrupt trigger for edge triggered interrupts. 0 means trigger on single edge using the configured interrupt polarity and 1 means trigger on both edges.
Returns:
None.
Note:
This function is used for setting the interrupt related properties of all the pins in the specified bank. The previous state of the pins is not maintained. To change the Interrupt properties of a single GPIO pin, use the function XGpioPs_SetPinIntrType().
void XGpioPs_SetIntrTypePin ( XGpioPs InstancePtr,
int  Pin,
u8  IrqType 
)

This function is used for setting the IRQ Type of a single GPIO pin.

Parameters:
InstancePtr is a pointer to an XGpioPs instance.
Pin is the pin number whose IRQ type is to be set. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
IrqType is the IRQ type for GPIO Pin. Use XGPIOPS_IRQ_TYPE_* defined in xgpiops.h to specify the IRQ type.
Returns:
None.
Note:
None.
void XGpioPs_SetOutputEnable ( XGpioPs InstancePtr,
u8  Bank,
u32  OpEnable 
)

Set the Output Enable of the pins of the specified GPIO Bank.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
OpEnable is the 32 bit mask of the Output Enables to be set for all the pins in the Bank. The Output Enable of bits with 0 are disabled, the Output Enable of bits with 1 are enabled.
Returns:
None.
Note:
This function is used for setting the Output Enables of all the pins in the specified bank. The previous state of the Output Enables is not maintained.
void XGpioPs_SetOutputEnablePin ( XGpioPs InstancePtr,
int  Pin,
int  OpEnable 
)

Set the Output Enable of the specified pin.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number to which the Data is to be written. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
OpEnable specifies whether the Output Enable for the specified pin should be enabled. Valid values are 0 for Disabling Output Enable, 1 for Enabling Output Enable.
Returns:
None.
Note:
None.
void XGpioPs_Write ( XGpioPs InstancePtr,
u8  Bank,
u32  Data 
)

Write to the Data register of the specified GPIO bank.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Bank is the bank number of the GPIO to operate on. Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
Data is the value to be written to the Data register.
Returns:
None.
Note:
This function is used for writing to all the GPIO pins of the bank. The previous state of the pins is not maintained.
void XGpioPs_WritePin ( XGpioPs InstancePtr,
int  Pin,
int  Data 
)

Write data to the specified pin.

Parameters:
InstancePtr is a pointer to the XGpioPs instance.
Pin is the pin number to which the Data is to be written. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
Data is the data to be written to the specified pin (0 or 1).
Returns:
None.
Note:
This function does a masked write to the specified pin of the specified GPIO bank. The previous state of other pins is maintained.