gd32f4xx_dma.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*!
  2. \file gd32f4xx_dma.h
  3. \brief definitions for the DMA
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.0, firmware for GD32F4xx
  8. */
  9. #ifndef GD32F4XX_DMA_H
  10. #define GD32F4XX_DMA_H
  11. #include "gd32f4xx.h"
  12. /* DMA definitions */
  13. #define DMA0 (DMA_BASE) /*!< DMA0 base address */
  14. #define DMA1 (DMA_BASE + 0x0400U) /*!< DMA1 base address */
  15. /* registers definitions */
  16. #define DMA_INTF0(dmax) REG32((dmax) + 0x00U) /*!< DMA interrupt flag register 0 */
  17. #define DMA_INTF1(dmax) REG32((dmax) + 0x04U) /*!< DMA interrupt flag register 1 */
  18. #define DMA_INTC0(dmax) REG32((dmax) + 0x08U) /*!< DMA interrupt flag clear register 0 */
  19. #define DMA_INTC1(dmax) REG32((dmax) + 0x0CU) /*!< DMA interrupt flag clear register 1 */
  20. #define DMA_CH0CTL(dmax) REG32((dmax) + 0x10U) /*!< DMA channel 0 control register */
  21. #define DMA_CH0CNT(dmax) REG32((dmax) + 0x14U) /*!< DMA channel 0 counter register */
  22. #define DMA_CH0PADDR(dmax) REG32((dmax) + 0x18U) /*!< DMA channel 0 peripheral base address register */
  23. #define DMA_CH0M0ADDR(dmax) REG32((dmax) + 0x1CU) /*!< DMA channel 0 memory 0 base address register */
  24. #define DMA_CH0M1ADDR(dmax) REG32((dmax) + 0x20U) /*!< DMA channel 0 memory 1 base address register */
  25. #define DMA_CH0FCTL(dmax) REG32((dmax) + 0x24U) /*!< DMA channel 0 FIFO control register */
  26. #define DMA_CH1CTL(dmax) REG32((dmax) + 0x28U) /*!< DMA channel 1 control register */
  27. #define DMA_CH1CNT(dmax) REG32((dmax) + 0x2CU) /*!< DMA channel 1 counter register */
  28. #define DMA_CH1PADDR(dmax) REG32((dmax) + 0x30U) /*!< DMA channel 1 peripheral base address register */
  29. #define DMA_CH1M0ADDR(dmax) REG32((dmax) + 0x34U) /*!< DMA channel 1 memory 0 base address register */
  30. #define DMA_CH1M1ADDR(dmax) REG32((dmax) + 0x38U) /*!< DMA channel 1 memory 1 base address register */
  31. #define DMA_CH1FCTL(dmax) REG32((dmax) + 0x3CU) /*!< DMA channel 1 FIFO control register */
  32. #define DMA_CH2CTL(dmax) REG32((dmax) + 0x40U) /*!< DMA channel 2 control register */
  33. #define DMA_CH2CNT(dmax) REG32((dmax) + 0x44U) /*!< DMA channel 2 counter register */
  34. #define DMA_CH2PADDR(dmax) REG32((dmax) + 0x48U) /*!< DMA channel 2 peripheral base address register */
  35. #define DMA_CH2M0ADDR(dmax) REG32((dmax) + 0x4CU) /*!< DMA channel 2 memory 0 base address register */
  36. #define DMA_CH2M1ADDR(dmax) REG32((dmax) + 0x50U) /*!< DMA channel 2 memory 1 base address register */
  37. #define DMA_CH2FCTL(dmax) REG32((dmax) + 0x54U) /*!< DMA channel 2 FIFO control register */
  38. #define DMA_CH3CTL(dmax) REG32((dmax) + 0x58U) /*!< DMA channel 3 control register */
  39. #define DMA_CH3CNT(dmax) REG32((dmax) + 0x5CU) /*!< DMA channel 3 counter register */
  40. #define DMA_CH3PADDR(dmax) REG32((dmax) + 0x60U) /*!< DMA channel 3 peripheral base address register */
  41. #define DMA_CH3M0ADDR(dmax) REG32((dmax) + 0x64U) /*!< DMA channel 3 memory 0 base address register */
  42. #define DMA_CH3M1ADDR(dmax) REG32((dmax) + 0x68U) /*!< DMA channel 3 memory 1 base address register */
  43. #define DMA_CH3FCTL(dmax) REG32((dmax) + 0x6CU) /*!< DMA channel 3 FIFO control register */
  44. #define DMA_CH4CTL(dmax) REG32((dmax) + 0x70U) /*!< DMA channel 4 control register */
  45. #define DMA_CH4CNT(dmax) REG32((dmax) + 0x74U) /*!< DMA channel 4 counter register */
  46. #define DMA_CH4PADDR(dmax) REG32((dmax) + 0x78U) /*!< DMA channel 4 peripheral base address register */
  47. #define DMA_CH4M0ADDR(dmax) REG32((dmax) + 0x7CU) /*!< DMA channel 4 memory 0 base address register */
  48. #define DMA_CH4M1ADDR(dmax) REG32((dmax) + 0x80U) /*!< DMA channel 4 memory 1 base address register */
  49. #define DMA_CH4FCTL(dmax) REG32((dmax) + 0x84U) /*!< DMA channel 4 FIFO control register */
  50. #define DMA_CH5CTL(dmax) REG32((dmax) + 0x88U) /*!< DMA channel 5 control register */
  51. #define DMA_CH5CNT(dmax) REG32((dmax) + 0x8CU) /*!< DMA channel 5 counter register */
  52. #define DMA_CH5PADDR(dmax) REG32((dmax) + 0x90U) /*!< DMA channel 5 peripheral base address register */
  53. #define DMA_CH5M0ADDR(dmax) REG32((dmax) + 0x94U) /*!< DMA channel 5 memory 0 base address register */
  54. #define DMA_CH5M1ADDR(dmax) REG32((dmax) + 0x98U) /*!< DMA channel 5 memory 1 base address register */
  55. #define DMA_CH5FCTL(dmax) REG32((dmax) + 0x9CU) /*!< DMA channel 5 FIFO control register */
  56. #define DMA_CH6CTL(dmax) REG32((dmax) + 0xA0U) /*!< DMA channel 6 control register */
  57. #define DMA_CH6CNT(dmax) REG32((dmax) + 0xA4U) /*!< DMA channel 6 counter register */
  58. #define DMA_CH6PADDR(dmax) REG32((dmax) + 0xA8U) /*!< DMA channel 6 peripheral base address register */
  59. #define DMA_CH6M0ADDR(dmax) REG32((dmax) + 0xACU) /*!< DMA channel 6 memory 0 base address register */
  60. #define DMA_CH6M1ADDR(dmax) REG32((dmax) + 0xB0U) /*!< DMA channel 6 memory 1 base address register */
  61. #define DMA_CH6FCTL(dmax) REG32((dmax) + 0xB4U) /*!< DMA channel 6 FIFO control register */
  62. #define DMA_CH7CTL(dmax) REG32((dmax) + 0xB8U) /*!< DMA channel 7 control register */
  63. #define DMA_CH7CNT(dmax) REG32((dmax) + 0xBCU) /*!< DMA channel 7 counter register */
  64. #define DMA_CH7PADDR(dmax) REG32((dmax) + 0xC0U) /*!< DMA channel 7 peripheral base address register */
  65. #define DMA_CH7M0ADDR(dmax) REG32((dmax) + 0xC4U) /*!< DMA channel 7 memory 0 base address register */
  66. #define DMA_CH7M1ADDR(dmax) REG32((dmax) + 0xC8U) /*!< DMA channel 7 memory 1 base address register */
  67. #define DMA_CH7FCTL(dmax) REG32((dmax) + 0xCCU) /*!< DMA channel 7 FIFO control register */
  68. /* bits definitions */
  69. /* DMA_INTF */
  70. #define DMA_INTF_FEEIF BIT(0) /*!< FIFO error and exception flag */
  71. #define DMA_INTF_SDEIF BIT(2) /*!< single data mode exception flag */
  72. #define DMA_INTF_TAEIF BIT(3) /*!< transfer access error flag */
  73. #define DMA_INTF_HTFIF BIT(4) /*!< half transfer finish flag */
  74. #define DMA_INTF_FTFIF BIT(5) /*!< full transger finish flag */
  75. /* DMA_INTC */
  76. #define DMA_INTC_FEEIFC BIT(0) /*!< clear FIFO error and exception flag */
  77. #define DMA_INTC_SDEIFC BIT(2) /*!< clear single data mode exception flag */
  78. #define DMA_INTC_TAEIFC BIT(3) /*!< clear single data mode exception flag */
  79. #define DMA_INTC_HTFIFC BIT(4) /*!< clear half transfer finish flag */
  80. #define DMA_INTC_FTFIFC BIT(5) /*!< clear full transger finish flag */
  81. /* DMA_CHxCTL,x=0..7 */
  82. #define DMA_CHXCTL_CHEN BIT(0) /*!< channel x enable */
  83. #define DMA_CHXCTL_SDEIE BIT(1) /*!< enable bit for channel x single data mode exception interrupt */
  84. #define DMA_CHXCTL_TAEIE BIT(2) /*!< enable bit for channel x tranfer access error interrupt */
  85. #define DMA_CHXCTL_HTFIE BIT(3) /*!< enable bit for channel x half transfer finish interrupt */
  86. #define DMA_CHXCTL_FTFIE BIT(4) /*!< enable bit for channel x full transfer finish interrupt */
  87. #define DMA_CHXCTL_TFCS BIT(5) /*!< transfer flow controller select */
  88. #define DMA_CHXCTL_TM BITS(6,7) /*!< transfer mode */
  89. #define DMA_CHXCTL_CMEN BIT(8) /*!< circulation mode */
  90. #define DMA_CHXCTL_PNAGA BIT(9) /*!< next address generation algorithm of peripheral */
  91. #define DMA_CHXCTL_MNAGA BIT(10) /*!< next address generation algorithm of memory */
  92. #define DMA_CHXCTL_PWIDTH BITS(11,12) /*!< transfer width of peipheral */
  93. #define DMA_CHXCTL_MWIDTH BITS(13,14) /*!< transfer width of memory */
  94. #define DMA_CHXCTL_PAIF BIT(15) /*!< peripheral address increment fixed */
  95. #define DMA_CHXCTL_PRIO BITS(16,17) /*!< priority level */
  96. #define DMA_CHXCTL_SBMEN BIT(18) /*!< switch-buffer mode enable */
  97. #define DMA_CHXCTL_MBS BIT(19) /*!< memory buffer select */
  98. #define DMA_CHXCTL_PBURST BITS(21,22) /*!< transfer burst type of peripheral */
  99. #define DMA_CHXCTL_MBURST BITS(23,24) /*!< transfer burst type of memory */
  100. #define DMA_CHXCTL_PERIEN BITS(25,27) /*!< peripheral enable */
  101. /* DMA_CHxCNT,x=0..7 */
  102. #define DMA_CHXCNT_CNT BITS(0,15) /*!< transfer counter */
  103. /* DMA_CHxPADDR,x=0..7 */
  104. #define DMA_CHXPADDR_PADDR BITS(0,31) /*!< peripheral base address */
  105. /* DMA_CHxM0ADDR,x=0..7 */
  106. #define DMA_CHXM0ADDR_PADDR BITS(0,31) /*!< memory 0 base address */
  107. /* DMA_CHxM1ADDR,x=0..7 */
  108. #define DMA_CHXM1ADDR_PADDR BITS(0,31) /*!< memory 1 base address */
  109. /* DMA_CHxFCTL,x=0..7 */
  110. #define DMA_CHXFCTL_FCCV BITS(0,1) /*!< FIFO counter critical value */
  111. #define DMA_CHXFCTL_MDMEN BIT(2) /*!< multi-data mode enable */
  112. #define DMA_CHXFCTL_FCNT BITS(3,5) /*!< FIFO counter */
  113. #define DMA_CHXFCTL_FEEIE BIT(7) /*!< FIFO exception interrupt enable */
  114. /* constants definitions */
  115. /* DMA channel select */
  116. typedef enum
  117. {
  118. DMA_CH0 = 0, /*!< DMA Channel 0 */
  119. DMA_CH1, /*!< DMA Channel 1 */
  120. DMA_CH2, /*!< DMA Channel 2 */
  121. DMA_CH3, /*!< DMA Channel 3 */
  122. DMA_CH4, /*!< DMA Channel 4 */
  123. DMA_CH5, /*!< DMA Channel 5 */
  124. DMA_CH6, /*!< DMA Channel 6 */
  125. DMA_CH7 /*!< DMA Channel 7 */
  126. } dma_channel_enum;
  127. /* DMA peripheral select */
  128. typedef enum
  129. {
  130. DMA_SUBPERI0 = 0, /*!< DMA Peripheral 0 */
  131. DMA_SUBPERI1, /*!< DMA Peripheral 1 */
  132. DMA_SUBPERI2, /*!< DMA Peripheral 2 */
  133. DMA_SUBPERI3, /*!< DMA Peripheral 3 */
  134. DMA_SUBPERI4, /*!< DMA Peripheral 4 */
  135. DMA_SUBPERI5, /*!< DMA Peripheral 5 */
  136. DMA_SUBPERI6, /*!< DMA Peripheral 6 */
  137. DMA_SUBPERI7 /*!< DMA Peripheral 7 */
  138. } dma_subperipheral_enum;
  139. /* DMA multidata mode initialize struct */
  140. typedef struct
  141. {
  142. uint32_t periph_addr; /*!< peripheral base address */
  143. uint32_t periph_width; /*!< transfer data size of peripheral */
  144. uint32_t periph_inc; /*!< peripheral increasing mode */
  145. uint32_t memory0_addr; /*!< memory 0 base address */
  146. uint32_t memory_width; /*!< transfer data size of memory */
  147. uint32_t memory_inc; /*!< memory increasing mode */
  148. uint32_t memory_burst_width; /*!< multi data mode enable */
  149. uint32_t periph_burst_width; /*!< multi data mode enable */
  150. uint32_t critical_value; /*!< FIFO critical */
  151. uint32_t circular_mode;
  152. uint32_t direction; /*!< channel data transfer direction */
  153. uint32_t number; /*!< channel transfer number */
  154. uint32_t priority; /*!< channel priority level */
  155. }dma_multi_data_parameter_struct;
  156. /* DMA singledata mode initialize struct */
  157. typedef struct
  158. {
  159. uint32_t periph_addr; /*!< peripheral base address */
  160. uint32_t periph_inc; /*!< peripheral increasing mode */
  161. uint32_t memory0_addr; /*!< memory 0 base address */
  162. uint32_t memory_inc; /*!< memory increasing mode */
  163. uint32_t periph_memory_width; /*!< transfer data size of peripheral */
  164. uint32_t circular_mode; /*!< DMA circular mode */
  165. uint32_t direction; /*!< channel data transfer direction */
  166. uint32_t number; /*!< channel transfer number */
  167. uint32_t priority; /*!< channel priority level */
  168. } dma_single_data_parameter_struct;
  169. #define DMA_FLAG_ADD(flag,channel) ((uint32_t)((flag)<<((((uint32_t)(channel)*6U))+((uint32_t)(((uint32_t)(channel)) >> 1U)&0x01U)*4U))) /*!< DMA channel flag shift */
  170. /* DMA_register address */
  171. #define DMA_CHCTL(dma,channel) REG32(((dma) + 0x10U) + 0x18U*(channel)) /*!< the address of DMA channel CHXCTL register */
  172. #define DMA_CHCNT(dma,channel) REG32(((dma) + 0x14U) + 0x18U*(channel)) /*!< the address of DMA channel CHXCNT register */
  173. #define DMA_CHPADDR(dma,channel) REG32(((dma) + 0x18U) + 0x18U*(channel)) /*!< the address of DMA channel CHXPADDR register */
  174. #define DMA_CHM0ADDR(dma,channel) REG32(((dma) + 0x1CU) + 0x18U*(channel)) /*!< the address of DMA channel CHXM0ADDR register */
  175. #define DMA_CHM1ADDR(dma,channel) REG32(((dma) + 0x20U) + 0x18U*(channel)) /*!< the address of DMA channel CHXM1ADDR register */
  176. #define DMA_CHFCTL(dma,channel) REG32(((dma) + 0x24U) + 0x18U*(channel)) /*!< the address of DMA channel CHXMADDR register */
  177. /* peripheral select */
  178. #define CHCTL_PERIEN(regval) (BITS(25,27) & ((uint32_t)(regval) << 25))
  179. #define DMA_PERIPH_0_SELECT CHCTL_PERIEN(0) /*!< peripheral 0 select */
  180. #define DMA_PERIPH_1_SELECT CHCTL_PERIEN(1) /*!< peripheral 1 select */
  181. #define DMA_PERIPH_2_SELECT CHCTL_PERIEN(2) /*!< peripheral 2 select */
  182. #define DMA_PERIPH_3_SELECT CHCTL_PERIEN(3) /*!< peripheral 3 select */
  183. #define DMA_PERIPH_4_SELECT CHCTL_PERIEN(4) /*!< peripheral 4 select */
  184. #define DMA_PERIPH_5_SELECT CHCTL_PERIEN(5) /*!< peripheral 5 select */
  185. #define DMA_PERIPH_6_SELECT CHCTL_PERIEN(6) /*!< peripheral 6 select */
  186. #define DMA_PERIPH_7_SELECT CHCTL_PERIEN(7) /*!< peripheral 7 select */
  187. /* burst type of memory */
  188. #define CHCTL_MBURST(regval) (BITS(23,24) & ((uint32_t)(regval) << 23))
  189. #define DMA_MEMORY_BURST_SINGLE CHCTL_MBURST(0) /*!< single burst */
  190. #define DMA_MEMORY_BURST_4_BEAT CHCTL_MBURST(1) /*!< 4-beat burst */
  191. #define DMA_MEMORY_BURST_8_BEAT CHCTL_MBURST(2) /*!< 8-beat burst */
  192. #define DMA_MEMORY_BURST_16_BEAT CHCTL_MBURST(3) /*!< 16-beat burst */
  193. /* burst type of peripheral */
  194. #define CHCTL_PBURST(regval) (BITS(21,22) & ((uint32_t)(regval) << 21))
  195. #define DMA_PERIPH_BURST_SINGLE CHCTL_PBURST(0) /*!< single burst */
  196. #define DMA_PERIPH_BURST_4_BEAT CHCTL_PBURST(1) /*!< 4-beat burst */
  197. #define DMA_PERIPH_BURST_8_BEAT CHCTL_PBURST(2) /*!< 8-beat burst */
  198. #define DMA_PERIPH_BURST_16_BEAT CHCTL_PBURST(3) /*!< 16-beat burst */
  199. /* channel priority level */
  200. #define CHCTL_PRIO(regval) (BITS(16,17) & ((uint32_t)(regval) << 16))
  201. #define DMA_PRIORITY_LOW CHCTL_PRIO(0) /*!< low priority */
  202. #define DMA_PRIORITY_MEDIUM CHCTL_PRIO(1) /*!< medium priority */
  203. #define DMA_PRIORITY_HIGH CHCTL_PRIO(2) /*!< high priority */
  204. #define DMA_PRIORITY_ULTRA_HIGH CHCTL_PRIO(3) /*!< ultra high priority */
  205. /* transfer data width of memory */
  206. #define CHCTL_MWIDTH(regval) (BITS(13,14) & ((uint32_t)(regval) << 13))
  207. #define DMA_MEMORY_WIDTH_8BIT CHCTL_MWIDTH(0) /*!< transfer data width of memory is 8-bit */
  208. #define DMA_MEMORY_WIDTH_16BIT CHCTL_MWIDTH(1) /*!< transfer data width of memory is 16-bit */
  209. #define DMA_MEMORY_WIDTH_32BIT CHCTL_MWIDTH(2) /*!< transfer data width of memory is 32-bit */
  210. /* transfer data width of peripheral */
  211. #define CHCTL_PWIDTH(regval) (BITS(11,12) & ((uint32_t)(regval) << 11))
  212. #define DMA_PERIPH_WIDTH_8BIT CHCTL_PWIDTH(0) /*!< transfer data width of peripheral is 8-bit */
  213. #define DMA_PERIPH_WIDTH_16BIT CHCTL_PWIDTH(1) /*!< transfer data width of peripheral is 16-bit */
  214. #define DMA_PERIPH_WIDTH_32BIT CHCTL_PWIDTH(2) /*!< transfer data width of peripheral is 32-bit */
  215. /* channel transfer mode */
  216. #define CHCTL_TM(regval) (BITS(6,7) & ((uint32_t)(regval) << 6))
  217. #define DMA_PERIPH_TO_MEMORY CHCTL_TM(0) /*!< read from peripheral and write to memory */
  218. #define DMA_MEMORY_TO_PERIPH CHCTL_TM(1) /*!< read from memory and write to peripheral */
  219. #define DMA_MEMORY_TO_MEMORY CHCTL_TM(2) /*!< read from memory and write to memory */
  220. /* FIFO counter critical value */
  221. #define CHFCTL_FCCV(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
  222. #define DMA_FIFO_1_WORD CHFCTL_FCCV(0) /*!< critical value 1 word */
  223. #define DMA_FIFO_2_WORD CHFCTL_FCCV(1) /*!< critical value 2 word */
  224. #define DMA_FIFO_3_WORD CHFCTL_FCCV(2) /*!< critical value 3 word */
  225. #define DMA_FIFO_4_WORD CHFCTL_FCCV(3) /*!< critical value 4 word */
  226. /* memory select */
  227. #define DMA_MEMORY_0 ((uint32_t)0x00000000U) /*!< select memory 0 */
  228. #define DMA_MEMORY_1 ((uint32_t)0x00000001U) /*!< select memory 1 */
  229. /* DMA circular mode */
  230. #define DMA_CIRCULAR_MODE_ENABLE ((uint32_t)0x00000000U) /*!< circular mode enable */
  231. #define DMA_CIRCULAR_MODE_DISABLE ((uint32_t)0x00000001U) /*!< circular mode disable */
  232. /* DMA flow controller select */
  233. #define DMA_FLOW_CONTROLLER_DMA ((uint32_t)0x00000000U) /*!< DMA is the flow controler */
  234. #define DMA_FLOW_CONTROLLER_PERI ((uint32_t)0x00000001U) /*!< peripheral is the flow controler */
  235. /* peripheral increasing mode */
  236. #define DMA_PERIPH_INCREASE_ENABLE ((uint32_t)0x00000000U) /*!< next address of peripheral is increasing address mode */
  237. #define DMA_PERIPH_INCREASE_DISABLE ((uint32_t)0x00000001U) /*!< next address of peripheral is fixed address mode */
  238. #define DMA_PERIPH_INCREASE_FIX ((uint32_t)0x00000002U) /*!< next address of peripheral is increasing fixed */
  239. /* memory increasing mode */
  240. #define DMA_MEMORY_INCREASE_ENABLE ((uint32_t)0x00000000U) /*!< next address of memory is increasing address mode */
  241. #define DMA_MEMORY_INCREASE_DISABLE ((uint32_t)0x00000001U) /*!< next address of memory is fixed address mode */
  242. /* FIFO status */
  243. #define DMA_FIFO_STATUS_NODATA ((uint32_t)0x00000000U) /*!< the data in the FIFO less than 1 word */
  244. #define DMA_FIFO_STATUS_1_WORD ((uint32_t)0x00000001U) /*!< the data in the FIFO more than 1 word, less than 2 words */
  245. #define DMA_FIFO_STATUS_2_WORD ((uint32_t)0x00000002U) /*!< the data in the FIFO more than 2 word, less than 3 words */
  246. #define DMA_FIFO_STATUS_3_WORD ((uint32_t)0x00000003U) /*!< the data in the FIFO more than 3 word, less than 4 words */
  247. #define DMA_FIFO_STATUS_EMPTY ((uint32_t)0x00000004U) /*!< the data in the FIFO is empty */
  248. #define DMA_FIFO_STATUS_FULL ((uint32_t)0x00000005U) /*!< the data in the FIFO is full */
  249. /* DMA reset value */
  250. #define DMA_CHCTL_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXCTL register */
  251. #define DMA_CHCNT_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXCNT register */
  252. #define DMA_CHPADDR_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXPADDR register */
  253. #define DMA_CHMADDR_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXMADDR register */
  254. #define DMA_CHINTF_RESET_VALUE ((uint32_t)0x0000003DU) /*!< clear DMA channel CHXINTFS register */
  255. #define DMA_CHFCTL_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXFCTL register */
  256. /* function declarations */
  257. /* deinitialize DMA a channel registers */
  258. void dma_deinit(uint32_t dma_periph,dma_channel_enum channelx);
  259. /* DMA single data mode initialize */
  260. void dma_single_data_mode_init(uint32_t dma_periph,dma_channel_enum channelx,dma_single_data_parameter_struct init_struct);
  261. /* DMA multi data mode initialize */
  262. void dma_multi_data_mode_init(uint32_t dma_periph,dma_channel_enum channelx,dma_multi_data_parameter_struct init_struct);
  263. /* set DMA peripheral base address */
  264. void dma_periph_address_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t address);
  265. /* set DMA Memory base address */
  266. void dma_memory_address_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t memory_flag,uint32_t address);
  267. /* set the number of remaining data to be transferred by the DMA */
  268. void dma_transfer_number_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t number);
  269. /* get the number of remaining data to be transferred by the DMA */
  270. uint32_t dma_transfer_number_get(uint32_t dma_periph,dma_channel_enum channelx);
  271. /* configure priority level of DMA channel */
  272. void dma_priority_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t priority);
  273. /* configure transfer burst beats of memory */
  274. void dma_memory_burst_beats_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t mbeat);
  275. /* configure transfer burst beats of peripheral */
  276. void dma_periph_burst_beats_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t pbeat);
  277. /* configure transfer data size of memory */
  278. void dma_memory_width_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t msize);
  279. /* configure transfer data size of peripheral */
  280. void dma_periph_width_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t psize);
  281. /* configure next address increasement algorithm of memory */
  282. void dma_memory_address_generation_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t generation_algorithm);
  283. /* configure next address increasement algorithm of peripheral */
  284. void dma_peripheral_address_generation_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t generation_algorithm);
  285. /* enable DMA circulation mode */
  286. void dma_circulation_enable(uint32_t dma_periph,dma_channel_enum channelx);
  287. /* disable DMA circulation mode */
  288. void dma_circulation_disable(uint32_t dma_periph,dma_channel_enum channelx);
  289. /* enable DMA channel */
  290. void dma_channel_enable(uint32_t dma_periph,dma_channel_enum channelx);
  291. /* disable DMA channel */
  292. void dma_channel_disable(uint32_t dma_periph,dma_channel_enum channelx);
  293. /* configure the direction of data transfer on the channel */
  294. void dma_transfer_direction_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t direction);
  295. /* DMA switch buffer mode config */
  296. void dma_switch_buffer_mode_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t memory1_addr,uint32_t memory_select);
  297. /* DMA using memory get */
  298. uint32_t dma_using_memory_get(uint32_t dma_periph,dma_channel_enum channelx);
  299. /* DMA channel peripheral select */
  300. void dma_channel_subperipheral_select(uint32_t dma_periph,dma_channel_enum channelx,dma_subperipheral_enum sub_periph);
  301. /* DMA flow controller configure */
  302. void dma_flow_controller_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t controller);
  303. /* DMA flow controller enable */
  304. void dma_switch_buffer_mode_enable(uint32_t dma_periph,dma_channel_enum channelx,ControlStatus newvalue);
  305. /* DMA FIFO status get */
  306. uint32_t dma_fifo_status_get(uint32_t dma_periph,dma_channel_enum channelx);
  307. /* check DMA flag is set or not */
  308. FlagStatus dma_flag_get(uint32_t dma_periph,dma_channel_enum channelx,uint32_t flag);
  309. /* clear DMA a channel flag */
  310. void dma_flag_clear(uint32_t dma_periph,dma_channel_enum channelx,uint32_t flag);
  311. /* check DMA flag is set or not */
  312. FlagStatus dma_interrupt_flag_get(uint32_t dma_periph,dma_channel_enum channelx,uint32_t interrupt);
  313. /* clear DMA a channel flag */
  314. void dma_interrupt_flag_clear(uint32_t dma_periph,dma_channel_enum channelx,uint32_t interrupt);
  315. /* enable DMA interrupt */
  316. void dma_interrupt_enable(uint32_t dma_periph,dma_channel_enum channelx,uint32_t source);
  317. /* disable DMA interrupt */
  318. void dma_interrupt_disable(uint32_t dma_periph,dma_channel_enum channelx,uint32_t source);
  319. #endif /* GD32F4XX_DMA_H */