1 /******************************************************************************
3 * Copyright (C) 2002 - 2015 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
35 * @addtogroup gpio_v4_1
39 * This file contains the software API definition of the Xilinx General Purpose
40 * I/O (XGpio) device driver.
42 * The Xilinx GPIO controller is a soft IP core designed for Xilinx FPGAs and
43 * contains the following general features:
44 * - Support for up to 32 I/O discretes for each channel (64 bits total).
45 * - Each of the discretes can be configured for input or output.
46 * - Configurable support for dual channels and interrupt generation.
48 * The driver provides interrupt management functions. Implementation of
49 * interrupt handlers is left to the user. Refer to the provided interrupt
50 * example in the examples directory for details.
52 * This driver is intended to be RTOS and processor independent. Any needs for
53 * dynamic memory management, threads or thread mutual exclusion, virtual
54 * memory, or cache control must be satisfied by the layer above this driver.
56 * <b>Initialization & Configuration</b>
58 * The XGpio_Config structure is used by the driver to configure itself. This
59 * configuration structure is typically created by the tool-chain based on HW
62 * To support multiple runtime loading and initialization strategies employed
63 * by various operating systems, the driver instance can be initialized in one
64 * of the following ways:
66 * - XGpio_Initialize(InstancePtr, DeviceId) - The driver looks up its own
67 * configuration structure created by the tool-chain based on an ID provided
70 * - XGpio_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddr) - Uses a
71 * configuration structure provided by the caller. If running in a system
72 * with address translation, the provided virtual memory base address
73 * replaces the physical address present in the configuration structure.
77 * This API utilizes 32 bit I/O to the GPIO registers. With less than 32 bits,
78 * the unused bits from registers are read as zero and written as don't cares.
81 * MODIFICATION HISTORY:
83 * Ver Who Date Changes
84 * ----- ---- -------- -----------------------------------------------
85 * 1.00a rmm 03/13/02 First release
86 * 2.00a jhl 11/26/03 Added support for dual channels and interrupts
87 * 2.01a jvb 12/14/05 I separated dependency on the static config table and
88 * xparameters.h from the driver initialization by moving
89 * _Initialize and _LookupConfig to _sinit.c. I also added
90 * the new _CfgInitialize routine.
91 * 2.11a mta 03/21/07 Updated to new coding style, added GetDataDirection
92 * 2.12a sv 11/21/07 Updated driver to support access through DCR bus
93 * 2.12a sv 06/05/08 Updated driver to fix the XGpio_InterruptDisable function
94 * to properly update the Interrupt Enable register
95 * 2.13a sdm 08/22/08 Removed support for static interrupt handlers from the MDD
97 * 3.00a sv 11/21/09 Updated to use HAL Processor APIs.
98 * Renamed the macros XGpio_mWriteReg to XGpio_WriteReg and
99 * XGpio_mReadReg to XGpio_ReadReg. Removed the macros
100 * XGpio_mSetDataDirection, XGpio_mGetDataReg and
101 * XGpio_mSetDataReg. Users should use XGpio_WriteReg and
102 * XGpio_ReadReg to achieve the same functionality.
103 * 3.01a bss 04/18/13 Updated driver tcl to generate Canonical params in
104 * xparameters.h. CR#698589
105 * 4.0 adk 19/12/13 Updated as per the New Tcl API's
106 * 4.1 lks 11/18/15 Updated to use cannonical xparameters in examples and
107 * clean up of the comments, removed support for DCR bridge
108 * and removed xgpio_intr_example for CR 900381
111 *****************************************************************************/
113 #ifndef XGPIO_H /* prevent circular inclusions */
114 #define XGPIO_H /* by using protection macros */
120 /***************************** Include Files ********************************/
122 #include "xil_types.h"
123 #include "xil_assert.h"
127 /************************** Constant Definitions ****************************/
129 /**************************** Type Definitions ******************************/
132 * This typedef contains configuration information for the device.
135 u16 DeviceId; /* Unique ID of device */
136 u32 BaseAddress; /* Device base address */
137 int InterruptPresent; /* Are interrupts supported in h/w */
138 int IsDual; /* Are 2 channels supported in h/w */
142 * The XGpio driver instance data. The user is required to allocate a
143 * variable of this type for every GPIO device in the system. A pointer
144 * to a variable of this type is then passed to the driver API functions.
147 u32 BaseAddress; /* Device base address */
148 u32 IsReady; /* Device is initialized and ready */
149 int InterruptPresent; /* Are interrupts supported in h/w */
150 int IsDual; /* Are 2 channels supported in h/w */
153 /***************** Macros (Inline Functions) Definitions ********************/
156 /************************** Function Prototypes *****************************/
159 * Initialization functions in xgpio_sinit.c
161 int XGpio_Initialize(XGpio *InstancePtr, u16 DeviceId);
162 XGpio_Config *XGpio_LookupConfig(u16 DeviceId);
165 * API Basic functions implemented in xgpio.c
167 int XGpio_CfgInitialize(XGpio *InstancePtr, XGpio_Config * Config,
169 void XGpio_SetDataDirection(XGpio *InstancePtr, unsigned Channel,
171 u32 XGpio_GetDataDirection(XGpio *InstancePtr, unsigned Channel);
172 u32 XGpio_DiscreteRead(XGpio *InstancePtr, unsigned Channel);
173 void XGpio_DiscreteWrite(XGpio *InstancePtr, unsigned Channel, u32 Mask);
177 * API Functions implemented in xgpio_extra.c
179 void XGpio_DiscreteSet(XGpio *InstancePtr, unsigned Channel, u32 Mask);
180 void XGpio_DiscreteClear(XGpio *InstancePtr, unsigned Channel, u32 Mask);
183 * API Functions implemented in xgpio_selftest.c
185 int XGpio_SelfTest(XGpio *InstancePtr);
188 * API Functions implemented in xgpio_intr.c
190 void XGpio_InterruptGlobalEnable(XGpio *InstancePtr);
191 void XGpio_InterruptGlobalDisable(XGpio *InstancePtr);
192 void XGpio_InterruptEnable(XGpio *InstancePtr, u32 Mask);
193 void XGpio_InterruptDisable(XGpio *InstancePtr, u32 Mask);
194 void XGpio_InterruptClear(XGpio *InstancePtr, u32 Mask);
195 u32 XGpio_InterruptGetEnabled(XGpio *InstancePtr);
196 u32 XGpio_InterruptGetStatus(XGpio *InstancePtr);
202 #endif /* end of protection macro */