nu_pdma.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /**************************************************************************//**
  2. * @file nu_pdma.h
  3. * @version V1.00
  4. * @brief M480 series PDMA driver header file
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * @copyright (C) 2016-2020 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 16UL /*!< 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_USB_TX 2UL /*!<DMA Connect to USB_TX \hideinitializer */
  67. #define PDMA_USB_RX 3UL /*!<DMA Connect to USB_RX \hideinitializer */
  68. #define PDMA_UART0_TX 4UL /*!<DMA Connect to UART0_TX \hideinitializer */
  69. #define PDMA_UART0_RX 5UL /*!<DMA Connect to UART0_RX \hideinitializer */
  70. #define PDMA_UART1_TX 6UL /*!<DMA Connect to UART1_TX \hideinitializer */
  71. #define PDMA_UART1_RX 7UL /*!<DMA Connect to UART1_RX \hideinitializer */
  72. #define PDMA_UART2_TX 8UL /*!<DMA Connect to UART2_TX \hideinitializer */
  73. #define PDMA_UART2_RX 9UL /*!<DMA Connect to UART2_RX \hideinitializer */
  74. #define PDMA_UART3_TX 10UL /*!<DMA Connect to UART3_TX \hideinitializer */
  75. #define PDMA_UART3_RX 11UL /*!<DMA Connect to UART3_RX \hideinitializer */
  76. #define PDMA_UART4_TX 12UL /*!<DMA Connect to UART4_TX \hideinitializer */
  77. #define PDMA_UART4_RX 13UL /*!<DMA Connect to UART4_RX \hideinitializer */
  78. #define PDMA_UART5_TX 14UL /*!<DMA Connect to UART5_TX \hideinitializer */
  79. #define PDMA_UART5_RX 15UL /*!<DMA Connect to UART5_RX \hideinitializer */
  80. #define PDMA_USCI0_TX 16UL /*!<DMA Connect to USCI0_TX \hideinitializer */
  81. #define PDMA_USCI0_RX 17UL /*!<DMA Connect to USCI0_RX \hideinitializer */
  82. #define PDMA_USCI1_TX 18UL /*!<DMA Connect to USCI1_TX \hideinitializer */
  83. #define PDMA_USCI1_RX 19UL /*!<DMA Connect to USCI1_RX \hideinitializer */
  84. #define PDMA_QSPI0_TX 20UL /*!<DMA Connect to QSPI0_TX \hideinitializer */
  85. #define PDMA_QSPI0_RX 21UL /*!<DMA Connect to QSPI0_RX \hideinitializer */
  86. #define PDMA_SPI0_TX 22UL /*!<DMA Connect to SPI0_TX \hideinitializer */
  87. #define PDMA_SPI0_RX 23UL /*!<DMA Connect to SPI0_RX \hideinitializer */
  88. #define PDMA_SPI1_TX 24UL /*!<DMA Connect to SPI1_TX \hideinitializer */
  89. #define PDMA_SPI1_RX 25UL /*!<DMA Connect to SPI1_RX \hideinitializer */
  90. #define PDMA_SPI2_TX 26UL /*!<DMA Connect to SPI2_TX \hideinitializer */
  91. #define PDMA_SPI2_RX 27UL /*!<DMA Connect to SPI2_RX \hideinitializer */
  92. #define PDMA_SPI3_TX 28UL /*!<DMA Connect to SPI3_TX \hideinitializer */
  93. #define PDMA_SPI3_RX 29UL /*!<DMA Connect to SPI3_RX \hideinitializer */
  94. #define PDMA_QSPI1_TX 30UL /*!<DMA Connect to QSPI1_TX \hideinitializer */
  95. #define PDMA_QSPI1_RX 31UL /*!<DMA Connect to QSPI1_RX \hideinitializer */
  96. #define PDMA_EPWM0_P1_RX 32UL /*!<DMA Connect to EPWM0_P1 \hideinitializer */
  97. #define PDMA_EPWM0_P2_RX 33UL /*!<DMA Connect to EPWM0_P2 \hideinitializer */
  98. #define PDMA_EPWM0_P3_RX 34UL /*!<DMA Connect to EPWM0_P3 \hideinitializer */
  99. #define PDMA_EPWM1_P1_RX 35UL /*!<DMA Connect to EPWM1_P1 \hideinitializer */
  100. #define PDMA_EPWM1_P2_RX 36UL /*!<DMA Connect to EPWM1_P2 \hideinitializer */
  101. #define PDMA_EPWM1_P3_RX 37UL /*!<DMA Connect to PWM1_P3 \hideinitializer */
  102. #define PDMA_I2C0_TX 38UL /*!<DMA Connect to I2C0_TX \hideinitializer */
  103. #define PDMA_I2C0_RX 39UL /*!<DMA Connect to I2C0_RX \hideinitializer */
  104. #define PDMA_I2C1_TX 40UL /*!<DMA Connect to I2C1_TX \hideinitializer */
  105. #define PDMA_I2C1_RX 41UL /*!<DMA Connect to I2C1_RX \hideinitializer */
  106. #define PDMA_I2C2_TX 42UL /*!<DMA Connect to I2C2_TX \hideinitializer */
  107. #define PDMA_I2C2_RX 43UL /*!<DMA Connect to I2C2_RX \hideinitializer */
  108. #define PDMA_I2S0_TX 44UL /*!<DMA Connect to I2S0_TX \hideinitializer */
  109. #define PDMA_I2S0_RX 45UL /*!<DMA Connect to I2S0_RX \hideinitializer */
  110. #define PDMA_TMR0 46UL /*!<DMA Connect to TMR0 \hideinitializer */
  111. #define PDMA_TMR1 47UL /*!<DMA Connect to TMR1 \hideinitializer */
  112. #define PDMA_TMR2 48UL /*!<DMA Connect to TMR2 \hideinitializer */
  113. #define PDMA_TMR3 49UL /*!<DMA Connect to TMR3 \hideinitializer */
  114. #define PDMA_EADC0_RX 50UL /*!<DMA Connect to EADC0_RX \hideinitializer */
  115. #define PDMA_DAC0_TX 51UL /*!<DMA Connect to DAC0_TX \hideinitializer */
  116. #define PDMA_DAC1_TX 52UL /*!<DMA Connect to DAC1_TX \hideinitializer */
  117. #define PDMA_EPWM0_CH0_TX 53UL /*!<DMA Connect to EPWM0_CH0_TX \hideinitializer */
  118. #define PDMA_EPWM0_CH1_TX 54UL /*!<DMA Connect to EPWM0_CH1_TX \hideinitializer */
  119. #define PDMA_EPWM0_CH2_TX 55UL /*!<DMA Connect to EPWM0_CH2_TX \hideinitializer */
  120. #define PDMA_EPWM0_CH3_TX 56UL /*!<DMA Connect to EPWM0_CH3_TX \hideinitializer */
  121. #define PDMA_EPWM0_CH4_TX 57UL /*!<DMA Connect to EPWM0_CH4_TX \hideinitializer */
  122. #define PDMA_EPWM0_CH5_TX 58UL /*!<DMA Connect to EPWM0_CH5_TX \hideinitializer */
  123. #define PDMA_EPWM1_CH0_TX 59UL /*!<DMA Connect to EPWM1_CH0_TX \hideinitializer */
  124. #define PDMA_EPWM1_CH1_TX 60UL /*!<DMA Connect to EPWM1_CH1_TX \hideinitializer */
  125. #define PDMA_EPWM1_CH2_TX 61UL /*!<DMA Connect to EPWM1_CH2_TX \hideinitializer */
  126. #define PDMA_EPWM1_CH3_TX 62UL /*!<DMA Connect to EPWM1_CH3_TX \hideinitializer */
  127. #define PDMA_EPWM1_CH4_TX 63UL /*!<DMA Connect to EPWM1_CH4_TX \hideinitializer */
  128. #define PDMA_EPWM1_CH5_TX 64UL /*!<DMA Connect to EPWM1_CH5_TX \hideinitializer */
  129. #define PDMA_UART6_TX 66UL /*!<DMA Connect to UART6_TX \hideinitializer */
  130. #define PDMA_UART6_RX 67UL /*!<DMA Connect to UART6_RX \hideinitializer */
  131. #define PDMA_UART7_TX 68UL /*!<DMA Connect to UART7_TX \hideinitializer */
  132. #define PDMA_UART7_RX 69UL /*!<DMA Connect to UART7_RX \hideinitializer */
  133. #define PDMA_EADC1_RX 70UL /*!<DMA Connect to EADC1_RX \hideinitializer */
  134. /*---------------------------------------------------------------------------------------------------------*/
  135. /* Interrupt Type Constant Definitions */
  136. /*---------------------------------------------------------------------------------------------------------*/
  137. #define PDMA_INT_TRANS_DONE 0x00000000UL /*!<Transfer Done Interrupt \hideinitializer */
  138. #define PDMA_INT_TEMPTY 0x00000001UL /*!<Table Empty Interrupt \hideinitializer */
  139. #define PDMA_INT_TIMEOUT 0x00000002UL /*!<Timeout Interrupt \hideinitializer */
  140. /*@}*/ /* end of group PDMA_EXPORTED_CONSTANTS */
  141. /** @addtogroup PDMA_EXPORTED_FUNCTIONS PDMA Exported Functions
  142. @{
  143. */
  144. /**
  145. * @brief Get PDMA Interrupt Status
  146. *
  147. * @param[in] pdma The pointer of the specified PDMA module
  148. *
  149. * @return None
  150. *
  151. * @details This macro gets the interrupt status.
  152. * \hideinitializer
  153. */
  154. #define PDMA_GET_INT_STATUS(pdma) ((uint32_t)(pdma->INTSTS))
  155. /**
  156. * @brief Get Transfer Done Interrupt Status
  157. *
  158. * @param[in] pdma The pointer of the specified PDMA module
  159. *
  160. * @return None
  161. *
  162. * @details Get the transfer done Interrupt status.
  163. * \hideinitializer
  164. */
  165. #define PDMA_GET_TD_STS(pdma) ((uint32_t)(pdma->TDSTS))
  166. /**
  167. * @brief Clear Transfer Done Interrupt Status
  168. *
  169. * @param[in] pdma The pointer of the specified PDMA module
  170. *
  171. * @param[in] u32Mask The channel mask
  172. *
  173. * @return None
  174. *
  175. * @details Clear the transfer done Interrupt status.
  176. * \hideinitializer
  177. */
  178. #define PDMA_CLR_TD_FLAG(pdma,u32Mask) ((uint32_t)(pdma->TDSTS = (u32Mask)))
  179. /**
  180. * @brief Get Target Abort Interrupt Status
  181. *
  182. * @param[in] pdma The pointer of the specified PDMA module
  183. *
  184. * @return None
  185. *
  186. * @details Get the target abort Interrupt status.
  187. * \hideinitializer
  188. */
  189. #define PDMA_GET_ABORT_STS(pdma) ((uint32_t)(pdma->ABTSTS))
  190. /**
  191. * @brief Clear Target Abort Interrupt Status
  192. *
  193. * @param[in] pdma The pointer of the specified PDMA module
  194. *
  195. * @param[in] u32Mask The channel mask
  196. *
  197. * @return None
  198. *
  199. * @details Clear the target abort Interrupt status.
  200. * \hideinitializer
  201. */
  202. #define PDMA_CLR_ABORT_FLAG(pdma,u32Mask) ((uint32_t)(pdma->ABTSTS = (u32Mask)))
  203. /**
  204. * @brief Get Alignment Interrupt Status
  205. *
  206. * @param[in] pdma The pointer of the specified PDMA module
  207. *
  208. * @return None
  209. *
  210. * @details Get Alignment Interrupt status.
  211. * \hideinitializer
  212. */
  213. #define PDMA_GET_ALIGN_STS(pdma) ((uint32_t)(PDMA->ALIGN))
  214. /**
  215. * @brief Clear Alignment Interrupt Status
  216. *
  217. * @param[in] pdma The pointer of the specified PDMA module
  218. * @param[in] u32Mask The channel mask
  219. *
  220. * @return None
  221. *
  222. * @details Clear the Alignment Interrupt status.
  223. * \hideinitializer
  224. */
  225. #define PDMA_CLR_ALIGN_FLAG(pdma,u32Mask) ((uint32_t)(pdma->ALIGN = (u32Mask)))
  226. /**
  227. * @brief Clear Timeout Interrupt Status
  228. *
  229. * @param[in] pdma The pointer of the specified PDMA module
  230. * @param[in] u32Ch The selected channel
  231. *
  232. * @return None
  233. *
  234. * @details Clear the selected channel timeout interrupt status.
  235. * \hideinitializer
  236. */
  237. #define PDMA_CLR_TMOUT_FLAG(pdma,u32Ch) ((uint32_t)(pdma->INTSTS = (1 << ((u32Ch) + 8))))
  238. /**
  239. * @brief Check Channel Status
  240. *
  241. * @param[in] pdma The pointer of the specified PDMA module
  242. * @param[in] u32Ch The selected channel
  243. *
  244. * @retval 0 Idle state
  245. * @retval 1 Busy state
  246. *
  247. * @details Check the selected channel is busy or not.
  248. * \hideinitializer
  249. */
  250. #define PDMA_IS_CH_BUSY(pdma,u32Ch) ((uint32_t)(pdma->TRGSTS & (1 << (u32Ch)))? 1 : 0)
  251. /**
  252. * @brief Set Source Address
  253. *
  254. * @param[in] pdma The pointer of the specified PDMA module
  255. * @param[in] u32Ch The selected channel
  256. * @param[in] u32Addr The selected address
  257. *
  258. * @return None
  259. *
  260. * @details This macro set the selected channel source address.
  261. * \hideinitializer
  262. */
  263. #define PDMA_SET_SRC_ADDR(pdma,u32Ch, u32Addr) ((uint32_t)(pdma->DSCT[(u32Ch)].SA = (u32Addr)))
  264. /**
  265. * @brief Set Destination Address
  266. *
  267. * @param[in] pdma The pointer of the specified PDMA module
  268. * @param[in] u32Ch The selected channel
  269. * @param[in] u32Addr The selected address
  270. *
  271. * @return None
  272. *
  273. * @details This macro set the selected channel destination address.
  274. * \hideinitializer
  275. */
  276. #define PDMA_SET_DST_ADDR(pdma,u32Ch, u32Addr) ((uint32_t)(pdma->DSCT[(u32Ch)].DA = (u32Addr)))
  277. /**
  278. * @brief Set Transfer Count
  279. *
  280. * @param[in] pdma The pointer of the specified PDMA module
  281. * @param[in] u32Ch The selected channel
  282. * @param[in] u32TransCount Transfer Count
  283. *
  284. * @return None
  285. *
  286. * @details This macro set the selected channel transfer count.
  287. * \hideinitializer
  288. */
  289. #define PDMA_SET_TRANS_CNT(pdma,u32Ch, u32TransCount) ((uint32_t)(pdma->DSCT[(u32Ch)].CTL=(pdma->DSCT[(u32Ch)].CTL&~PDMA_DSCT_CTL_TXCNT_Msk)|(((u32TransCount)-1) << PDMA_DSCT_CTL_TXCNT_Pos)))
  290. /**
  291. * @brief Set Scatter-gather descriptor Address
  292. *
  293. * @param[in] pdma The pointer of the specified PDMA module
  294. * @param[in] u32Ch The selected channel
  295. * @param[in] u32Addr The descriptor address
  296. *
  297. * @return None
  298. *
  299. * @details This macro set the selected channel scatter-gather descriptor address.
  300. * \hideinitializer
  301. */
  302. #define PDMA_SET_SCATTER_DESC(pdma,u32Ch, u32Addr) ((uint32_t)(pdma->DSCT[(u32Ch)].NEXT = (u32Addr) - (pdma->SCATBA)))
  303. /**
  304. * @brief Stop the channel
  305. *
  306. * @param[in] pdma The pointer of the specified PDMA module
  307. *
  308. * @param[in] u32Ch The selected channel
  309. *
  310. * @return None
  311. *
  312. * @details This macro stop the selected channel.
  313. * \hideinitializer
  314. */
  315. #define PDMA_STOP(pdma,u32Ch) ((uint32_t)(pdma->PAUSE = (1 << (u32Ch))))
  316. /**
  317. * @brief Pause the channel
  318. *
  319. * @param[in] pdma The pointer of the specified PDMA module
  320. *
  321. * @param[in] u32Ch The selected channel
  322. *
  323. * @return None
  324. *
  325. * @details This macro pause the selected channel.
  326. * \hideinitializer
  327. */
  328. #define PDMA_PAUSE(pdma,u32Ch) ((uint32_t)(pdma->PAUSE = (1 << (u32Ch))))
  329. /*---------------------------------------------------------------------------------------------------------*/
  330. /* Define PDMA functions prototype */
  331. /*---------------------------------------------------------------------------------------------------------*/
  332. void PDMA_Open(PDMA_T * pdma,uint32_t u32Mask);
  333. void PDMA_Close(PDMA_T * pdma);
  334. void PDMA_SetTransferCnt(PDMA_T * pdma,uint32_t u32Ch, uint32_t u32Width, uint32_t u32TransCount);
  335. void PDMA_SetTransferAddr(PDMA_T * pdma,uint32_t u32Ch, uint32_t u32SrcAddr, uint32_t u32SrcCtrl, uint32_t u32DstAddr, uint32_t u32DstCtrl);
  336. void PDMA_SetTransferMode(PDMA_T * pdma,uint32_t u32Ch, uint32_t u32Peripheral, uint32_t u32ScatterEn, uint32_t u32DescAddr);
  337. void PDMA_SetBurstType(PDMA_T * pdma,uint32_t u32Ch, uint32_t u32BurstType, uint32_t u32BurstSize);
  338. void PDMA_EnableTimeout(PDMA_T * pdma,uint32_t u32Mask);
  339. void PDMA_DisableTimeout(PDMA_T * pdma,uint32_t u32Mask);
  340. void PDMA_SetTimeOut(PDMA_T * pdma,uint32_t u32Ch, uint32_t u32OnOff, uint32_t u32TimeOutCnt);
  341. void PDMA_Trigger(PDMA_T * pdma,uint32_t u32Ch);
  342. void PDMA_EnableInt(PDMA_T * pdma,uint32_t u32Ch, uint32_t u32Mask);
  343. void PDMA_DisableInt(PDMA_T * pdma,uint32_t u32Ch, uint32_t u32Mask);
  344. void PDMA_SetStride(PDMA_T * pdma,uint32_t u32Ch, uint32_t u32DestLen, uint32_t u32SrcLen, uint32_t u32TransCount);
  345. void PDMA_SetRepeat(PDMA_T * pdma,uint32_t u32Ch, uint32_t u32DestInterval, uint32_t u32SrcInterval, uint32_t u32RepeatCount);
  346. /*@}*/ /* end of group PDMA_EXPORTED_FUNCTIONS */
  347. /*@}*/ /* end of group PDMA_Driver */
  348. /*@}*/ /* end of group Standard_Driver */
  349. #ifdef __cplusplus
  350. }
  351. #endif
  352. #endif /* __NU_PDMA_H__ */
  353. /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/