dmac.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*****************************************************************************
  2. * Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
  3. *
  4. * This software is owned and published by:
  5. * Huada Semiconductor Co.,Ltd ("HDSC").
  6. *
  7. * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
  8. * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
  9. *
  10. * This software contains source code for use with HDSC
  11. * components. This software is licensed by HDSC to be adapted only
  12. * for use in systems utilizing HDSC components. HDSC shall not be
  13. * responsible for misuse or illegal use of this software for devices not
  14. * supported herein. HDSC is providing this software "AS IS" and will
  15. * not be responsible for issues arising from incorrect user implementation
  16. * of the software.
  17. *
  18. * Disclaimer:
  19. * HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
  20. * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
  21. * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
  22. * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
  23. * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
  24. * WARRANTY OF NONINFRINGEMENT.
  25. * HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
  26. * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
  27. * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
  28. * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
  29. * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
  30. * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
  31. * SAVINGS OR PROFITS,
  32. * EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  33. * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
  34. * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
  35. * FROM, THE SOFTWARE.
  36. *
  37. * This software may be replicated in part or whole for the licensed use,
  38. * with the restriction that this Disclaimer and Copyright notice must be
  39. * included with each copy of this software, whether used in part or whole,
  40. * at all times.
  41. */
  42. /******************************************************************************/
  43. /** \file dma.h
  44. **
  45. ** A detailed description is available at
  46. ** @link DmacGroup Dmac description @endlink
  47. **
  48. ** - 2018-03-09 1.0 Hongjh First version for Device Driver Library of Dmac.
  49. **
  50. ******************************************************************************/
  51. #ifndef __DMAC_H__
  52. #define __DMAC_H__
  53. /*******************************************************************************
  54. * Include files
  55. ******************************************************************************/
  56. #include "ddl.h"
  57. /* C binding of definitions if building with C++ compiler */
  58. #ifdef __cplusplus
  59. extern "C"
  60. {
  61. #endif
  62. /**
  63. *******************************************************************************
  64. ** \defgroup DmacGroup Direct Memory Access Control(DMAC)
  65. **
  66. ******************************************************************************/
  67. //@{
  68. /*******************************************************************************
  69. * Global type definitions ('typedef')
  70. ******************************************************************************/
  71. /**
  72. *******************************************************************************
  73. ** \brief DMA Channel
  74. **
  75. ******************************************************************************/
  76. typedef enum en_dma_channel
  77. {
  78. DmaCh0 = 0U, ///< DMA channel 0
  79. DmaCh1 = 1U, ///< DMA channel 1
  80. DmaChMax = 2U ///< DMA channel max
  81. } en_dma_channel_t;
  82. /**
  83. *******************************************************************************
  84. ** \brief DMA priority
  85. **
  86. ******************************************************************************/
  87. typedef enum en_dma_priority
  88. {
  89. DmaPriorityFix = 0U, ///< DMA channel priority fix (CH0>CH1)
  90. DmaPriorityLoop = 1U, ///< DMA channel priority loop
  91. } en_dma_priority_t;
  92. /**
  93. *******************************************************************************
  94. ** \brief DMA transfer data width
  95. **
  96. ******************************************************************************/
  97. typedef enum en_dma_transfer_width
  98. {
  99. Dma8Bit = 0U, ///< 8 bit transfer via DMA
  100. Dma16Bit = 1U, ///< 16 bit transfer via DMA
  101. Dma32Bit = 2U ///< 32 bit transfer via DMA
  102. } en_dma_transfer_width_t;
  103. /**
  104. *******************************************************************************
  105. ** \brief DMA transfer mode
  106. **
  107. ******************************************************************************/
  108. typedef enum en_dma_transfer_mode
  109. {
  110. DmaBlock = 0U, ///< block transfer via DMA
  111. DmaBurst = 1U, ///< burst transfer via DMA
  112. } en_dma_transfer_mode_t;
  113. /**
  114. *******************************************************************************
  115. ** \brief DMA flag
  116. **
  117. ******************************************************************************/
  118. typedef enum en_dma_stat
  119. {
  120. DEFAULT = 0U, ///< Reserve
  121. DmaAddOverflow = 1U, ///< DMA address overflow
  122. DmaHALT = 2U, ///< DMA HALT
  123. DmaAccSCRErr = 3U, ///< DMA access source address error
  124. DmaAccDestErr = 4U, ///< DMA access dest address error
  125. DmaTransferComplete = 5U, ///< DMA transfer complete
  126. DmaTransferPause = 7U, ///< DMA transfer pause
  127. } en_dma_stat_t;
  128. /**
  129. *******************************************************************************
  130. ** \brief DMA address mode
  131. **
  132. ******************************************************************************/
  133. typedef enum en_address_mode
  134. {
  135. AddressIncrease = 0U, ///< Address increased
  136. AddressFix = 1U, ///< Address fixed
  137. } en_address_mode_t;
  138. /**
  139. *******************************************************************************
  140. ** \brief DMA repeat tranfer
  141. **
  142. ******************************************************************************/
  143. typedef enum en_dma_msk
  144. {
  145. OneTranfer = 0U, ///< One Tranfer
  146. ContinuousTranfer = 1U, ///< Continuous Tranfer
  147. } en_dma_msk_t;
  148. /**
  149. *******************************************************************************
  150. ** \brief DMA trigger selection
  151. **
  152. ******************************************************************************/
  153. typedef enum stc_dma_trig_sel
  154. {
  155. SWTrig = 0U, ///< Select DMA software trig
  156. SPI0RXTrig = 32U, ///< Select DMA hardware trig 0
  157. SPI0TXTrig = 33U, ///< Select DMA hardware trig 1
  158. SPI1RXTrig = 34U, ///< Select DMA hardware trig 2
  159. SPI1TXTrig = 35U, ///< Select DMA hardware trig 3
  160. ADCJQRTrig = 36U, ///< Select DMA hardware trig 4
  161. ADCSQRTrig = 37U, ///< Select DMA hardware trig 5
  162. LCDTxTrig = 38U, ///< Select DMA hardware trig 6
  163. Uart0RxTrig = 40U, ///< Select DMA hardware trig 8
  164. Uart0TxTrig = 41U, ///< Select DMA hardware trig 9
  165. Uart1RxTrig = 42U, ///< Select DMA hardware trig 10
  166. Uart1TxTrig = 43U, ///< Select DMA hardware trig 11
  167. LpUart0RxTrig = 44U, ///< Select DMA hardware trig 12
  168. LpUart0TxTrig = 45U, ///< Select DMA hardware trig 13
  169. LpUart1RxTrig = 46U, ///< Select DMA hardware trig 14
  170. LpUart1TxTrig = 47U, ///< Select DMA hardware trig 15
  171. TIM0ATrig = 50U, ///< Select DMA hardware trig 18
  172. TIM0BTrig = 51U, ///< Select DMA hardware trig 19
  173. TIM1ATrig = 52U, ///< Select DMA hardware trig 20
  174. TIM1BTrig = 53U, ///< Select DMA hardware trig 21
  175. TIM2ATrig = 54U, ///< Select DMA hardware trig 22
  176. TIM2BTrig = 55U, ///< Select DMA hardware trig 23
  177. TIM3ATrig = 56U, ///< Select DMA hardware trig 24
  178. TIM3BTrig = 57U, ///< Select DMA hardware trig 25
  179. TIM4ATrig = 58U, ///< Select DMA hardware trig 26
  180. TIM4BTrig = 59U, ///< Select DMA hardware trig 27
  181. TIM5ATrig = 60U, ///< Select DMA hardware trig 28
  182. TIM5BTrig = 61U, ///< Select DMA hardware trig 29
  183. TIM6ATrig = 62U, ///< Select DMA hardware trig 30
  184. TIM6BTrig = 63U, ///< Select DMA hardware trig 31
  185. }en_dma_trig_sel_t;
  186. /**
  187. *******************************************************************************
  188. ** \brief DMA interrupt selection
  189. **
  190. ******************************************************************************/
  191. typedef struct stc_dma_irq
  192. {
  193. boolean_t TrnErrIrq; ///< Select DMA transfer error interrupt
  194. boolean_t TrnCpltIrq; ///< Select DMA transfer completion interrupt
  195. }stc_dma_irq_sel_t;
  196. /**
  197. *******************************************************************************
  198. ** \brief DMA configuration
  199. **
  200. ******************************************************************************/
  201. typedef struct stc_dma_config
  202. {
  203. en_dma_transfer_mode_t enMode;
  204. uint16_t u16BlockSize; ///< Transfer Block counter
  205. uint16_t u16TransferCnt; ///< Transfer counter
  206. en_dma_transfer_width_t enTransferWidth; ///< DMA transfer width (see #en_dma_transfer_width_t for details)
  207. en_address_mode_t enSrcAddrMode; ///< Source address mode(see #en_source_address_mode_t for details)
  208. en_address_mode_t enDstAddrMode; ///< Destination address mode(see #en_dest_address_mode_t for details)
  209. boolean_t bSrcAddrReloadCtl; ///< Source address reload(TRUE: reload;FALSE: reload forbidden)
  210. boolean_t bDestAddrReloadCtl; ///< Dest address reload(TRUE: reload;FALSE: reload forbidden)
  211. boolean_t bSrcBcTcReloadCtl; ///< Bc/Tc address reload(TRUE: reload;FALSE: reload forbidden)
  212. uint32_t u32SrcAddress; ///< Source address>
  213. uint32_t u32DstAddress; ///< Dest address>
  214. boolean_t bMsk; ///0: clear the bit (CONFA:ENS) after tarnfer;1: remain the bit (CONFA:ENS) after tarnfer
  215. en_dma_trig_sel_t enRequestNum; ///< DMA trigger request number
  216. } stc_dma_config_t;
  217. /**
  218. ******************************************************************************
  219. ** \brief DMA中断回调函数
  220. *****************************************************************************/
  221. typedef struct stc_dma_irq_calbakfn_pt
  222. {
  223. /*! Dma传输完成中断回调函数指针*/
  224. func_ptr_t pfnDma0TranferCompleteIrq;
  225. /*! Dma传输完成中断回调函数指针*/
  226. func_ptr_t pfnDma1TranferCompleteIrq;
  227. /*! Dma传输错误中断回调函数指针*/
  228. func_ptr_t pfnDma0TranferErrIrq;
  229. /*! Dma传输错误中断回调函数指针*/
  230. func_ptr_t pfnDma1TranferErrIrq;
  231. }stc_dma_irq_calbakfn_pt_t;
  232. /*******************************************************************************
  233. * Global pre-processor symbols/macros ('#define')
  234. ******************************************************************************/
  235. /*******************************************************************************
  236. * Global variable definitions ('extern')
  237. ******************************************************************************/
  238. /*******************************************************************************
  239. * Global function prototypes (definition in C source)
  240. ******************************************************************************/
  241. en_result_t Dma_InitChannel(en_dma_channel_t enCh, stc_dma_config_t* pstcConfig);
  242. void Dma_SwTrigger(en_dma_channel_t enCh);
  243. void Dma_Enable(void);
  244. void Dma_Disable(void);
  245. void Dma_Start(en_dma_channel_t enCh);
  246. void Dma_Stop(en_dma_channel_t enCh);
  247. en_result_t Dma_EnableChannel(en_dma_channel_t enCh);
  248. en_result_t Dma_DisableChannel(en_dma_channel_t enCh);
  249. en_result_t Dma_SetTriggerSel(en_dma_channel_t enCh, en_dma_trig_sel_t enTrgSel);
  250. en_result_t Dma_SetSourceAddress(en_dma_channel_t enCh, uint32_t u32Address);
  251. en_result_t Dma_SetDestinationAddress(en_dma_channel_t enCh, uint32_t u32Address);
  252. en_result_t Dma_SetBlockSize(en_dma_channel_t enCh, uint16_t u16BlkSize);
  253. en_result_t Dma_SetTransferCnt(en_dma_channel_t enCh, uint16_t u16TrnCnt);
  254. en_result_t Dma_SetSourceIncMode(en_dma_channel_t enCh, en_address_mode_t enMode);
  255. en_result_t Dma_SetDestinationIncMode(en_dma_channel_t enCh, en_address_mode_t enMode);
  256. en_result_t Dma_EnableSourceRload(en_dma_channel_t enCh);
  257. en_result_t Dma_DisableSourceRload(en_dma_channel_t enCh);
  258. en_result_t Dma_EnableDestinationRload(en_dma_channel_t enCh);
  259. en_result_t Dma_DisableDestinationRload(en_dma_channel_t enCh);
  260. en_result_t Dma_EnableContinusTranfer(en_dma_channel_t enCh);
  261. en_result_t Dma_DisableContinusTranfer(en_dma_channel_t enCh);
  262. en_result_t Dma_EnableBcTcReload(en_dma_channel_t enCh);
  263. en_result_t Dma_DisableBcTcReload(en_dma_channel_t enCh);
  264. void Dma_HaltTranfer(void);
  265. void Dma_RecoverTranfer(void);
  266. en_result_t Dma_PauseChannelTranfer(en_dma_channel_t enCh);
  267. en_result_t Dma_RecoverChannelTranfer(en_dma_channel_t enCh);
  268. en_result_t Dma_SetTransferWidth(en_dma_channel_t enCh, en_dma_transfer_width_t enWidth);
  269. en_result_t Dma_SetChPriority(en_dma_priority_t enPrio);
  270. en_result_t Dma_EnableChannelIrq(en_dma_channel_t enCh);
  271. en_result_t Dma_DisableChannelIrq(en_dma_channel_t enCh);
  272. en_result_t Dma_EnableChannelErrIrq(en_dma_channel_t enCh);
  273. en_result_t Dma_DisableChannelErrIrq(en_dma_channel_t enCh);
  274. en_result_t Dma_ConfigIrq(en_dma_channel_t enCh,stc_dma_irq_sel_t* stcDmaIrqCfg,stc_dma_irq_calbakfn_pt_t* pstcDmaIrqCalbaks);
  275. en_dma_stat_t Dma_GetStat(en_dma_channel_t enCh);
  276. void Dma_ClrStat(en_dma_channel_t enCh);
  277. //@} // DmacGroup
  278. #ifdef __cplusplus
  279. }
  280. #endif
  281. #endif /* __DMAC_H__ */
  282. /*******************************************************************************
  283. * EOF (not truncated)
  284. ******************************************************************************/