gpdma_001.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * @brief GPDMA Registers and control functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __GPDMA_001_H_
  32. #define __GPDMA_001_H_
  33. #include "sys_config.h"
  34. #include "cmsis.h"
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /** @defgroup IP_GPDMA_001 IP: GPDMA register block and driver
  39. * @ingroup IP_Drivers
  40. * General Purpose DMA
  41. * @{
  42. */
  43. /**
  44. * @brief GPDMA Channel register block structure
  45. */
  46. typedef struct {
  47. __IO uint32_t SRCADDR; /*!< DMA Channel Source Address Register */
  48. __IO uint32_t DESTADDR; /*!< DMA Channel Destination Address Register */
  49. __IO uint32_t LLI; /*!< DMA Channel Linked List Item Register */
  50. __IO uint32_t CONTROL; /*!< DMA Channel Control Register */
  51. __IO uint32_t CONFIG; /*!< DMA Channel Configuration Register */
  52. __I uint32_t RESERVED1[3];
  53. } IP_GPDMA_001_CH_Type;
  54. #define GPDMA_CHANNELS 8
  55. /**
  56. * @brief GPDMA register block
  57. */
  58. typedef struct { /*!< GPDMA Structure */
  59. __I uint32_t INTSTAT; /*!< DMA Interrupt Status Register */
  60. __I uint32_t INTTCSTAT; /*!< DMA Interrupt Terminal Count Request Status Register */
  61. __O uint32_t INTTCCLEAR; /*!< DMA Interrupt Terminal Count Request Clear Register */
  62. __I uint32_t INTERRSTAT; /*!< DMA Interrupt Error Status Register */
  63. __O uint32_t INTERRCLR; /*!< DMA Interrupt Error Clear Register */
  64. __I uint32_t RAWINTTCSTAT; /*!< DMA Raw Interrupt Terminal Count Status Register */
  65. __I uint32_t RAWINTERRSTAT; /*!< DMA Raw Error Interrupt Status Register */
  66. __I uint32_t ENBLDCHNS; /*!< DMA Enabled Channel Register */
  67. __IO uint32_t SOFTBREQ; /*!< DMA Software Burst Request Register */
  68. __IO uint32_t SOFTSREQ; /*!< DMA Software Single Request Register */
  69. __IO uint32_t SOFTLBREQ; /*!< DMA Software Last Burst Request Register */
  70. __IO uint32_t SOFTLSREQ; /*!< DMA Software Last Single Request Register */
  71. __IO uint32_t CONFIG; /*!< DMA Configuration Register */
  72. __IO uint32_t SYNC; /*!< DMA Synchronization Register */
  73. __I uint32_t RESERVED0[50];
  74. IP_GPDMA_001_CH_Type CH[GPDMA_CHANNELS];
  75. } IP_GPDMA_001_Type;
  76. /**
  77. * @brief Macro defines for DMA channel control registers
  78. */
  79. #define GPDMA_DMACCxControl_TransferSize(n) (((n & 0xFFF) << 0)) /**< Transfer size*/
  80. #define GPDMA_DMACCxControl_SBSize(n) (((n & 0x07) << 12)) /**< Source burst size*/
  81. #define GPDMA_DMACCxControl_DBSize(n) (((n & 0x07) << 15)) /**< Destination burst size*/
  82. #define GPDMA_DMACCxControl_SWidth(n) (((n & 0x07) << 18)) /**< Source transfer width*/
  83. #define GPDMA_DMACCxControl_DWidth(n) (((n & 0x07) << 21)) /**< Destination transfer width*/
  84. #define GPDMA_DMACCxControl_SI ((1UL << 26)) /**< Source increment*/
  85. #define GPDMA_DMACCxControl_DI ((1UL << 27)) /**< Destination increment*/
  86. #if defined(CHIP_LPC43XX) || defined(CHIP_LPC18XX)
  87. #define GPDMA_DMACCxControl_SrcTransUseAHBMaster1 ((1UL << 24)) /**< Source AHB master select in 18xx43xx*/
  88. #define GPDMA_DMACCxControl_DestTransUseAHBMaster1 ((1UL << 25)) /**< Destination AHB master select in 18xx43xx*/
  89. #else
  90. #define GPDMA_DMACCxControl_SrcTransUseAHBMaster1 0
  91. #define GPDMA_DMACCxControl_DestTransUseAHBMaster1 0
  92. #endif
  93. #define GPDMA_DMACCxControl_Prot1 ((1UL << 28)) /**< Indicates that the access is in user mode or privileged mode*/
  94. #define GPDMA_DMACCxControl_Prot2 ((1UL << 29)) /**< Indicates that the access is bufferable or not bufferable*/
  95. #define GPDMA_DMACCxControl_Prot3 ((1UL << 30)) /**< Indicates that the access is cacheable or not cacheable*/
  96. #define GPDMA_DMACCxControl_I ((1UL << 31)) /**< Terminal count interrupt enable bit */
  97. /**
  98. * @brief Macro defines for DMA Configuration register
  99. */
  100. #define GPDMA_DMACConfig_E ((0x01)) /**< DMA Controller enable*/
  101. #define GPDMA_DMACConfig_M ((0x02)) /**< AHB Master endianness configuration*/
  102. #define GPDMA_DMACConfig_BITMASK ((0x03))
  103. /**
  104. * @brief Macro defines for DMA Channel Configuration registers
  105. */
  106. #define GPDMA_DMACCxConfig_E ((1UL << 0)) /**< DMA control enable*/
  107. #define GPDMA_DMACCxConfig_SrcPeripheral(n) (((n & 0x1F) << 1)) /**< Source peripheral*/
  108. #define GPDMA_DMACCxConfig_DestPeripheral(n) (((n & 0x1F) << 6)) /**< Destination peripheral*/
  109. #define GPDMA_DMACCxConfig_TransferType(n) (((n & 0x7) << 11)) /**< This value indicates the type of transfer*/
  110. #define GPDMA_DMACCxConfig_IE ((1UL << 14)) /**< Interrupt error mask*/
  111. #define GPDMA_DMACCxConfig_ITC ((1UL << 15)) /**< Terminal count interrupt mask*/
  112. #define GPDMA_DMACCxConfig_L ((1UL << 16)) /**< Lock*/
  113. #define GPDMA_DMACCxConfig_A ((1UL << 17)) /**< Active*/
  114. #define GPDMA_DMACCxConfig_H ((1UL << 18)) /**< Halt*/
  115. /**
  116. * @brief GPDMA Interrupt Clear Status
  117. */
  118. typedef enum {
  119. GPDMA_STATCLR_INTTC, /**< GPDMA Interrupt Terminal Count Request Clear */
  120. GPDMA_STATCLR_INTERR /**< GPDMA Interrupt Error Clear */
  121. } GPDMA_StateClear_Type;
  122. /**
  123. * @brief GPDMA Type of Interrupt Status
  124. */
  125. typedef enum {
  126. GPDMA_STAT_INT, /**< GPDMA Interrupt Status */
  127. GPDMA_STAT_INTTC, /**< GPDMA Interrupt Terminal Count Request Status */
  128. GPDMA_STAT_INTERR, /**< GPDMA Interrupt Error Status */
  129. GPDMA_STAT_RAWINTTC, /**< GPDMA Raw Interrupt Terminal Count Status */
  130. GPDMA_STAT_RAWINTERR, /**< GPDMA Raw Error Interrupt Status */
  131. GPDMA_STAT_ENABLED_CH /**< GPDMA Enabled Channel Status */
  132. } GPDMA_Status_Type;
  133. /**
  134. * @brief GPDMA Type of DMA controller
  135. */
  136. typedef enum {
  137. GPDMA_TRANSFERTYPE_M2M_CONTROLLER_DMA = ((0UL)), /**< Memory to memory - DMA control */
  138. GPDMA_TRANSFERTYPE_M2P_CONTROLLER_DMA = ((1UL)), /**< Memory to peripheral - DMA control */
  139. GPDMA_TRANSFERTYPE_P2M_CONTROLLER_DMA = ((2UL)), /**< Peripheral to memory - DMA control */
  140. GPDMA_TRANSFERTYPE_P2P_CONTROLLER_DMA = ((3UL)), /**< Source peripheral to destination peripheral - DMA control */
  141. GPDMA_TRANSFERTYPE_P2P_CONTROLLER_DestPERIPHERAL = ((4UL)), /**< Source peripheral to destination peripheral - destination peripheral control */
  142. GPDMA_TRANSFERTYPE_M2P_CONTROLLER_PERIPHERAL = ((5UL)), /**< Memory to peripheral - peripheral control */
  143. GPDMA_TRANSFERTYPE_P2M_CONTROLLER_PERIPHERAL = ((6UL)), /**< Peripheral to memory - peripheral control */
  144. GPDMA_TRANSFERTYPE_P2P_CONTROLLER_SrcPERIPHERAL = ((7UL)) /**< Source peripheral to destination peripheral - source peripheral control */
  145. } FlowControlType;
  146. /**
  147. * @brief GPDMA structure using for DMA configuration
  148. */
  149. typedef struct {
  150. uint32_t ChannelNum; /**< DMA channel number, should be in
  151. * range from 0 to 7.
  152. * Note: DMA channel 0 has the highest priority
  153. * and DMA channel 7 the lowest priority.
  154. */
  155. uint32_t TransferSize; /**< Length/Size of transfer */
  156. uint32_t TransferWidth; /**< Transfer width - used for TransferType is GPDMA_TRANSFERTYPE_M2M only */
  157. uint32_t SrcAddr; /**< Physical Source Address, used in case TransferType is chosen as
  158. * GPDMA_TRANSFERTYPE_M2M or GPDMA_TRANSFERTYPE_M2P */
  159. uint32_t DstAddr; /**< Physical Destination Address, used in case TransferType is chosen as
  160. * GPDMA_TRANSFERTYPE_M2M or GPDMA_TRANSFERTYPE_P2M */
  161. uint32_t TransferType; /**< Transfer Type, should be one of the following:
  162. * - GPDMA_TRANSFERTYPE_M2M: Memory to memory - DMA control
  163. * - GPDMA_TRANSFERTYPE_M2P: Memory to peripheral - DMA control
  164. * - GPDMA_TRANSFERTYPE_P2M: Peripheral to memory - DMA control
  165. * - GPDMA_TRANSFERTYPE_P2P: Source peripheral to destination peripheral - DMA control
  166. */
  167. } GPDMA_Channel_CFG_Type;
  168. /**
  169. * @brief Initialize the GPDMA
  170. * @param pGPDMA : The Base Address of GPDMA on the chip
  171. * @return Nothing
  172. */
  173. void IP_GPDMA_Init(IP_GPDMA_001_Type *pGPDMA);
  174. /**
  175. * @brief Set up the DPDMA according to the specification configuration details
  176. * @param pGPDMA : The Base Address of GPDMA on the chip
  177. * @param GPDMAChannelConfig : Configuration struct
  178. * @param GPDMA_LUTPerBurstSrcConn : Peripheral Source burst size
  179. * @param GPDMA_LUTPerBurstDstConn : Peripheral Destination burst size
  180. * @param GPDMA_LUTPerWidSrcConn : Peripheral Source transfer width
  181. * @param GPDMA_LUTPerWidDstConn : Peripheral Destination transfer width
  182. * @param GPDMA_LUTPerAddrSrcConn : Peripheral Source Address
  183. * @param GPDMA_LUTPerAddrDstConn : Peripheral Destination Address
  184. * @param SrcPeripheral : Peripheral Source ID
  185. * @param DstPeripheral : Peripheral Destination ID
  186. * @return SUCCESS or ERROR on setup failure
  187. */
  188. Status IP_GPDMA_Setup(IP_GPDMA_001_Type *pGPDMA,
  189. GPDMA_Channel_CFG_Type *GPDMAChannelConfig,
  190. uint32_t GPDMA_LUTPerBurstSrcConn,
  191. uint32_t GPDMA_LUTPerBurstDstConn,
  192. uint32_t GPDMA_LUTPerWidSrcConn,
  193. uint32_t GPDMA_LUTPerWidDstConn,
  194. uint32_t GPDMA_LUTPerAddrSrcConn,
  195. uint32_t GPDMA_LUTPerAddrDstConn,
  196. uint8_t SrcPeripheral,
  197. uint8_t DstPeripheral);
  198. /**
  199. * @brief Read the status from different registers according to the type
  200. * @param pGPDMA : The Base Address of GPDMA on the chip
  201. * @param type : Status mode, should be:
  202. * - GPDMA_STAT_INT : GPDMA Interrupt Status
  203. * - GPDMA_STAT_INTTC : GPDMA Interrupt Terminal Count Request Status
  204. * - GPDMA_STAT_INTERR : GPDMA Interrupt Error Status
  205. * - GPDMA_STAT_RAWINTTC : GPDMA Raw Interrupt Terminal Count Status
  206. * - GPDMA_STAT_RAWINTERR : GPDMA Raw Error Interrupt Status
  207. * - GPDMA_STAT_ENABLED_CH : GPDMA Enabled Channel Status
  208. * @param channel : The GPDMA channel : 0 - 7
  209. * @return SET is interrupt is pending or RESET if not pending
  210. */
  211. IntStatus IP_GPDMA_IntGetStatus(IP_GPDMA_001_Type *pGPDMA, GPDMA_Status_Type type, uint8_t channel);
  212. /**
  213. * @brief Clear the Interrupt Flag from different registers according to the type
  214. * @param pGPDMA : The Base Address of GPDMA on the chip
  215. * @param type : Flag mode, should be:
  216. * - GPDMA_STATCLR_INTTC : GPDMA Interrupt Terminal Count Request
  217. * - GPDMA_STATCLR_INTERR : GPDMA Interrupt Error
  218. * @param channel : The GPDMA channel : 0 - 7
  219. * @return Nothing
  220. */
  221. void IP_GPDMA_ClearIntPending(IP_GPDMA_001_Type *pGPDMA, GPDMA_StateClear_Type type, uint8_t channel);
  222. /**
  223. * @brief Enable or Disable the GPDMA Channel
  224. * @param pGPDMA : The Base Address of GPDMA on the chip
  225. * @param channelNum : The GPDMA channel : 0 - 7
  226. * @param NewState : ENABLE to enable GPDMA or DISABLE to disable GPDMA
  227. * @return Nothing
  228. */
  229. void IP_GPDMA_ChannelCmd(IP_GPDMA_001_Type *pGPDMA, uint8_t channelNum, FunctionalState NewState);
  230. /**
  231. * @}
  232. */
  233. #ifdef __cplusplus
  234. }
  235. #endif
  236. #endif /* __GPDMA_001_H_ */