]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/gpio_v4_0/src/xgpio.h
5116edb256f0aa67e6c4aacca5f1976837b4be45
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / gpio_v4_0 / src / xgpio.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2002 - 2014 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 * @file xgpio.h
35 *
36 * This file contains the software API definition of the Xilinx General Purpose
37 * I/O (XGpio) device driver.
38 *
39 * The Xilinx GPIO controller is a soft IP core designed for Xilinx FPGAs and
40 * contains the following general features:
41 *   - Support for up to 32 I/O discretes for each channel (64 bits total).
42 *   - Each of the discretes can be configured for input or output.
43 *   - Configurable support for dual channels and interrupt generation.
44 *
45 * The driver provides interrupt management functions. Implementation of
46 * interrupt handlers is left to the user. Refer to the provided interrupt
47 * example in the examples directory for details.
48 *
49 * This driver is intended to be RTOS and processor independent. Any needs for
50 * dynamic memory management, threads or thread mutual exclusion, virtual
51 * memory, or cache control must be satisfied by the layer above this driver.
52 *
53 * <b>Initialization & Configuration</b>
54 *
55 * The XGpio_Config structure is used by the driver to configure itself. This
56 * configuration structure is typically created by the tool-chain based on HW
57 * build properties.
58 *
59 * To support multiple runtime loading and initialization strategies employed
60 * by various operating systems, the driver instance can be initialized in one
61 * of the following ways:
62 *
63 *   - XGpio_Initialize(InstancePtr, DeviceId) - The driver looks up its own
64 *     configuration structure created by the tool-chain based on an ID provided
65 *     by the tool-chain.
66 *
67 *   - XGpio_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddr) - Uses a
68 *     configuration structure provided by the caller. If running in a system
69 *     with address translation, the provided virtual memory base address
70 *     replaces the physical address present in the configuration structure.
71 *
72 * @note
73 *
74 * This API utilizes 32 bit I/O to the GPIO registers. With less than 32 bits,
75 * the unused bits from registers are read as zero and written as don't cares.
76 *
77 * <pre>
78 * MODIFICATION HISTORY:
79 *
80 * Ver   Who  Date     Changes
81 * ----- ---- -------- -----------------------------------------------
82 * 1.00a rmm  03/13/02 First release
83 * 2.00a jhl  11/26/03 Added support for dual channels and interrupts
84 * 2.01a jvb  12/14/05 I separated dependency on the static config table and
85 *                     xparameters.h from the driver initialization by moving
86 *                     _Initialize and _LookupConfig to _sinit.c. I also added
87 *                     the new _CfgInitialize routine.
88 * 2.11a mta  03/21/07 Updated to new coding style, added GetDataDirection
89 * 2.12a sv   11/21/07 Updated driver to support access through DCR bus
90 * 2.12a sv   06/05/08 Updated driver to fix the XGpio_InterruptDisable function
91 *                     to properly update the Interrupt Enable register
92 * 2.13a sdm  08/22/08 Removed support for static interrupt handlers from the MDD
93 *                     file
94 * 3.00a sv   11/21/09 Updated to use HAL Processor APIs.
95 *                     Renamed the macros XGpio_mWriteReg to XGpio_WriteReg and
96 *                     XGpio_mReadReg to XGpio_ReadReg. Removed the macros
97 *                     XGpio_mSetDataDirection, XGpio_mGetDataReg and
98 *                     XGpio_mSetDataReg. Users should use XGpio_WriteReg and
99 *                     XGpio_ReadReg to achieve the same functionality.
100 * 3.01a bss  04/18/13 Updated driver tcl to generate Canonical params in
101 *                     xparameters.h. CR#698589
102 * 4.0   adk  19/12/13 Updated as per the New Tcl API's
103 * </pre>
104 *****************************************************************************/
105
106 #ifndef XGPIO_H                 /* prevent circular inclusions */
107 #define XGPIO_H                 /* by using protection macros */
108
109 #ifdef __cplusplus
110 extern "C" {
111 #endif
112
113 /***************************** Include Files ********************************/
114
115 #include "xil_types.h"
116 #include "xil_assert.h"
117 #include "xstatus.h"
118 #include "xgpio_l.h"
119
120 /************************** Constant Definitions ****************************/
121
122 /**************************** Type Definitions ******************************/
123
124 /**
125  * This typedef contains configuration information for the device.
126  */
127 typedef struct {
128         u16 DeviceId;           /* Unique ID  of device */
129         u32 BaseAddress;        /* Device base address */
130         int InterruptPresent;   /* Are interrupts supported in h/w */
131         int IsDual;             /* Are 2 channels supported in h/w */
132 } XGpio_Config;
133
134 /**
135  * The XGpio driver instance data. The user is required to allocate a
136  * variable of this type for every GPIO device in the system. A pointer
137  * to a variable of this type is then passed to the driver API functions.
138  */
139 typedef struct {
140         u32 BaseAddress;        /* Device base address */
141         u32 IsReady;            /* Device is initialized and ready */
142         int InterruptPresent;   /* Are interrupts supported in h/w */
143         int IsDual;             /* Are 2 channels supported in h/w */
144 } XGpio;
145
146 /***************** Macros (Inline Functions) Definitions ********************/
147
148
149 /************************** Function Prototypes *****************************/
150
151 /*
152  * Initialization functions in xgpio_sinit.c
153  */
154 int XGpio_Initialize(XGpio *InstancePtr, u16 DeviceId);
155 XGpio_Config *XGpio_LookupConfig(u16 DeviceId);
156
157 /*
158  * API Basic functions implemented in xgpio.c
159  */
160 int XGpio_CfgInitialize(XGpio *InstancePtr, XGpio_Config * Config,
161                         u32 EffectiveAddr);
162 void XGpio_SetDataDirection(XGpio *InstancePtr, unsigned Channel,
163                             u32 DirectionMask);
164 u32 XGpio_GetDataDirection(XGpio *InstancePtr, unsigned Channel);
165 u32 XGpio_DiscreteRead(XGpio *InstancePtr, unsigned Channel);
166 void XGpio_DiscreteWrite(XGpio *InstancePtr, unsigned Channel, u32 Mask);
167
168
169 /*
170  * API Functions implemented in xgpio_extra.c
171  */
172 void XGpio_DiscreteSet(XGpio *InstancePtr, unsigned Channel, u32 Mask);
173 void XGpio_DiscreteClear(XGpio *InstancePtr, unsigned Channel, u32 Mask);
174
175 /*
176  * API Functions implemented in xgpio_selftest.c
177  */
178 int XGpio_SelfTest(XGpio *InstancePtr);
179
180 /*
181  * API Functions implemented in xgpio_intr.c
182  */
183 void XGpio_InterruptGlobalEnable(XGpio *InstancePtr);
184 void XGpio_InterruptGlobalDisable(XGpio *InstancePtr);
185 void XGpio_InterruptEnable(XGpio *InstancePtr, u32 Mask);
186 void XGpio_InterruptDisable(XGpio *InstancePtr, u32 Mask);
187 void XGpio_InterruptClear(XGpio *InstancePtr, u32 Mask);
188 u32 XGpio_InterruptGetEnabled(XGpio *InstancePtr);
189 u32 XGpio_InterruptGetStatus(XGpio *InstancePtr);
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif /* end of protection macro */