]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/include/xgpiops.h
c2825cca1a2310a5d99675181cc8bdf53c7ba608
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / include / xgpiops.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 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 *
35 * @file xgpiops.h
36 * @addtogroup gpiops_v2_1
37 * @{
38 * @details
39 *
40 * The Xilinx PS GPIO driver. This driver supports the Xilinx PS GPIO
41 * Controller.
42 *
43 * The GPIO Controller supports the following features:
44 *       - 4 banks
45 *       - Masked writes (There are no masked reads)
46 *       - Bypass mode
47 *       - Configurable Interrupts (Level/Edge)
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 * This driver supports all the features listed above, if applicable.
54 *
55 * <b>Driver Description</b>
56 *
57 * The device driver enables higher layer software (e.g., an application) to
58 * communicate to the GPIO.
59 *
60 * <b>Interrupts</b>
61 *
62 * The driver provides interrupt management functions and an interrupt handler.
63 * Users of this driver need to provide callback functions. An interrupt handler
64 * example is available with the driver.
65 *
66 * <b>Threads</b>
67 *
68 * This driver is not thread safe. Any needs for threads or thread mutual
69 * exclusion must be satisfied by the layer above this driver.
70 *
71 * <b>Asserts</b>
72 *
73 * Asserts are used within all Xilinx drivers to enforce constraints on argument
74 * values. Asserts can be turned off on a system-wide basis by defining, at
75 * compile time, the NDEBUG identifier. By default, asserts are turned on and it
76 * is recommended that users leave asserts on during development.
77 *
78 * <b>Building the driver</b>
79 *
80 * The XGpioPs driver is composed of several source files. This allows the user
81 * to build and link only those parts of the driver that are necessary.
82 * <br><br>
83 *
84 * <pre>
85 * MODIFICATION HISTORY:
86 *
87 * Ver   Who  Date     Changes
88 * ----- ---- -------- -----------------------------------------------
89 * 1.00a sv   01/15/10 First Release
90 * 1.01a sv   04/15/12 Removed the APIs XGpioPs_SetMode, XGpioPs_SetModePin
91 *                     XGpioPs_GetMode, XGpioPs_GetModePin as they are not
92 *                     relevant to Zynq device.The interrupts are disabled
93 *                     for output pins on all banks during initialization.
94 * 1.02a hk   08/22/13 Added low level reset API
95 * 2.1   hk   04/29/14 Use Input data register DATA_RO for read. CR# 771667.
96 *
97 * </pre>
98 *
99 ******************************************************************************/
100 #ifndef XGPIOPS_H               /* prevent circular inclusions */
101 #define XGPIOPS_H               /* by using protection macros */
102
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
106
107 /***************************** Include Files *********************************/
108
109 #include "xstatus.h"
110 #include "xgpiops_hw.h"
111
112 /************************** Constant Definitions *****************************/
113
114 /** @name Interrupt types
115  *  @{
116  * The following constants define the interrupt types that can be set for each
117  * GPIO pin.
118  */
119 #define XGPIOPS_IRQ_TYPE_EDGE_RISING    0  /**< Interrupt on Rising edge */
120 #define XGPIOPS_IRQ_TYPE_EDGE_FALLING   1  /**< Interrupt Falling edge */
121 #define XGPIOPS_IRQ_TYPE_EDGE_BOTH      2  /**< Interrupt on both edges */
122 #define XGPIOPS_IRQ_TYPE_LEVEL_HIGH     3  /**< Interrupt on high level */
123 #define XGPIOPS_IRQ_TYPE_LEVEL_LOW      4  /**< Interrupt on low level */
124 /*@}*/
125
126 #define XGPIOPS_BANK0                   0  /**< GPIO Bank 0 */
127 #define XGPIOPS_BANK1                   1  /**< GPIO Bank 1 */
128 #define XGPIOPS_BANK2                   2  /**< GPIO Bank 2 */
129 #define XGPIOPS_BANK3                   3  /**< GPIO Bank 3 */
130
131 #define XGPIOPS_MAX_BANKS               4  /**< Max banks in a GPIO device */
132 #define XGPIOPS_BANK_MAX_PINS           32 /**< Max pins in a GPIO bank */
133
134 #define XGPIOPS_DEVICE_MAX_PIN_NUM      118 /*< Max pins in the GPIO device
135                                               * 0 - 31,  Bank 0
136                                               * 32 - 53, Bank 1
137                                               * 54 - 85, Bank 2
138                                               * 86 - 117, Bank 3
139                                               */
140
141 /**************************** Type Definitions *******************************/
142
143 /****************************************************************************/
144 /**
145  * This handler data type allows the user to define a callback function to
146  * handle the interrupts for the GPIO device. The application using this
147  * driver is expected to define a handler of this type, to support interrupt
148  * driven mode. The handler executes in an interrupt context such that minimal
149  * processing should be performed.
150  *
151  * @param       CallBackRef is a callback reference passed in by the upper layer
152  *              when setting the callback functions for a GPIO bank. It is
153  *              passed back to the upper layer when the callback is invoked. Its
154  *              type is not important to the driver component, so it is a void
155  *              pointer.
156  * @param       Bank is the bank for which the interrupt status has changed.
157  * @param       Status is the Interrupt status of the GPIO bank.
158  *
159  *****************************************************************************/
160 typedef void (*XGpioPs_Handler) (void *CallBackRef, int Bank, u32 Status);
161
162 /**
163  * This typedef contains configuration information for a device.
164  */
165 typedef struct {
166         u16 DeviceId;           /**< Unique ID of device */
167         u32 BaseAddr;           /**< Register base address */
168 } XGpioPs_Config;
169
170 /**
171  * The XGpioPs driver instance data. The user is required to allocate a
172  * variable of this type for the GPIO device in the system. A pointer
173  * to a variable of this type is then passed to the driver API functions.
174  */
175 typedef struct {
176         XGpioPs_Config GpioConfig;      /**< Device configuration */
177         u32 IsReady;                    /**< Device is initialized and ready */
178         XGpioPs_Handler Handler;        /**< Status handlers for all banks */
179         void *CallBackRef;              /**< Callback ref for bank handlers */
180 } XGpioPs;
181
182 /***************** Macros (Inline Functions) Definitions *********************/
183
184 /************************** Function Prototypes ******************************/
185
186 /*
187  * Functions in xgpiops.c
188  */
189 int XGpioPs_CfgInitialize(XGpioPs *InstancePtr, XGpioPs_Config *ConfigPtr,
190                            u32 EffectiveAddr);
191
192 /*
193  * Bank APIs in xgpiops.c
194  */
195 u32 XGpioPs_Read(XGpioPs *InstancePtr, u8 Bank);
196 void XGpioPs_Write(XGpioPs *InstancePtr, u8 Bank, u32 Data);
197 void XGpioPs_SetDirection(XGpioPs *InstancePtr, u8 Bank, u32 Direction);
198 u32 XGpioPs_GetDirection(XGpioPs *InstancePtr, u8 Bank);
199 void XGpioPs_SetOutputEnable(XGpioPs *InstancePtr, u8 Bank, u32 Enable);
200 u32 XGpioPs_GetOutputEnable(XGpioPs *InstancePtr, u8 Bank);
201 void XGpioPs_GetBankPin(u8 PinNumber,   u8 *BankNumber, u8 *PinNumberInBank);
202
203 /*
204  * Pin APIs in xgpiops.c
205  */
206 int XGpioPs_ReadPin(XGpioPs *InstancePtr, int Pin);
207 void XGpioPs_WritePin(XGpioPs *InstancePtr, int Pin, int Data);
208 void XGpioPs_SetDirectionPin(XGpioPs *InstancePtr, int Pin, int Direction);
209 int XGpioPs_GetDirectionPin(XGpioPs *InstancePtr, int Pin);
210 void XGpioPs_SetOutputEnablePin(XGpioPs *InstancePtr, int Pin, int Enable);
211 int XGpioPs_GetOutputEnablePin(XGpioPs *InstancePtr, int Pin);
212
213 /*
214  * Diagnostic functions in xgpiops_selftest.c
215  */
216 int XGpioPs_SelfTest(XGpioPs *InstancePtr);
217
218 /*
219  * Functions in xgpiops_intr.c
220  */
221 /*
222  * Bank APIs in xgpiops_intr.c
223  */
224 void XGpioPs_IntrEnable(XGpioPs *InstancePtr, u8 Bank, u32 Mask);
225 void XGpioPs_IntrDisable(XGpioPs *InstancePtr, u8 Bank, u32 Mask);
226 u32 XGpioPs_IntrGetEnabled(XGpioPs *InstancePtr, u8 Bank);
227 u32 XGpioPs_IntrGetStatus(XGpioPs *InstancePtr, u8 Bank);
228 void XGpioPs_IntrClear(XGpioPs *InstancePtr, u8 Bank, u32 Mask);
229 void XGpioPs_SetIntrType(XGpioPs *InstancePtr, u8 Bank, u32 IntrType,
230                           u32 IntrPolarity, u32 IntrOnAny);
231 void XGpioPs_GetIntrType(XGpioPs *InstancePtr, u8 Bank, u32 *IntrType,
232                           u32 *IntrPolarity, u32 *IntrOnAny);
233 void XGpioPs_SetCallbackHandler(XGpioPs *InstancePtr, void *CallBackRef,
234                              XGpioPs_Handler FuncPtr);
235 void XGpioPs_IntrHandler(XGpioPs *InstancePtr);
236
237 /*
238  * Pin APIs in xgpiops_intr.c
239  */
240 void XGpioPs_SetIntrTypePin(XGpioPs *InstancePtr, int Pin, u8 IrqType);
241 u8 XGpioPs_GetIntrTypePin(XGpioPs *InstancePtr, int Pin);
242
243 void XGpioPs_IntrEnablePin(XGpioPs *InstancePtr, int Pin);
244 void XGpioPs_IntrDisablePin(XGpioPs *InstancePtr, int Pin);
245 int XGpioPs_IntrGetEnabledPin(XGpioPs *InstancePtr, int Pin);
246 int XGpioPs_IntrGetStatusPin(XGpioPs *InstancePtr, int Pin);
247 void XGpioPs_IntrClearPin(XGpioPs *InstancePtr, int Pin);
248
249 /*
250  * Functions in xgpiops_sinit.c
251  */
252 XGpioPs_Config *XGpioPs_LookupConfig(u16 DeviceId);
253
254 #ifdef __cplusplus
255 }
256 #endif
257
258 #endif /* end of protection macro */
259 /** @} */