]> 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.c
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.c
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.c
36 *
37 * The XGpioPs driver. Functions in this file are the minimum required functions
38 * for this driver. See xgpiops.h for a detailed description of the driver.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
43 * Ver   Who  Date     Changes
44 * ----- ---- -------- -----------------------------------------------
45 * 1.00a sv   01/15/10 First Release
46 * 1.01a sv   04/15/12 Removed the APIs XGpioPs_SetMode, XGpioPs_SetModePin
47 *                     XGpioPs_GetMode, XGpioPs_GetModePin as they are not
48 *                     relevant to Zynq device. The interrupts are disabled
49 *                     for output pins on all banks during initialization.
50 * 2.1   hk   04/29/14 Use Input data register DATA_RO for read. CR# 771667.
51 * 3.00  kvn  02/13/15 Modified code for MISRA-C:2012 compliance.
52 *
53 * </pre>
54 *
55 ******************************************************************************/
56
57 /***************************** Include Files *********************************/
58
59 #include "xgpiops.h"
60
61 /************************** Constant Definitions *****************************/
62
63 /**************************** Type Definitions *******************************/
64
65 /***************** Macros (Inline Functions) Definitions *********************/
66
67 /************************** Variable Definitions *****************************/
68
69
70 /************************** Function Prototypes ******************************/
71
72 extern void StubHandler(void *CallBackRef, u32 Bank, u32 Status);
73
74 /*****************************************************************************/
75 /*
76 *
77 * This function initializes a XGpioPs instance/driver.
78 * All members of the XGpioPs instance structure are initialized and
79 * StubHandlers are assigned to the Bank Status Handlers.
80 *
81 * @param        InstancePtr is a pointer to the XGpioPs instance.
82 * @param        ConfigPtr points to the XGpioPs device configuration structure.
83 * @param        EffectiveAddr is the device base address in the virtual memory
84 *               address space. If the address translation is not used then the
85 *               physical address should be passed.
86 *               Unexpected errors may occur if the address mapping is changed
87 *               after this function is invoked.
88 *
89 * @return       XST_SUCCESS always.
90 *
91 * @note         None.
92 *
93 ******************************************************************************/
94 s32 XGpioPs_CfgInitialize(XGpioPs *InstancePtr, XGpioPs_Config *ConfigPtr,
95                                 u32 EffectiveAddr)
96 {
97         s32 Status = XST_SUCCESS;
98         Xil_AssertNonvoid(InstancePtr != NULL);
99         Xil_AssertNonvoid(ConfigPtr != NULL);
100         Xil_AssertNonvoid(EffectiveAddr != (u32)0);
101         /*
102          * Set some default values for instance data, don't indicate the device
103          * is ready to use until everything has been initialized successfully.
104          */
105         InstancePtr->IsReady = 0U;
106         InstancePtr->GpioConfig.BaseAddr = EffectiveAddr;
107         InstancePtr->GpioConfig.DeviceId = ConfigPtr->DeviceId;
108         InstancePtr->Handler = StubHandler;
109
110         /*
111          * By default, interrupts are not masked in GPIO. Disable
112          * interrupts for all pins in all the 4 banks.
113          */
114         XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
115                           XGPIOPS_INTDIS_OFFSET, 0xFFFFFFFFU);
116
117         XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
118                           ((u32)(1) * XGPIOPS_REG_MASK_OFFSET) +
119                           XGPIOPS_INTDIS_OFFSET, 0xFFFFFFFFU);
120
121         XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
122                           ((u32)(2) * XGPIOPS_REG_MASK_OFFSET) +
123                           XGPIOPS_INTDIS_OFFSET, 0xFFFFFFFFU);
124
125         XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
126                           ((u32)(3) * XGPIOPS_REG_MASK_OFFSET) +
127                           XGPIOPS_INTDIS_OFFSET, 0xFFFFFFFFU);
128
129         /*
130          * Indicate the component is now ready to use.
131          */
132         InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
133
134         return Status;
135 }
136
137 /****************************************************************************/
138 /**
139 *
140 * Read the Data register of the specified GPIO bank.
141 *
142 * @param        InstancePtr is a pointer to the XGpioPs instance.
143 * @param        Bank is the bank number of the GPIO to operate on.
144 *               Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
145 *
146 * @return       Current value of the Data register.
147 *
148 * @note         This function is used for reading the state of all the GPIO pins
149 *               of specified bank.
150 *
151 *****************************************************************************/
152 u32 XGpioPs_Read(XGpioPs *InstancePtr, u8 Bank)
153 {
154         Xil_AssertNonvoid(InstancePtr != NULL);
155         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
156         Xil_AssertNonvoid(Bank < XGPIOPS_MAX_BANKS);
157
158         return XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
159                                  ((u32)(Bank) * XGPIOPS_DATA_BANK_OFFSET) +
160                                  XGPIOPS_DATA_RO_OFFSET);
161 }
162
163 /****************************************************************************/
164 /**
165 *
166 * Read Data from the specified pin.
167 *
168 * @param        InstancePtr is a pointer to the XGpioPs instance.
169 * @param        Pin is the pin number for which the data has to be read.
170 *               Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
171 *               See xgpiops.h for the mapping of the pin numbers in the banks.
172 *
173 * @return       Current value of the Pin (0 or 1).
174 *
175 * @note         This function is used for reading the state of the specified
176 *               GPIO pin.
177 *
178 *****************************************************************************/
179 u32 XGpioPs_ReadPin(XGpioPs *InstancePtr, u32 Pin)
180 {
181         u8 Bank;
182         u8 PinNumber;
183
184         Xil_AssertNonvoid(InstancePtr != NULL);
185         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
186         Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
187
188         /*
189          * Get the Bank number and Pin number within the bank.
190          */
191         XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
192
193         return (XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
194                                  ((u32)(Bank) * XGPIOPS_DATA_BANK_OFFSET) +
195                                  XGPIOPS_DATA_RO_OFFSET) >> (u32)PinNumber) & (u32)1;
196
197 }
198
199 /****************************************************************************/
200 /**
201 *
202 * Write to the Data register of the specified GPIO bank.
203 *
204 * @param        InstancePtr is a pointer to the XGpioPs instance.
205 * @param        Bank is the bank number of the GPIO to operate on.
206 *               Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
207 * @param        Data is the value to be written to the Data register.
208 *
209 * @return       None.
210 *
211 * @note         This function is used for writing to all the GPIO pins of
212 *               the bank. The previous state of the pins is not maintained.
213 *
214 *****************************************************************************/
215 void XGpioPs_Write(XGpioPs *InstancePtr, u8 Bank, u32 Data)
216 {
217         Xil_AssertVoid(InstancePtr != NULL);
218         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
219         Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
220
221         XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
222                           ((u32)(Bank) * XGPIOPS_DATA_BANK_OFFSET) +
223                           XGPIOPS_DATA_OFFSET, Data);
224 }
225
226 /****************************************************************************/
227 /**
228 *
229 * Write data to the specified pin.
230 *
231 * @param        InstancePtr is a pointer to the XGpioPs instance.
232 * @param        Pin is the pin number to which the Data is to be written.
233 *               Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
234 * @param        Data is the data to be written to the specified pin (0 or 1).
235 *
236 * @return       None.
237 *
238 * @note         This function does a masked write to the specified pin of
239 *               the specified GPIO bank. The previous state of other pins
240 *               is maintained.
241 *
242 *****************************************************************************/
243 void XGpioPs_WritePin(XGpioPs *InstancePtr, u32 Pin, u32 Data)
244 {
245         u32 RegOffset;
246         u32 Value;
247         u8 Bank;
248         u8 PinNumber;
249         u32 DataVar = Data;
250
251         Xil_AssertVoid(InstancePtr != NULL);
252         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
253         Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
254
255         /*
256          * Get the Bank number and Pin number within the bank.
257          */
258         XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
259
260         if (PinNumber > 15U) {
261                 /*
262                  * There are only 16 data bits in bit maskable register.
263                  */
264                 PinNumber -= (u8)16;
265                 RegOffset = XGPIOPS_DATA_MSW_OFFSET;
266         } else {
267                 RegOffset = XGPIOPS_DATA_LSW_OFFSET;
268         }
269
270         /*
271          * Get the 32 bit value to be written to the Mask/Data register where
272          * the upper 16 bits is the mask and lower 16 bits is the data.
273          */
274         DataVar &= (u32)0x01;
275         Value = ~((u32)1 << (PinNumber + 16U)) & ((DataVar << PinNumber) | 0xFFFF0000U);
276         XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
277                           ((u32)(Bank) * XGPIOPS_DATA_MASK_OFFSET) +
278                           RegOffset, Value);
279 }
280
281
282
283 /****************************************************************************/
284 /**
285 *
286 * Set the Direction of the pins of the specified GPIO Bank.
287 *
288 * @param        InstancePtr is a pointer to the XGpioPs instance.
289 * @param        Bank is the bank number of the GPIO to operate on.
290 *               Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
291 * @param        Direction is the 32 bit mask of the Pin direction to be set for
292 *               all the pins in the Bank. Bits with 0 are set to Input mode,
293 *               bits with 1 are set to Output Mode.
294 *
295 * @return       None.
296 *
297 * @note         This function is used for setting the direction of all the pins
298 *               in the specified bank. The previous state of the pins is
299 *               not maintained.
300 *
301 *****************************************************************************/
302 void XGpioPs_SetDirection(XGpioPs *InstancePtr, u8 Bank, u32 Direction)
303 {
304         Xil_AssertVoid(InstancePtr != NULL);
305         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
306         Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
307
308         XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
309                           ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
310                           XGPIOPS_DIRM_OFFSET, Direction);
311 }
312
313 /****************************************************************************/
314 /**
315 *
316 * Set the Direction of the specified pin.
317 *
318 * @param        InstancePtr is a pointer to the XGpioPs instance.
319 * @param        Pin is the pin number to which the Data is to be written.
320 *               Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
321 * @param        Direction is the direction to be set for the specified pin.
322 *               Valid values are 0 for Input Direction, 1 for Output Direction.
323 *
324 * @return       None.
325 *
326 *****************************************************************************/
327 void XGpioPs_SetDirectionPin(XGpioPs *InstancePtr, u32 Pin, u32 Direction)
328 {
329         u8 Bank;
330         u8 PinNumber;
331         u32 DirModeReg;
332
333         Xil_AssertVoid(InstancePtr != NULL);
334         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
335         Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
336         Xil_AssertVoid(Direction <= (u32)1);
337
338         /*
339          * Get the Bank number and Pin number within the bank.
340          */
341         XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
342
343         DirModeReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
344                                       ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
345                                       XGPIOPS_DIRM_OFFSET);
346
347         if (Direction!=(u32)0) { /*  Output Direction */
348                 DirModeReg |= ((u32)1 << (u32)PinNumber);
349         } else { /* Input Direction */
350                 DirModeReg &= ~ ((u32)1 << (u32)PinNumber);
351         }
352
353         XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
354                          ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
355                          XGPIOPS_DIRM_OFFSET, DirModeReg);
356 }
357
358 /****************************************************************************/
359 /**
360 *
361 * Get the Direction of the pins of the specified GPIO Bank.
362 *
363 * @param        InstancePtr is a pointer to the XGpioPs instance.
364 * @param        Bank is the bank number of the GPIO to operate on.
365 *               Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
366 *
367 * return        Returns a 32 bit mask of the Direction register. Bits with 0 are
368 *               in Input mode, bits with 1 are in Output Mode.
369 *
370 * @note         None.
371 *
372 *****************************************************************************/
373 u32 XGpioPs_GetDirection(XGpioPs *InstancePtr, u8 Bank)
374 {
375         Xil_AssertNonvoid(InstancePtr != NULL);
376         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
377         Xil_AssertNonvoid(Bank < XGPIOPS_MAX_BANKS);
378
379         return XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
380                                 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
381                                 XGPIOPS_DIRM_OFFSET);
382 }
383
384 /****************************************************************************/
385 /**
386 *
387 * Get the Direction of the specified pin.
388 *
389 * @param        InstancePtr is a pointer to the XGpioPs instance.
390 * @param        Pin is the pin number for which the Direction is to be
391 *               retrieved.
392 *               Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
393 *
394 * @return       Direction of the specified pin.
395 *               - 0 for Input Direction
396 *               - 1 for Output Direction
397 *
398 * @note         None.
399 *
400 *****************************************************************************/
401 u32 XGpioPs_GetDirectionPin(XGpioPs *InstancePtr, u32 Pin)
402 {
403         u8 Bank;
404         u8 PinNumber;
405
406         Xil_AssertNonvoid(InstancePtr != NULL);
407         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
408         Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
409
410         /*
411          * Get the Bank number and Pin number within the bank.
412          */
413         XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
414
415         return (XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
416                                  ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
417                                  XGPIOPS_DIRM_OFFSET) >> (u32)PinNumber) & (u32)1;
418 }
419
420 /****************************************************************************/
421 /**
422 *
423 * Set the Output Enable of the pins of the specified GPIO Bank.
424 *
425 * @param        InstancePtr is a pointer to the XGpioPs instance.
426 * @param        Bank is the bank number of the GPIO to operate on.
427 *               Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
428 * @param        OpEnable is the 32 bit mask of the Output Enables to be set for
429 *               all the pins in the Bank. The Output Enable of bits with 0 are
430 *               disabled, the Output Enable of bits with 1 are enabled.
431 *
432 * @return       None.
433 *
434 * @note         This function is used for setting the Output Enables of all the
435 *               pins in the specified bank. The previous state of the Output
436 *               Enables is not maintained.
437 *
438 *****************************************************************************/
439 void XGpioPs_SetOutputEnable(XGpioPs *InstancePtr, u8 Bank, u32 OpEnable)
440 {
441         Xil_AssertVoid(InstancePtr != NULL);
442         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
443         Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
444
445         XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
446                           ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
447                           XGPIOPS_OUTEN_OFFSET, OpEnable);
448 }
449
450 /****************************************************************************/
451 /**
452 *
453 * Set the Output Enable of the specified pin.
454 *
455 * @param        InstancePtr is a pointer to the XGpioPs instance.
456 * @param        Pin is the pin number to which the Data is to be written.
457 *               Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
458 * @param        OpEnable specifies whether the Output Enable for the specified
459 *               pin should be enabled.
460 *               Valid values are 0 for Disabling Output Enable,
461 *               1 for Enabling Output Enable.
462 *
463 * @return       None.
464 *
465 * @note         None.
466 *
467 *****************************************************************************/
468 void XGpioPs_SetOutputEnablePin(XGpioPs *InstancePtr, u32 Pin, u32 OpEnable)
469 {
470         u8 Bank;
471         u8 PinNumber;
472         u32 OpEnableReg;
473
474         Xil_AssertVoid(InstancePtr != NULL);
475         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
476         Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
477         Xil_AssertVoid(OpEnable <= (u32)1);
478
479         /*
480          * Get the Bank number and Pin number within the bank.
481          */
482         XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
483
484         OpEnableReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
485                                        ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
486                                        XGPIOPS_OUTEN_OFFSET);
487
488         if (OpEnable != (u32)0) { /*  Enable Output Enable */
489                 OpEnableReg |= ((u32)1 << (u32)PinNumber);
490         } else { /* Disable Output Enable */
491                 OpEnableReg &= ~ ((u32)1 << (u32)PinNumber);
492         }
493
494         XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
495                           ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
496                           XGPIOPS_OUTEN_OFFSET, OpEnableReg);
497 }
498 /****************************************************************************/
499 /**
500 *
501 * Get the Output Enable status of the pins of the specified GPIO Bank.
502 *
503 * @param        InstancePtr is a pointer to the XGpioPs instance.
504 * @param        Bank is the bank number of the GPIO to operate on.
505 *               Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
506 *
507 * return        Returns a a 32 bit mask of the Output Enable register.
508 *               Bits with 0 are in Disabled state, bits with 1 are in
509 *               Enabled State.
510 *
511 * @note         None.
512 *
513 *****************************************************************************/
514 u32 XGpioPs_GetOutputEnable(XGpioPs *InstancePtr, u8 Bank)
515 {
516         Xil_AssertNonvoid(InstancePtr != NULL);
517         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
518         Xil_AssertNonvoid(Bank < XGPIOPS_MAX_BANKS);
519
520         return XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
521                                 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
522                                 XGPIOPS_OUTEN_OFFSET);
523 }
524
525 /****************************************************************************/
526 /**
527 *
528 * Get the Output Enable status of the specified pin.
529 *
530 * @param        InstancePtr is a pointer to the XGpioPs instance.
531 * @param        Pin is the pin number for which the Output Enable status is to
532 *               be retrieved.
533 *               Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
534 *
535 * @return       Output Enable of the specified pin.
536 *               - 0 if Output Enable is disabled for this pin
537 *               - 1 if Output Enable is enabled for this pin
538 *
539 * @note         None.
540 *
541 *****************************************************************************/
542 u32 XGpioPs_GetOutputEnablePin(XGpioPs *InstancePtr, u32 Pin)
543 {
544         u8 Bank;
545         u8 PinNumber;
546
547         Xil_AssertNonvoid(InstancePtr != NULL);
548         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
549         Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
550
551         /*
552          * Get the Bank number and Pin number within the bank.
553          */
554         XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
555
556         return (XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
557                                  ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
558                                  XGPIOPS_OUTEN_OFFSET) >> (u32)PinNumber) & (u32)1;
559 }
560
561 /****************************************************************************/
562 /*
563 *
564 * Get the Bank number and the Pin number in the Bank, for the given PinNumber
565 * in the GPIO device.
566 *
567 * @param        PinNumber is the Pin number in the GPIO device.
568 * @param        BankNumber returns the Bank in which this GPIO pin is present.
569 *               Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
570 * @param        PinNumberInBank returns the Pin Number within the Bank.
571 *
572 * @return       None.
573 *
574 * @note         None.
575 *
576 *****************************************************************************/
577 void XGpioPs_GetBankPin(u8 PinNumber, u8 *BankNumber, u8 *PinNumberInBank)
578 {
579         /*
580          * This structure defines the mapping of the pin numbers to the banks when
581          * the driver APIs are used for working on the individual pins.
582          */
583 #ifdef XPAR_PSU_GPIO_0_BASEADDR
584         u32 XGpioPsPinTable[] = {
585                                         (u32)25, /* 0 - 25, Bank 0 */
586                                         (u32)51, /* 26 - 51, Bank 1 */
587                                         (u32)77, /* 52 - 77, Bank 2 */
588                                         (u32)109, /* 78 - 109, Bank 3 */
589                                         (u32)141, /* 110 - 141, Bank 4 */
590                                         (u32)173 /* 142 - 173 Bank 5 */
591                                 };
592                         *BankNumber = 0U;
593                         while (*BankNumber < 6U) {
594                                 if (PinNumber <= XGpioPsPinTable[*BankNumber]) {
595                                         break;
596                                 }
597                                 (*BankNumber)++;
598                         }
599 #else
600         u32 XGpioPsPinTable[] = {
601                 (u32)31, /* 0 - 31, Bank 0 */
602                 (u32)53, /* 32 - 53, Bank 1 */
603                 (u32)85, /* 54 - 85, Bank 2 */
604                 (u32)117 /* 86 - 117 Bank 3 */
605         };
606         *BankNumber = 0U;
607         while (*BankNumber < 4U) {
608                 if (PinNumber <= XGpioPsPinTable[*BankNumber]) {
609                         break;
610                 }
611                 (*BankNumber)++;
612     }
613 #endif
614         if (*BankNumber == (u8)0) {
615                 *PinNumberInBank = PinNumber;
616         } else {
617                 *PinNumberInBank = (u8)((u32)PinNumber %
618                                         (XGpioPsPinTable[*BankNumber - (u8)1] + (u32)1));
619         }
620 }