xgpiops.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /******************************************************************************
  2. * Copyright (C) 2010 - 2020 Xilinx, Inc. All rights reserved.
  3. * SPDX-License-Identifier: MIT
  4. ******************************************************************************/
  5. /*****************************************************************************/
  6. /**
  7. *
  8. * @file xgpiops.h
  9. * @addtogroup gpiops_v3_7
  10. * @{
  11. * @details
  12. *
  13. * The Xilinx PS GPIO driver. This driver supports the Xilinx PS GPIO
  14. * Controller.
  15. *
  16. * The GPIO Controller supports the following features:
  17. * - 4 banks
  18. * - Masked writes (There are no masked reads)
  19. * - Bypass mode
  20. * - Configurable Interrupts (Level/Edge)
  21. *
  22. * This driver is intended to be RTOS and processor independent. Any needs for
  23. * dynamic memory management, threads or thread mutual exclusion, virtual
  24. * memory, or cache control must be satisfied by the layer above this driver.
  25. * This driver supports all the features listed above, if applicable.
  26. *
  27. * <b>Driver Description</b>
  28. *
  29. * The device driver enables higher layer software (e.g., an application) to
  30. * communicate to the GPIO.
  31. *
  32. * <b>Interrupts</b>
  33. *
  34. * The driver provides interrupt management functions and an interrupt handler.
  35. * Users of this driver need to provide callback functions. An interrupt handler
  36. * example is available with the driver.
  37. *
  38. * <b>Threads</b>
  39. *
  40. * This driver is not thread safe. Any needs for threads or thread mutual
  41. * exclusion must be satisfied by the layer above this driver.
  42. *
  43. * <b>Asserts</b>
  44. *
  45. * Asserts are used within all Xilinx drivers to enforce constraints on argument
  46. * values. Asserts can be turned off on a system-wide basis by defining, at
  47. * compile time, the NDEBUG identifier. By default, asserts are turned on and it
  48. * is recommended that users leave asserts on during development.
  49. *
  50. * <b>Building the driver</b>
  51. *
  52. * The XGpioPs driver is composed of several source files. This allows the user
  53. * to build and link only those parts of the driver that are necessary.
  54. * <br><br>
  55. *
  56. * <pre>
  57. * MODIFICATION HISTORY:
  58. *
  59. * Ver Who Date Changes
  60. * ----- ---- -------- -----------------------------------------------
  61. * 1.00a sv 01/15/10 First Release
  62. * 1.01a sv 04/15/12 Removed the APIs XGpioPs_SetMode, XGpioPs_SetModePin
  63. * XGpioPs_GetMode, XGpioPs_GetModePin as they are not
  64. * relevant to Zynq device.The interrupts are disabled
  65. * for output pins on all banks during initialization.
  66. * 1.02a hk 08/22/13 Added low level reset API
  67. * 2.1 hk 04/29/14 Use Input data register DATA_RO for read. CR# 771667.
  68. * 2.2 sk 10/13/14 Used Pin number in Bank instead of pin number
  69. * passed to APIs. CR# 822636
  70. * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
  71. * 3.1 kvn 04/13/15 Add support for Zynq Ultrascale+ MP. CR# 856980.
  72. * ms 03/17/17 Added readme.txt file in examples folder for doxygen
  73. * generation.
  74. * ms 04/05/17 Added tabspace for return statements in functions of
  75. * gpiops examples for proper documentation while
  76. * generating doxygen.
  77. * 3.3 ms 04/17/17 Added notes about gpio input and output pin description
  78. * for zcu102 and zc702 boards in polled and interrupt
  79. * example, configured Interrupt pin to input pin for
  80. * proper functioning of interrupt example.
  81. * 3.4 aru 08/17/18 Resolved MISRA-C mandatory violations. CR# 1007751
  82. * 3.5 sne 03/01/19 Fixes violations according to MISRAC-2012
  83. * in safety mode and modified the code such as
  84. * Use of mixed mode arithmetic,Declared the pointer param
  85. * as Pointer to const,Casting operation to a pointer,
  86. * Literal value requires a U suffix.
  87. * 3.5 sne 03/14/19 Added Versal support.
  88. * 3.6 mus 04/05/19 Replaced XPLAT_versal macro with XPLAT_VERSAL, to be in
  89. * sync with standalone BSP
  90. * 3.6 sne 06/12/19 Fixed IAR compiler warning.
  91. * 3.6 sne 08/14/19 Added interrupt handler support on versal.
  92. * 3.7 sne 12/04/19 Reverted versal examples support.
  93. *
  94. * </pre>
  95. *
  96. ******************************************************************************/
  97. #ifndef XGPIOPS_H /* prevent circular inclusions */
  98. #define XGPIOPS_H /* by using protection macros */
  99. #ifdef __cplusplus
  100. extern "C" {
  101. #endif
  102. /***************************** Include Files *********************************/
  103. #include "xstatus.h"
  104. #include "xgpiops_hw.h"
  105. #include "xplatform_info.h"
  106. /************************** Constant Definitions *****************************/
  107. /** @name Interrupt types
  108. * @{
  109. * The following constants define the interrupt types that can be set for each
  110. * GPIO pin.
  111. */
  112. #define XGPIOPS_IRQ_TYPE_EDGE_RISING 0x00U /**< Interrupt on Rising edge */
  113. #define XGPIOPS_IRQ_TYPE_EDGE_FALLING 0x01U /**< Interrupt Falling edge */
  114. #define XGPIOPS_IRQ_TYPE_EDGE_BOTH 0x02U /**< Interrupt on both edges */
  115. #define XGPIOPS_IRQ_TYPE_LEVEL_HIGH 0x03U /**< Interrupt on high level */
  116. #define XGPIOPS_IRQ_TYPE_LEVEL_LOW 0x04U /**< Interrupt on low level */
  117. /*@}*/
  118. #define XGPIOPS_BANK_MAX_PINS (u32)32 /**< Max pins in a GPIO bank */
  119. #define XGPIOPS_BANK0 0x00U /**< GPIO Bank 0 */
  120. #define XGPIOPS_BANK1 0x01U /**< GPIO Bank 1 */
  121. #define XGPIOPS_BANK2 0x02U /**< GPIO Bank 2 */
  122. #define XGPIOPS_BANK3 0x03U /**< GPIO Bank 3 */
  123. #ifdef XPAR_PSU_GPIO_0_BASEADDR
  124. #define XGPIOPS_BANK4 0x04U /**< GPIO Bank 4 */
  125. #define XGPIOPS_BANK5 0x05U /**< GPIO Bank 5 */
  126. #endif
  127. #define XGPIOPS_MAX_BANKS_ZYNQMP 0x06U /**< Max banks in a
  128. * Zynq Ultrascale+ MP GPIO device
  129. */
  130. #define XGPIOPS_MAX_BANKS 0x04U /**< Max banks in a Zynq GPIO device */
  131. #define XGPIOPS_DEVICE_MAX_PIN_NUM_ZYNQMP (u32)174 /**< Max pins in the
  132. * Zynq Ultrascale+ MP GPIO device
  133. * 0 - 25, Bank 0
  134. * 26 - 51, Bank 1
  135. * 52 - 77, Bank 2
  136. * 78 - 109, Bank 3
  137. * 110 - 141, Bank 4
  138. * 142 - 173, Bank 5
  139. */
  140. #define XGPIOPS_DEVICE_MAX_PIN_NUM (u32)118 /**< Max pins in the Zynq GPIO device
  141. * 0 - 31, Bank 0
  142. * 32 - 53, Bank 1
  143. * 54 - 85, Bank 2
  144. * 86 - 117, Bank 3
  145. */
  146. /**************************** Type Definitions *******************************/
  147. /****************************************************************************/
  148. /**
  149. * This handler data type allows the user to define a callback function to
  150. * handle the interrupts for the GPIO device. The application using this
  151. * driver is expected to define a handler of this type, to support interrupt
  152. * driven mode. The handler executes in an interrupt context such that minimal
  153. * processing should be performed.
  154. *
  155. * @param CallBackRef is a callback reference passed in by the upper layer
  156. * when setting the callback functions for a GPIO bank. It is
  157. * passed back to the upper layer when the callback is invoked. Its
  158. * type is not important to the driver component, so it is a void
  159. * pointer.
  160. * @param Bank is the bank for which the interrupt status has changed.
  161. * @param Status is the Interrupt status of the GPIO bank.
  162. *
  163. *****************************************************************************/
  164. typedef void (*XGpioPs_Handler) (void *CallBackRef, u32 Bank, u32 Status);
  165. /**
  166. * This typedef contains configuration information for a device.
  167. */
  168. typedef struct {
  169. u16 DeviceId; /**< Unique ID of device */
  170. u32 BaseAddr; /**< Register base address */
  171. } XGpioPs_Config;
  172. /**
  173. * The XGpioPs driver instance data. The user is required to allocate a
  174. * variable of this type for the GPIO device in the system. A pointer
  175. * to a variable of this type is then passed to the driver API functions.
  176. */
  177. typedef struct {
  178. XGpioPs_Config GpioConfig; /**< Device configuration */
  179. u32 IsReady; /**< Device is initialized and ready */
  180. XGpioPs_Handler Handler; /**< Status handlers for all banks */
  181. void *CallBackRef; /**< Callback ref for bank handlers */
  182. u32 Platform; /**< Platform data */
  183. u32 MaxPinNum; /**< Max pins in the GPIO device */
  184. u8 MaxBanks; /**< Max banks in a GPIO device */
  185. u32 PmcGpio; /**< Flag for accessing PS GPIO for versal*/
  186. } XGpioPs;
  187. /***************** Macros (Inline Functions) Definitions *********************/
  188. /************************** Function Prototypes ******************************/
  189. /* Functions in xgpiops.c */
  190. s32 XGpioPs_CfgInitialize(XGpioPs *InstancePtr, const XGpioPs_Config *ConfigPtr,
  191. u32 EffectiveAddr);
  192. /* Bank APIs in xgpiops.c */
  193. u32 XGpioPs_Read(const XGpioPs *InstancePtr, u8 Bank);
  194. void XGpioPs_Write(const XGpioPs *InstancePtr, u8 Bank, u32 Data);
  195. void XGpioPs_SetDirection(const XGpioPs *InstancePtr, u8 Bank, u32 Direction);
  196. u32 XGpioPs_GetDirection(const XGpioPs *InstancePtr, u8 Bank);
  197. void XGpioPs_SetOutputEnable(const XGpioPs *InstancePtr, u8 Bank, u32 OpEnable);
  198. u32 XGpioPs_GetOutputEnable(const XGpioPs *InstancePtr, u8 Bank);
  199. #ifdef versal
  200. void XGpioPs_GetBankPin(const XGpioPs *InstancePtr,u8 PinNumber,u8 *BankNumber, u8 *PinNumberInBank);
  201. #else
  202. void XGpioPs_GetBankPin(u8 PinNumber,u8 *BankNumber, u8 *PinNumberInBank);
  203. #endif
  204. /* Pin APIs in xgpiops.c */
  205. u32 XGpioPs_ReadPin(const XGpioPs *InstancePtr, u32 Pin);
  206. void XGpioPs_WritePin(const XGpioPs *InstancePtr, u32 Pin, u32 Data);
  207. void XGpioPs_SetDirectionPin(const XGpioPs *InstancePtr, u32 Pin, u32 Direction);
  208. u32 XGpioPs_GetDirectionPin(const XGpioPs *InstancePtr, u32 Pin);
  209. void XGpioPs_SetOutputEnablePin(const XGpioPs *InstancePtr, u32 Pin, u32 OpEnable);
  210. u32 XGpioPs_GetOutputEnablePin(const XGpioPs *InstancePtr, u32 Pin);
  211. /* Diagnostic functions in xgpiops_selftest.c */
  212. s32 XGpioPs_SelfTest(const XGpioPs *InstancePtr);
  213. /* Functions in xgpiops_intr.c */
  214. /* Bank APIs in xgpiops_intr.c */
  215. void XGpioPs_IntrEnable(const XGpioPs *InstancePtr, u8 Bank, u32 Mask);
  216. void XGpioPs_IntrDisable(const XGpioPs *InstancePtr, u8 Bank, u32 Mask);
  217. u32 XGpioPs_IntrGetEnabled(const XGpioPs *InstancePtr, u8 Bank);
  218. u32 XGpioPs_IntrGetStatus(const XGpioPs *InstancePtr, u8 Bank);
  219. void XGpioPs_IntrClear(const XGpioPs *InstancePtr, u8 Bank, u32 Mask);
  220. void XGpioPs_SetIntrType(const XGpioPs *InstancePtr, u8 Bank, u32 IntrType,
  221. u32 IntrPolarity, u32 IntrOnAny);
  222. void XGpioPs_GetIntrType(const XGpioPs *InstancePtr, u8 Bank, u32 *IntrType,
  223. u32 *IntrPolarity, u32 *IntrOnAny);
  224. void XGpioPs_SetCallbackHandler(XGpioPs *InstancePtr, void *CallBackRef,
  225. XGpioPs_Handler FuncPointer);
  226. void XGpioPs_IntrHandler(const XGpioPs *InstancePtr);
  227. /* Pin APIs in xgpiops_intr.c */
  228. void XGpioPs_SetIntrTypePin(const XGpioPs *InstancePtr, u32 Pin, u8 IrqType);
  229. u8 XGpioPs_GetIntrTypePin(const XGpioPs *InstancePtr, u32 Pin);
  230. void XGpioPs_IntrEnablePin(const XGpioPs *InstancePtr, u32 Pin);
  231. void XGpioPs_IntrDisablePin(const XGpioPs *InstancePtr, u32 Pin);
  232. u32 XGpioPs_IntrGetEnabledPin(const XGpioPs *InstancePtr, u32 Pin);
  233. u32 XGpioPs_IntrGetStatusPin(const XGpioPs *InstancePtr, u32 Pin);
  234. void XGpioPs_IntrClearPin(const XGpioPs *InstancePtr, u32 Pin);
  235. /* Functions in xgpiops_sinit.c */
  236. XGpioPs_Config *XGpioPs_LookupConfig(u16 DeviceId);
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240. #endif /* end of protection macro */
  241. /** @} */