nu_pdma.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /**************************************************************************//**
  2. * @file nu_pdma.h
  3. * @version V1.00
  4. * @brief M031 series PDMA driver header file
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #ifndef __NU_PDMA_H__
  10. #define __NU_PDMA_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /** @addtogroup Standard_Driver Standard Driver
  16. @{
  17. */
  18. /** @addtogroup PDMA_Driver PDMA Driver
  19. @{
  20. */
  21. /** @addtogroup PDMA_EXPORTED_CONSTANTS PDMA Exported Constants
  22. @{
  23. */
  24. #define PDMA_CH_MAX 9UL /*!< Specify Maximum Channels of PDMA \hideinitializer */
  25. /*---------------------------------------------------------------------------------------------------------*/
  26. /* Operation Mode Constant Definitions */
  27. /*---------------------------------------------------------------------------------------------------------*/
  28. #define PDMA_OP_STOP 0x00000000UL /*!<DMA Stop Mode \hideinitializer */
  29. #define PDMA_OP_BASIC 0x00000001UL /*!<DMA Basic Mode \hideinitializer */
  30. #define PDMA_OP_SCATTER 0x00000002UL /*!<DMA Scatter-gather Mode \hideinitializer */
  31. /*---------------------------------------------------------------------------------------------------------*/
  32. /* Data Width Constant Definitions */
  33. /*---------------------------------------------------------------------------------------------------------*/
  34. #define PDMA_WIDTH_8 0x00000000UL /*!<DMA Transfer Width 8-bit \hideinitializer */
  35. #define PDMA_WIDTH_16 0x00001000UL /*!<DMA Transfer Width 16-bit \hideinitializer */
  36. #define PDMA_WIDTH_32 0x00002000UL /*!<DMA Transfer Width 32-bit \hideinitializer */
  37. /*---------------------------------------------------------------------------------------------------------*/
  38. /* Address Attribute Constant Definitions */
  39. /*---------------------------------------------------------------------------------------------------------*/
  40. #define PDMA_SAR_INC 0x00000000UL /*!<DMA SAR increment \hideinitializer */
  41. #define PDMA_SAR_FIX 0x00000300UL /*!<DMA SAR fix address \hideinitializer */
  42. #define PDMA_DAR_INC 0x00000000UL /*!<DMA DAR increment \hideinitializer */
  43. #define PDMA_DAR_FIX 0x00000C00UL /*!<DMA DAR fix address \hideinitializer */
  44. /*---------------------------------------------------------------------------------------------------------*/
  45. /* Burst Mode Constant Definitions */
  46. /*---------------------------------------------------------------------------------------------------------*/
  47. #define PDMA_REQ_SINGLE 0x00000004UL /*!<DMA Single Request \hideinitializer */
  48. #define PDMA_REQ_BURST 0x00000000UL /*!<DMA Burst Request \hideinitializer */
  49. #define PDMA_BURST_128 0x00000000UL /*!<DMA Burst 128 Transfers \hideinitializer */
  50. #define PDMA_BURST_64 0x00000010UL /*!<DMA Burst 64 Transfers \hideinitializer */
  51. #define PDMA_BURST_32 0x00000020UL /*!<DMA Burst 32 Transfers \hideinitializer */
  52. #define PDMA_BURST_16 0x00000030UL /*!<DMA Burst 16 Transfers \hideinitializer */
  53. #define PDMA_BURST_8 0x00000040UL /*!<DMA Burst 8 Transfers \hideinitializer */
  54. #define PDMA_BURST_4 0x00000050UL /*!<DMA Burst 4 Transfers \hideinitializer */
  55. #define PDMA_BURST_2 0x00000060UL /*!<DMA Burst 2 Transfers \hideinitializer */
  56. #define PDMA_BURST_1 0x00000070UL /*!<DMA Burst 1 Transfers \hideinitializer */
  57. /*---------------------------------------------------------------------------------------------------------*/
  58. /* Table Interrupt Disable Constant Definitions */
  59. /*---------------------------------------------------------------------------------------------------------*/
  60. #define PDMA_TBINTDIS_ENABLE (0x0UL<<PDMA_DSCT_CTL_TBINTDIS_Pos) /*!<DMA Table Interrupt Enabled \hideinitializer */
  61. #define PDMA_TBINTDIS_DISABLE (0x1UL<<PDMA_DSCT_CTL_TBINTDIS_Pos) /*!<DMA Table Interrupt Disabled \hideinitializer */
  62. /*---------------------------------------------------------------------------------------------------------*/
  63. /* Peripheral Transfer Mode Constant Definitions */
  64. /*---------------------------------------------------------------------------------------------------------*/
  65. #define PDMA_MEM 0UL /*!<DMA Connect to Memory \hideinitializer */
  66. #define PDMA_UART0_TX 4UL /*!<DMA Connect to UART0_TX \hideinitializer */
  67. #define PDMA_UART0_RX 5UL /*!<DMA Connect to UART0_RX \hideinitializer */
  68. #define PDMA_UART1_TX 6UL /*!<DMA Connect to UART1_TX \hideinitializer */
  69. #define PDMA_UART1_RX 7UL /*!<DMA Connect to UART1_RX \hideinitializer */
  70. #define PDMA_UART2_TX 8UL /*!<DMA Connect to UART2_TX \hideinitializer */
  71. #define PDMA_UART2_RX 9UL /*!<DMA Connect to UART2_RX \hideinitializer */
  72. #define PDMA_USCI0_TX 10UL /*!<DMA Connect to USCI0_TX \hideinitializer */
  73. #define PDMA_USCI0_RX 11UL /*!<DMA Connect to USCI0_RX \hideinitializer */
  74. #define PDMA_USCI1_TX 12UL /*!<DMA Connect to USCI1_TX \hideinitializer */
  75. #define PDMA_USCI1_RX 13UL /*!<DMA Connect to USCI1_RX \hideinitializer */
  76. #define PDMA_QSPI0_TX 16UL /*!<DMA Connect to QSPI0_TX \hideinitializer */
  77. #define PDMA_QSPI0_RX 17UL /*!<DMA Connect to QSPI0_RX \hideinitializer */
  78. #define PDMA_SPI0_TX 18UL /*!<DMA Connect to SPI0_TX \hideinitializer */
  79. #define PDMA_SPI0_RX 19UL /*!<DMA Connect to SPI0_RX \hideinitializer */
  80. #define PDMA_ADC_RX 20UL /*!<DMA Connect to ADC_RX \hideinitializer */
  81. #define PDMA_PWM0_P1_RX 21UL /*!<DMA Connect to PWM0_P1 \hideinitializer */
  82. #define PDMA_PWM0_P2_RX 22UL /*!<DMA Connect to PWM0_P2 \hideinitializer */
  83. #define PDMA_PWM0_P3_RX 23UL /*!<DMA Connect to PWM0_P3 \hideinitializer */
  84. #define PDMA_PWM1_P1_RX 24UL /*!<DMA Connect to PWM1_P1 \hideinitializer */
  85. #define PDMA_PWM1_P2_RX 25UL /*!<DMA Connect to PWM1_P2 \hideinitializer */
  86. #define PDMA_PWM1_P3_RX 26UL /*!<DMA Connect to PWM1_P3 \hideinitializer */
  87. #define PDMA_I2C0_TX 28UL /*!<DMA Connect to I2C0_TX \hideinitializer */
  88. #define PDMA_I2C0_RX 29UL /*!<DMA Connect to I2C0_RX \hideinitializer */
  89. #define PDMA_I2C1_TX 30UL /*!<DMA Connect to I2C1_TX \hideinitializer */
  90. #define PDMA_I2C1_RX 31UL /*!<DMA Connect to I2C1_RX \hideinitializer */
  91. #define PDMA_TMR0 32UL /*!<DMA Connect to TMR0 \hideinitializer */
  92. #define PDMA_TMR1 33UL /*!<DMA Connect to TMR1 \hideinitializer */
  93. #define PDMA_TMR2 34UL /*!<DMA Connect to TMR2 \hideinitializer */
  94. #define PDMA_TMR3 35UL /*!<DMA Connect to TMR3 \hideinitializer */
  95. #define PDMA_UART3_TX 36UL /*!<DMA Connect to UART3_TX \hideinitializer */
  96. #define PDMA_UART3_RX 37UL /*!<DMA Connect to UART3_RX \hideinitializer */
  97. #define PDMA_UART4_TX 38UL /*!<DMA Connect to UART4_TX \hideinitializer */
  98. #define PDMA_UART4_RX 39UL /*!<DMA Connect to UART4_RX \hideinitializer */
  99. #define PDMA_UART5_TX 40UL /*!<DMA Connect to UART5_TX \hideinitializer */
  100. #define PDMA_UART5_RX 41UL /*!<DMA Connect to UART5_RX \hideinitializer */
  101. #define PDMA_UART6_TX 42UL /*!<DMA Connect to UART6_TX \hideinitializer */
  102. #define PDMA_UART6_RX 43UL /*!<DMA Connect to UART6_RX \hideinitializer */
  103. #define PDMA_UART7_TX 44UL /*!<DMA Connect to UART7_TX \hideinitializer */
  104. #define PDMA_UART7_RX 45UL /*!<DMA Connect to UART7_RX \hideinitializer */
  105. /*---------------------------------------------------------------------------------------------------------*/
  106. /* Interrupt Type Constant Definitions */
  107. /*---------------------------------------------------------------------------------------------------------*/
  108. #define PDMA_INT_TRANS_DONE 0x00000000UL /*!<Transfer Done Interrupt \hideinitializer */
  109. #define PDMA_INT_TEMPTY 0x00000001UL /*!<Table Empty Interrupt \hideinitializer */
  110. #define PDMA_INT_TIMEOUT 0x00000002UL /*!<Timeout Interrupt \hideinitializer */
  111. /*@}*/ /* end of group PDMA_EXPORTED_CONSTANTS */
  112. /** @addtogroup PDMA_EXPORTED_FUNCTIONS PDMA Exported Functions
  113. @{
  114. */
  115. /**
  116. * @brief Get PDMA Interrupt Status
  117. *
  118. * @param[in] pdma The pointer of the specified PDMA module
  119. *
  120. * @return None
  121. *
  122. * @details This macro gets the interrupt status.
  123. * \hideinitializer
  124. */
  125. #define PDMA_GET_INT_STATUS(pdma) ((uint32_t)((pdma)->INTSTS))
  126. /**
  127. * @brief Get Transfer Done Interrupt Status
  128. *
  129. * @param[in] pdma The pointer of the specified PDMA module
  130. *
  131. * @return None
  132. *
  133. * @details Get the transfer done Interrupt status.
  134. * \hideinitializer
  135. */
  136. #define PDMA_GET_TD_STS(pdma) ((uint32_t)((pdma)->TDSTS))
  137. /**
  138. * @brief Clear Transfer Done Interrupt Status
  139. *
  140. * @param[in] pdma The pointer of the specified PDMA module
  141. * @param[in] u32Mask The channel mask
  142. *
  143. * @return None
  144. *
  145. * @details Clear the transfer done Interrupt status.
  146. * \hideinitializer
  147. */
  148. #define PDMA_CLR_TD_FLAG(pdma, u32Mask) ((uint32_t)((pdma)->TDSTS = (u32Mask)))
  149. /**
  150. * @brief Get Target Abort Interrupt Status
  151. *
  152. * @param[in] pdma The pointer of the specified PDMA module
  153. *
  154. * @return None
  155. *
  156. * @details Get the target abort Interrupt status.
  157. * \hideinitializer
  158. */
  159. #define PDMA_GET_ABORT_STS(pdma) ((uint32_t)((pdma)->ABTSTS))
  160. /**
  161. * @brief Clear Target Abort Interrupt Status
  162. *
  163. * @param[in] pdma The pointer of the specified PDMA module
  164. * @param[in] u32Mask The channel mask
  165. *
  166. * @return None
  167. *
  168. * @details Clear the target abort Interrupt status.
  169. * \hideinitializer
  170. */
  171. #define PDMA_CLR_ABORT_FLAG(pdma, u32Mask) ((uint32_t)((pdma)->ABTSTS = (u32Mask)))
  172. /**
  173. * @brief Get Alignment Interrupt Status
  174. *
  175. * @param[in] pdma The pointer of the specified PDMA module
  176. *
  177. * @return None
  178. *
  179. * @details Get Alignment Interrupt status.
  180. * \hideinitializer
  181. */
  182. #define PDMA_GET_ALIGN_STS(pdma) ((uint32_t)((pdma)->ALIGN))
  183. /**
  184. * @brief Clear Alignment Interrupt Status
  185. *
  186. * @param[in] pdma The pointer of the specified PDMA module
  187. * @param[in] u32Mask The channel mask
  188. *
  189. * @return None
  190. *
  191. * @details Clear the Alignment Interrupt status.
  192. * \hideinitializer
  193. */
  194. #define PDMA_CLR_ALIGN_FLAG(pdma,u32Mask) ((uint32_t)((pdma)->ALIGN = (u32Mask)))
  195. /**
  196. * @brief Clear Timeout Interrupt Status
  197. *
  198. * @param[in] pdma The pointer of the specified PDMA module
  199. * @param[in] u32Ch The selected channel
  200. *
  201. * @return None
  202. *
  203. * @details Clear the selected channel timeout interrupt status.
  204. * \hideinitializer
  205. */
  206. #define PDMA_CLR_TMOUT_FLAG(pdma, u32Ch) ((uint32_t)((pdma)->INTSTS = (1UL << ((u32Ch) + 8UL))))
  207. /**
  208. * @brief Check Channel Status
  209. *
  210. * @param[in] pdma The pointer of the specified PDMA module
  211. * @param[in] u32Ch The selected channel
  212. *
  213. * @retval 0 Idle state
  214. * @retval 1 Busy state
  215. *
  216. * @details Check the selected channel is busy or not.
  217. * \hideinitializer
  218. */
  219. #define PDMA_IS_CH_BUSY(pdma, u32Ch) ((uint32_t)((pdma)->TRGSTS & (1UL << (u32Ch)))? 1 : 0)
  220. /**
  221. * @brief Set Source Address
  222. *
  223. * @param[in] pdma The pointer of the specified PDMA module
  224. * @param[in] u32Ch The selected channel
  225. * @param[in] u32Addr The selected address
  226. *
  227. * @return None
  228. *
  229. * @details This macro set the selected channel source address.
  230. * \hideinitializer
  231. */
  232. #define PDMA_SET_SRC_ADDR(pdma, u32Ch, u32Addr) ((uint32_t)((pdma)->DSCT[(u32Ch)].SA = (u32Addr)))
  233. /**
  234. * @brief Set Destination Address
  235. *
  236. * @param[in] pdma The pointer of the specified PDMA module
  237. * @param[in] u32Ch The selected channel
  238. * @param[in] u32Addr The selected address
  239. *
  240. * @return None
  241. *
  242. * @details This macro set the selected channel destination address.
  243. * \hideinitializer
  244. */
  245. #define PDMA_SET_DST_ADDR(pdma, u32Ch, u32Addr) ((uint32_t)((pdma)->DSCT[(u32Ch)].DA = (u32Addr)))
  246. /**
  247. * @brief Set Transfer Count
  248. *
  249. * @param[in] pdma The pointer of the specified PDMA module
  250. * @param[in] u32Ch The selected channel
  251. * @param[in] u32TransCount Transfer Count
  252. *
  253. * @return None
  254. *
  255. * @details This macro set the selected channel transfer count.
  256. * \hideinitializer
  257. */
  258. #define PDMA_SET_TRANS_CNT(pdma, u32Ch, u32TransCount) ((uint32_t)((pdma)->DSCT[(u32Ch)].CTL=((pdma)->DSCT[(u32Ch)].CTL&~PDMA_DSCT_CTL_TXCNT_Msk)|(((u32TransCount)-1UL) << PDMA_DSCT_CTL_TXCNT_Pos)))
  259. /**
  260. * @brief Set Scatter-gather descriptor Address
  261. *
  262. * @param[in] pdma The pointer of the specified PDMA module
  263. * @param[in] u32Ch The selected channel
  264. * @param[in] u32Addr The descriptor address
  265. *
  266. * @return None
  267. *
  268. * @details This macro set the selected channel scatter-gather descriptor address.
  269. * \hideinitializer
  270. */
  271. #define PDMA_SET_SCATTER_DESC(pdma, u32Ch, u32Addr) ((uint32_t)((pdma)->DSCT[(u32Ch)].NEXT = (u32Addr) - ((pdma)->SCATBA)))
  272. /**
  273. * @brief Stop the channel
  274. *
  275. * @param[in] pdma The pointer of the specified PDMA module
  276. * @param[in] u32Ch The selected channel
  277. *
  278. * @return None
  279. *
  280. * @details This macro stop the selected channel.
  281. * \hideinitializer
  282. */
  283. #define PDMA_STOP(pdma, u32Ch) ((uint32_t)((pdma)->PAUSE = (1UL << (u32Ch))))
  284. /**
  285. * @brief Pause the channel
  286. *
  287. * @param[in] pdma The pointer of the specified PDMA module
  288. * @param[in] u32Ch The selected channel
  289. *
  290. * @return None
  291. *
  292. * @details This macro pause the selected channel.
  293. * \hideinitializer
  294. */
  295. #define PDMA_PAUSE(pdma, u32Ch) ((uint32_t)((pdma)->PAUSE = (1UL << (u32Ch))))
  296. /*---------------------------------------------------------------------------------------------------------*/
  297. /* Define PDMA functions prototype */
  298. /*---------------------------------------------------------------------------------------------------------*/
  299. void PDMA_Open(PDMA_T *pdma, uint32_t u32Mask);
  300. void PDMA_Close(PDMA_T *pdma);
  301. void PDMA_SetTransferCnt(PDMA_T *pdma, uint32_t u32Ch, uint32_t u32Width, uint32_t u32TransCount);
  302. void PDMA_SetTransferAddr(PDMA_T *pdma, uint32_t u32Ch, uint32_t u32SrcAddr, uint32_t u32SrcCtrl, uint32_t u32DstAddr, uint32_t u32DstCtrl);
  303. void PDMA_SetTransferMode(PDMA_T *pdma, uint32_t u32Ch, uint32_t u32Peripheral, uint32_t u32ScatterEn, uint32_t u32DescAddr);
  304. void PDMA_SetBurstType(PDMA_T *pdma, uint32_t u32Ch, uint32_t u32BurstType, uint32_t u32BurstSize);
  305. void PDMA_EnableTimeout(PDMA_T *pdma, uint32_t u32Mask);
  306. void PDMA_DisableTimeout(PDMA_T *pdma, uint32_t u32Mask);
  307. void PDMA_SetTimeOut(PDMA_T *pdma, uint32_t u32Ch, uint32_t u32OnOff, uint32_t u32TimeOutCnt);
  308. void PDMA_Trigger(PDMA_T *pdma, uint32_t u32Ch);
  309. void PDMA_EnableInt(PDMA_T *pdma, uint32_t u32Ch, uint32_t u32Mask);
  310. void PDMA_DisableInt(PDMA_T *pdma, uint32_t u32Ch, uint32_t u32Mask);
  311. /*@}*/ /* end of group PDMA_EXPORTED_FUNCTIONS */
  312. /*@}*/ /* end of group PDMA_Driver */
  313. /*@}*/ /* end of group Standard_Driver */
  314. #ifdef __cplusplus
  315. }
  316. #endif
  317. #endif /* __NU_PDMA_H__ */
  318. /*** (C) COPYRIGHT 2018 Nuvoton Technology Corp. ***/