pdma.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /**************************************************************************//**
  2. * @file pdma.h
  3. * @version V1.00
  4. * $Revision: 15 $
  5. * $Date: 15/08/11 10:26a $
  6. * @brief M451 series PDMA driver header file
  7. *
  8. * @note
  9. * Copyright (C) 2014~2015 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #ifndef __PDMA_H__
  12. #define __PDMA_H__
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup Standard_Driver Standard Driver
  18. @{
  19. */
  20. /** @addtogroup PDMA_Driver PDMA Driver
  21. @{
  22. */
  23. /** @addtogroup PDMA_EXPORTED_CONSTANTS PDMA Exported Constants
  24. @{
  25. */
  26. #define PDMA_CH_MAX 12 /*!< Specify Maximum Channels of PDMA \hideinitializer */
  27. /*---------------------------------------------------------------------------------------------------------*/
  28. /* Operation Mode Constant Definitions */
  29. /*---------------------------------------------------------------------------------------------------------*/
  30. #define PDMA_OP_STOP 0x00000000UL /*!<DMA Stop Mode \hideinitializer */
  31. #define PDMA_OP_BASIC 0x00000001UL /*!<DMA Basic Mode \hideinitializer */
  32. #define PDMA_OP_SCATTER 0x00000002UL /*!<DMA Scatter-gather Mode \hideinitializer */
  33. /*---------------------------------------------------------------------------------------------------------*/
  34. /* Data Width Constant Definitions */
  35. /*---------------------------------------------------------------------------------------------------------*/
  36. #define PDMA_WIDTH_8 0x00000000UL /*!<DMA Transfer Width 8-bit \hideinitializer */
  37. #define PDMA_WIDTH_16 0x00001000UL /*!<DMA Transfer Width 16-bit \hideinitializer */
  38. #define PDMA_WIDTH_32 0x00002000UL /*!<DMA Transfer Width 32-bit \hideinitializer */
  39. /*---------------------------------------------------------------------------------------------------------*/
  40. /* Address Attribute Constant Definitions */
  41. /*---------------------------------------------------------------------------------------------------------*/
  42. #define PDMA_SAR_INC 0x00000000UL /*!<DMA SAR increment \hideinitializer */
  43. #define PDMA_SAR_FIX 0x00000300UL /*!<DMA SAR fix address \hideinitializer */
  44. #define PDMA_DAR_INC 0x00000000UL /*!<DMA DAR increment \hideinitializer */
  45. #define PDMA_DAR_FIX 0x00000C00UL /*!<DMA DAR fix address \hideinitializer */
  46. /*---------------------------------------------------------------------------------------------------------*/
  47. /* Burst Mode Constant Definitions */
  48. /*---------------------------------------------------------------------------------------------------------*/
  49. #define PDMA_REQ_SINGLE 0x00000004UL /*!<DMA Single Request \hideinitializer */
  50. #define PDMA_REQ_BURST 0x00000000UL /*!<DMA Burst Request \hideinitializer */
  51. #define PDMA_BURST_128 0x00000000UL /*!<DMA Burst 128 Transfers \hideinitializer */
  52. #define PDMA_BURST_64 0x00000010UL /*!<DMA Burst 64 Transfers \hideinitializer */
  53. #define PDMA_BURST_32 0x00000020UL /*!<DMA Burst 32 Transfers \hideinitializer */
  54. #define PDMA_BURST_16 0x00000030UL /*!<DMA Burst 16 Transfers \hideinitializer */
  55. #define PDMA_BURST_8 0x00000040UL /*!<DMA Burst 8 Transfers \hideinitializer */
  56. #define PDMA_BURST_4 0x00000050UL /*!<DMA Burst 4 Transfers \hideinitializer */
  57. #define PDMA_BURST_2 0x00000060UL /*!<DMA Burst 2 Transfers \hideinitializer */
  58. #define PDMA_BURST_1 0x00000070UL /*!<DMA Burst 1 Transfers \hideinitializer */
  59. /*---------------------------------------------------------------------------------------------------------*/
  60. /* Peripheral Transfer Mode Constant Definitions */
  61. /*---------------------------------------------------------------------------------------------------------*/
  62. #define PDMA_SPI0_TX 0x00000001UL /*!<DMA Connect to SPI1 TX \hideinitializer */
  63. #define PDMA_SPI1_TX 0x00000002UL /*!<DMA Connect to SPI2 TX \hideinitializer */
  64. #define PDMA_SPI2_TX 0x00000003UL /*!<DMA Connect to SPI3 TX \hideinitializer */
  65. #define PDMA_UART0_TX 0x00000004UL /*!<DMA Connect to UART0 TX \hideinitializer */
  66. #define PDMA_UART1_TX 0x00000005UL /*!<DMA Connect to UART1 TX \hideinitializer */
  67. #define PDMA_UART2_TX 0x00000006UL /*!<DMA Connect to UART2 TX \hideinitializer */
  68. #define PDMA_UART3_TX 0x00000007UL /*!<DMA Connect to UART3 TX \hideinitializer */
  69. #define PDMA_DAC_TX 0x00000008UL /*!<DMA Connect to DAC TX \hideinitializer */
  70. #define PDMA_ADC_RX 0x00000009UL /*!<DMA Connect to ADC RX \hideinitializer */
  71. #define PDMA_PWM0_P1_RX 0x0000000BUL /*!<DMA Connect to PWM0 P1 RX \hideinitializer */
  72. #define PDMA_PWM0_P2_RX 0x0000000CUL /*!<DMA Connect to PWM0 P2 RX \hideinitializer */
  73. #define PDMA_PWM0_P3_RX 0x0000000DUL /*!<DMA Connect to PWM0 P3 RX \hideinitializer */
  74. #define PDMA_PWM1_P1_RX 0x0000000EUL /*!<DMA Connect to PWM1 P1 RX \hideinitializer */
  75. #define PDMA_PWM1_P2_RX 0x0000000FUL /*!<DMA Connect to PWM1 P2 RX \hideinitializer */
  76. #define PDMA_PWM1_P3_RX 0x00000010UL /*!<DMA Connect to PWM1 P3 RX \hideinitializer */
  77. #define PDMA_SPI0_RX 0x00000011UL /*!<DMA Connect to SPI0 RX \hideinitializer */
  78. #define PDMA_SPI1_RX 0x00000012UL /*!<DMA Connect to SPI1 RX \hideinitializer */
  79. #define PDMA_SPI2_RX 0x00000013UL /*!<DMA Connect to SPI2 RX \hideinitializer */
  80. #define PDMA_UART0_RX 0x00000014UL /*!<DMA Connect to UART0 RX \hideinitializer */
  81. #define PDMA_UART1_RX 0x00000015UL /*!<DMA Connect to UART1 RX \hideinitializer */
  82. #define PDMA_UART2_RX 0x00000016UL /*!<DMA Connect to UART2 RX \hideinitializer */
  83. #define PDMA_UART3_RX 0x00000017UL /*!<DMA Connect to UART3 RX \hideinitializer */
  84. #define PDMA_MEM 0x0000001FUL /*!<DMA Connect to Memory \hideinitializer */
  85. /*---------------------------------------------------------------------------------------------------------*/
  86. /* Interrupt Type Constant Definitions */
  87. /*---------------------------------------------------------------------------------------------------------*/
  88. #define PDMA_INT_TRANS_DONE 0x00000000UL /*!<Transfer Done Interrupt \hideinitializer */
  89. #define PDMA_INT_TEMPTY 0x00000001UL /*!<Table Empty Interrupt \hideinitializer */
  90. #define PDMA_INT_TIMEOUT 0x00000002UL /*!<Timeout Interrupt(M45xD/M45xC Only) \hideinitializer */
  91. /*@}*/ /* end of group PDMA_EXPORTED_CONSTANTS */
  92. /** @addtogroup PDMA_EXPORTED_FUNCTIONS PDMA Exported Functions
  93. @{
  94. */
  95. /**
  96. * @brief Get PDMA Interrupt Status
  97. *
  98. * @param[in] None
  99. *
  100. * @return None
  101. *
  102. * @details This macro gets the interrupt status.
  103. */
  104. #define PDMA_GET_INT_STATUS() ((uint32_t)(PDMA->INTSTS))
  105. /**
  106. * @brief Get Transfer Done Interrupt Status
  107. *
  108. * @param[in] None
  109. *
  110. * @return None
  111. *
  112. * @details Get the transfer done Interrupt status.
  113. */
  114. #define PDMA_GET_TD_STS() ((uint32_t)(PDMA->TDSTS))
  115. /**
  116. * @brief Clear Transfer Done Interrupt Status
  117. *
  118. * @param[in] u32Mask The channel mask
  119. *
  120. * @return None
  121. *
  122. * @details Clear the transfer done Interrupt status.
  123. */
  124. #define PDMA_CLR_TD_FLAG(u32Mask) ((uint32_t)(PDMA->TDSTS = (u32Mask)))
  125. /**
  126. * @brief Get Target Abort Interrupt Status
  127. *
  128. * @param[in] None
  129. *
  130. * @return None
  131. *
  132. * @details Get the target abort Interrupt status.
  133. */
  134. #define PDMA_GET_ABORT_STS() ((uint32_t)(PDMA->ABTSTS))
  135. /**
  136. * @brief Clear Target Abort Interrupt Status
  137. *
  138. * @param[in] u32Mask The channel mask
  139. *
  140. * @return None
  141. *
  142. * @details Clear the target abort Interrupt status.
  143. */
  144. #define PDMA_CLR_ABORT_FLAG(u32Mask) ((uint32_t)(PDMA->ABTSTS = (u32Mask)))
  145. /**
  146. * @brief Get Scatter-Gather Table Empty Interrupt Status
  147. *
  148. * @param[in] None
  149. *
  150. * @return None
  151. *
  152. * @details Get the scatter-gather table empty Interrupt status.
  153. */
  154. #define PDMA_GET_EMPTY_STS() ((uint32_t)(PDMA->SCATSTS))
  155. /**
  156. * @brief Clear Scatter-Gather Table Empty Interrupt Status
  157. *
  158. * @param[in] u32Mask The channel mask
  159. *
  160. * @return None
  161. *
  162. * @details Clear the scatter-gather table empty Interrupt status.
  163. */
  164. #define PDMA_CLR_EMPTY_FLAG(u32Mask) ((uint32_t)(PDMA->SCATSTS = (u32Mask)))
  165. /**
  166. * @brief Clear Timeout Interrupt Status
  167. *
  168. * @param[in] u32Ch The selected channel
  169. *
  170. * @return None
  171. *
  172. * @details Clear the selected channel timeout interrupt status.
  173. * @note This function is only supported in M45xD/M45xC.
  174. */
  175. #define PDMA_CLR_TMOUT_FLAG(u32Ch) ((uint32_t)(PDMA->INTSTS = (1 << ((u32Ch) + 8))))
  176. /**
  177. * @brief Check Channel Status
  178. *
  179. * @param[in] u32Ch The selected channel
  180. *
  181. * @retval 0 Idle state
  182. * @retval 1 Busy state
  183. *
  184. * @details Check the selected channel is busy or not.
  185. */
  186. #define PDMA_IS_CH_BUSY(u32Ch) ((uint32_t)(PDMA->TRGSTS & (1 << (u32Ch)))? 1 : 0)
  187. /**
  188. * @brief Set Source Address
  189. *
  190. * @param[in] u32Ch The selected channel
  191. * @param[in] u32Addr The selected address
  192. *
  193. * @return None
  194. *
  195. * @details This macro set the selected channel source address.
  196. */
  197. #define PDMA_SET_SRC_ADDR(u32Ch, u32Addr) ((uint32_t)(PDMA->DSCT[(u32Ch)].SA = (u32Addr)))
  198. /**
  199. * @brief Set Destination Address
  200. *
  201. * @param[in] u32Ch The selected channel
  202. * @param[in] u32Addr The selected address
  203. *
  204. * @return None
  205. *
  206. * @details This macro set the selected channel destination address.
  207. */
  208. #define PDMA_SET_DST_ADDR(u32Ch, u32Addr) ((uint32_t)(PDMA->DSCT[(u32Ch)].DA = (u32Addr)))
  209. /**
  210. * @brief Set Transfer Count
  211. *
  212. * @param[in] u32Ch The selected channel
  213. * @param[in] u32TransCount Transfer Count
  214. *
  215. * @return None
  216. *
  217. * @details This macro set the selected channel transfer count.
  218. */
  219. #define PDMA_SET_TRANS_CNT(u32Ch, u32TransCount) ((uint32_t)(PDMA->DSCT[(u32Ch)].CTL=(PDMA->DSCT[(u32Ch)].CTL&~PDMA_DSCT_CTL_TXCNT_Msk)|((u32TransCount-1) << PDMA_DSCT_CTL_TXCNT_Pos)))
  220. /**
  221. * @brief Set Scatter-gather descriptor Address
  222. *
  223. * @param[in] u32Ch The selected channel
  224. * @param[in] u32Addr The descriptor address
  225. *
  226. * @return None
  227. *
  228. * @details This macro set the selected channel scatter-gather descriptor address.
  229. */
  230. #define PDMA_SET_SCATTER_DESC(u32Ch, u32Addr) ((uint32_t)(PDMA->DSCT[(u32Ch)].NEXT = (u32Addr) - (PDMA->SCATBA)))
  231. /**
  232. * @brief Stop the channel
  233. *
  234. * @param[in] u32Ch The selected channel
  235. *
  236. * @return None
  237. *
  238. * @details This macro stop the selected channel.
  239. */
  240. #define PDMA_STOP(u32Ch) ((uint32_t)(PDMA->STOP = (1 << (u32Ch))))
  241. /*---------------------------------------------------------------------------------------------------------*/
  242. /* Define PWM functions prototype */
  243. /*---------------------------------------------------------------------------------------------------------*/
  244. void PDMA_Open(uint32_t u32Mask);
  245. void PDMA_Close(void);
  246. void PDMA_SetTransferCnt(uint32_t u32Ch, uint32_t u32Width, uint32_t u32TransCount);
  247. void PDMA_SetTransferAddr(uint32_t u32Ch, uint32_t u32SrcAddr, uint32_t u32SrcCtrl, uint32_t u32DstAddr, uint32_t u32DstCtrl);
  248. void PDMA_SetTransferMode(uint32_t u32Ch, uint32_t u32Peripheral, uint32_t u32ScatterEn, uint32_t u32DescAddr);
  249. void PDMA_SetBurstType(uint32_t u32Ch, uint32_t u32BurstType, uint32_t u32BurstSize);
  250. void PDMA_EnableTimeout(uint32_t u32Mask);
  251. void PDMA_DisableTimeout(uint32_t u32Mask);
  252. void PDMA_SetTimeOut(uint32_t u32Ch, uint32_t u32OnOff, uint32_t u32TimeOutCnt);
  253. void PDMA_Trigger(uint32_t u32Ch);
  254. void PDMA_EnableInt(uint32_t u32Ch, uint32_t u32Mask);
  255. void PDMA_DisableInt(uint32_t u32Ch, uint32_t u32Mask);
  256. /*@}*/ /* end of group PDMA_EXPORTED_FUNCTIONS */
  257. /*@}*/ /* end of group PDMA_Driver */
  258. /*@}*/ /* end of group Standard_Driver */
  259. #ifdef __cplusplus
  260. }
  261. #endif
  262. #endif //__PDMA_H__
  263. /*** (C) COPYRIGHT 2014~2015 Nuvoton Technology Corp. ***/