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