pdma.h 17 KB

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