ch32v30x_dma.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ch32v30x_dma.h
  3. * Author : WCH
  4. * Version : V1.0.0
  5. * Date : 2021/06/06
  6. * Description : This file contains all the functions prototypes for the
  7. * DMA firmware library.
  8. *********************************************************************************
  9. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  10. * Attention: This software (modified or not) and binary are used for
  11. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  12. *******************************************************************************/
  13. #ifndef __CH32V30x_DMA_H
  14. #define __CH32V30x_DMA_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "ch32v30x.h"
  19. /* DMA Init structure definition */
  20. typedef struct
  21. {
  22. uint32_t DMA_PeripheralBaseAddr; /* Specifies the peripheral base address for DMAy Channelx. */
  23. uint32_t DMA_MemoryBaseAddr; /* Specifies the memory base address for DMAy Channelx. */
  24. uint32_t DMA_DIR; /* Specifies if the peripheral is the source or destination.
  25. This parameter can be a value of @ref DMA_data_transfer_direction */
  26. uint32_t DMA_BufferSize; /* Specifies the buffer size, in data unit, of the specified Channel.
  27. The data unit is equal to the configuration set in DMA_PeripheralDataSize
  28. or DMA_MemoryDataSize members depending in the transfer direction. */
  29. uint32_t DMA_PeripheralInc; /* Specifies whether the Peripheral address register is incremented or not.
  30. This parameter can be a value of @ref DMA_peripheral_incremented_mode */
  31. uint32_t DMA_MemoryInc; /* Specifies whether the memory address register is incremented or not.
  32. This parameter can be a value of @ref DMA_memory_incremented_mode */
  33. uint32_t DMA_PeripheralDataSize; /* Specifies the Peripheral data width.
  34. This parameter can be a value of @ref DMA_peripheral_data_size */
  35. uint32_t DMA_MemoryDataSize; /* Specifies the Memory data width.
  36. This parameter can be a value of @ref DMA_memory_data_size */
  37. uint32_t DMA_Mode; /* Specifies the operation mode of the DMAy Channelx.
  38. This parameter can be a value of @ref DMA_circular_normal_mode.
  39. @note: The circular buffer mode cannot be used if the memory-to-memory
  40. data transfer is configured on the selected Channel */
  41. uint32_t DMA_Priority; /* Specifies the software priority for the DMAy Channelx.
  42. This parameter can be a value of @ref DMA_priority_level */
  43. uint32_t DMA_M2M; /* Specifies if the DMAy Channelx will be used in memory-to-memory transfer.
  44. This parameter can be a value of @ref DMA_memory_to_memory */
  45. }DMA_InitTypeDef;
  46. /* DMA_data_transfer_direction */
  47. #define DMA_DIR_PeripheralDST ((uint32_t)0x00000010)
  48. #define DMA_DIR_PeripheralSRC ((uint32_t)0x00000000)
  49. /* DMA_peripheral_incremented_mode */
  50. #define DMA_PeripheralInc_Enable ((uint32_t)0x00000040)
  51. #define DMA_PeripheralInc_Disable ((uint32_t)0x00000000)
  52. /* DMA_memory_incremented_mode */
  53. #define DMA_MemoryInc_Enable ((uint32_t)0x00000080)
  54. #define DMA_MemoryInc_Disable ((uint32_t)0x00000000)
  55. /* DMA_peripheral_data_size */
  56. #define DMA_PeripheralDataSize_Byte ((uint32_t)0x00000000)
  57. #define DMA_PeripheralDataSize_HalfWord ((uint32_t)0x00000100)
  58. #define DMA_PeripheralDataSize_Word ((uint32_t)0x00000200)
  59. /* DMA_memory_data_size */
  60. #define DMA_MemoryDataSize_Byte ((uint32_t)0x00000000)
  61. #define DMA_MemoryDataSize_HalfWord ((uint32_t)0x00000400)
  62. #define DMA_MemoryDataSize_Word ((uint32_t)0x00000800)
  63. /* DMA_circular_normal_mode */
  64. #define DMA_Mode_Circular ((uint32_t)0x00000020)
  65. #define DMA_Mode_Normal ((uint32_t)0x00000000)
  66. /* DMA_priority_level */
  67. #define DMA_Priority_VeryHigh ((uint32_t)0x00003000)
  68. #define DMA_Priority_High ((uint32_t)0x00002000)
  69. #define DMA_Priority_Medium ((uint32_t)0x00001000)
  70. #define DMA_Priority_Low ((uint32_t)0x00000000)
  71. /* DMA_memory_to_memory */
  72. #define DMA_M2M_Enable ((uint32_t)0x00004000)
  73. #define DMA_M2M_Disable ((uint32_t)0x00000000)
  74. /* DMA_interrupts_definition */
  75. #define DMA_IT_TC ((uint32_t)0x00000002)
  76. #define DMA_IT_HT ((uint32_t)0x00000004)
  77. #define DMA_IT_TE ((uint32_t)0x00000008)
  78. #define DMA1_IT_GL1 ((uint32_t)0x00000001)
  79. #define DMA1_IT_TC1 ((uint32_t)0x00000002)
  80. #define DMA1_IT_HT1 ((uint32_t)0x00000004)
  81. #define DMA1_IT_TE1 ((uint32_t)0x00000008)
  82. #define DMA1_IT_GL2 ((uint32_t)0x00000010)
  83. #define DMA1_IT_TC2 ((uint32_t)0x00000020)
  84. #define DMA1_IT_HT2 ((uint32_t)0x00000040)
  85. #define DMA1_IT_TE2 ((uint32_t)0x00000080)
  86. #define DMA1_IT_GL3 ((uint32_t)0x00000100)
  87. #define DMA1_IT_TC3 ((uint32_t)0x00000200)
  88. #define DMA1_IT_HT3 ((uint32_t)0x00000400)
  89. #define DMA1_IT_TE3 ((uint32_t)0x00000800)
  90. #define DMA1_IT_GL4 ((uint32_t)0x00001000)
  91. #define DMA1_IT_TC4 ((uint32_t)0x00002000)
  92. #define DMA1_IT_HT4 ((uint32_t)0x00004000)
  93. #define DMA1_IT_TE4 ((uint32_t)0x00008000)
  94. #define DMA1_IT_GL5 ((uint32_t)0x00010000)
  95. #define DMA1_IT_TC5 ((uint32_t)0x00020000)
  96. #define DMA1_IT_HT5 ((uint32_t)0x00040000)
  97. #define DMA1_IT_TE5 ((uint32_t)0x00080000)
  98. #define DMA1_IT_GL6 ((uint32_t)0x00100000)
  99. #define DMA1_IT_TC6 ((uint32_t)0x00200000)
  100. #define DMA1_IT_HT6 ((uint32_t)0x00400000)
  101. #define DMA1_IT_TE6 ((uint32_t)0x00800000)
  102. #define DMA1_IT_GL7 ((uint32_t)0x01000000)
  103. #define DMA1_IT_TC7 ((uint32_t)0x02000000)
  104. #define DMA1_IT_HT7 ((uint32_t)0x04000000)
  105. #define DMA1_IT_TE7 ((uint32_t)0x08000000)
  106. #define DMA2_IT_GL1 ((uint32_t)0x10000001)
  107. #define DMA2_IT_TC1 ((uint32_t)0x10000002)
  108. #define DMA2_IT_HT1 ((uint32_t)0x10000004)
  109. #define DMA2_IT_TE1 ((uint32_t)0x10000008)
  110. #define DMA2_IT_GL2 ((uint32_t)0x10000010)
  111. #define DMA2_IT_TC2 ((uint32_t)0x10000020)
  112. #define DMA2_IT_HT2 ((uint32_t)0x10000040)
  113. #define DMA2_IT_TE2 ((uint32_t)0x10000080)
  114. #define DMA2_IT_GL3 ((uint32_t)0x10000100)
  115. #define DMA2_IT_TC3 ((uint32_t)0x10000200)
  116. #define DMA2_IT_HT3 ((uint32_t)0x10000400)
  117. #define DMA2_IT_TE3 ((uint32_t)0x10000800)
  118. #define DMA2_IT_GL4 ((uint32_t)0x10001000)
  119. #define DMA2_IT_TC4 ((uint32_t)0x10002000)
  120. #define DMA2_IT_HT4 ((uint32_t)0x10004000)
  121. #define DMA2_IT_TE4 ((uint32_t)0x10008000)
  122. #define DMA2_IT_GL5 ((uint32_t)0x10010000)
  123. #define DMA2_IT_TC5 ((uint32_t)0x10020000)
  124. #define DMA2_IT_HT5 ((uint32_t)0x10040000)
  125. #define DMA2_IT_TE5 ((uint32_t)0x10080000)
  126. #define DMA2_IT_GL6 ((uint32_t)0x10100000)
  127. #define DMA2_IT_TC6 ((uint32_t)0x10200000)
  128. #define DMA2_IT_HT6 ((uint32_t)0x10400000)
  129. #define DMA2_IT_TE6 ((uint32_t)0x10800000)
  130. #define DMA2_IT_GL7 ((uint32_t)0x11000000)
  131. #define DMA2_IT_TC7 ((uint32_t)0x12000000)
  132. #define DMA2_IT_HT7 ((uint32_t)0x14000000)
  133. #define DMA2_IT_TE7 ((uint32_t)0x18000000)
  134. #define DMA2_IT_GL8 ((uint32_t)0x20000001)
  135. #define DMA2_IT_TC8 ((uint32_t)0x20000002)
  136. #define DMA2_IT_HT8 ((uint32_t)0x20000004)
  137. #define DMA2_IT_TE8 ((uint32_t)0x20000008)
  138. #define DMA2_IT_GL9 ((uint32_t)0x20000010)
  139. #define DMA2_IT_TC9 ((uint32_t)0x20000020)
  140. #define DMA2_IT_HT9 ((uint32_t)0x20000040)
  141. #define DMA2_IT_TE9 ((uint32_t)0x20000080)
  142. #define DMA2_IT_GL10 ((uint32_t)0x20000100)
  143. #define DMA2_IT_TC10 ((uint32_t)0x20000200)
  144. #define DMA2_IT_HT10 ((uint32_t)0x20000400)
  145. #define DMA2_IT_TE10 ((uint32_t)0x20000800)
  146. #define DMA2_IT_GL11 ((uint32_t)0x20001000)
  147. #define DMA2_IT_TC11 ((uint32_t)0x20002000)
  148. #define DMA2_IT_HT11 ((uint32_t)0x20004000)
  149. #define DMA2_IT_TE11 ((uint32_t)0x20008000)
  150. /* DMA_flags_definition */
  151. #define DMA1_FLAG_GL1 ((uint32_t)0x00000001)
  152. #define DMA1_FLAG_TC1 ((uint32_t)0x00000002)
  153. #define DMA1_FLAG_HT1 ((uint32_t)0x00000004)
  154. #define DMA1_FLAG_TE1 ((uint32_t)0x00000008)
  155. #define DMA1_FLAG_GL2 ((uint32_t)0x00000010)
  156. #define DMA1_FLAG_TC2 ((uint32_t)0x00000020)
  157. #define DMA1_FLAG_HT2 ((uint32_t)0x00000040)
  158. #define DMA1_FLAG_TE2 ((uint32_t)0x00000080)
  159. #define DMA1_FLAG_GL3 ((uint32_t)0x00000100)
  160. #define DMA1_FLAG_TC3 ((uint32_t)0x00000200)
  161. #define DMA1_FLAG_HT3 ((uint32_t)0x00000400)
  162. #define DMA1_FLAG_TE3 ((uint32_t)0x00000800)
  163. #define DMA1_FLAG_GL4 ((uint32_t)0x00001000)
  164. #define DMA1_FLAG_TC4 ((uint32_t)0x00002000)
  165. #define DMA1_FLAG_HT4 ((uint32_t)0x00004000)
  166. #define DMA1_FLAG_TE4 ((uint32_t)0x00008000)
  167. #define DMA1_FLAG_GL5 ((uint32_t)0x00010000)
  168. #define DMA1_FLAG_TC5 ((uint32_t)0x00020000)
  169. #define DMA1_FLAG_HT5 ((uint32_t)0x00040000)
  170. #define DMA1_FLAG_TE5 ((uint32_t)0x00080000)
  171. #define DMA1_FLAG_GL6 ((uint32_t)0x00100000)
  172. #define DMA1_FLAG_TC6 ((uint32_t)0x00200000)
  173. #define DMA1_FLAG_HT6 ((uint32_t)0x00400000)
  174. #define DMA1_FLAG_TE6 ((uint32_t)0x00800000)
  175. #define DMA1_FLAG_GL7 ((uint32_t)0x01000000)
  176. #define DMA1_FLAG_TC7 ((uint32_t)0x02000000)
  177. #define DMA1_FLAG_HT7 ((uint32_t)0x04000000)
  178. #define DMA1_FLAG_TE7 ((uint32_t)0x08000000)
  179. #define DMA2_FLAG_GL1 ((uint32_t)0x10000001)
  180. #define DMA2_FLAG_TC1 ((uint32_t)0x10000002)
  181. #define DMA2_FLAG_HT1 ((uint32_t)0x10000004)
  182. #define DMA2_FLAG_TE1 ((uint32_t)0x10000008)
  183. #define DMA2_FLAG_GL2 ((uint32_t)0x10000010)
  184. #define DMA2_FLAG_TC2 ((uint32_t)0x10000020)
  185. #define DMA2_FLAG_HT2 ((uint32_t)0x10000040)
  186. #define DMA2_FLAG_TE2 ((uint32_t)0x10000080)
  187. #define DMA2_FLAG_GL3 ((uint32_t)0x10000100)
  188. #define DMA2_FLAG_TC3 ((uint32_t)0x10000200)
  189. #define DMA2_FLAG_HT3 ((uint32_t)0x10000400)
  190. #define DMA2_FLAG_TE3 ((uint32_t)0x10000800)
  191. #define DMA2_FLAG_GL4 ((uint32_t)0x10001000)
  192. #define DMA2_FLAG_TC4 ((uint32_t)0x10002000)
  193. #define DMA2_FLAG_HT4 ((uint32_t)0x10004000)
  194. #define DMA2_FLAG_TE4 ((uint32_t)0x10008000)
  195. #define DMA2_FLAG_GL5 ((uint32_t)0x10010000)
  196. #define DMA2_FLAG_TC5 ((uint32_t)0x10020000)
  197. #define DMA2_FLAG_HT5 ((uint32_t)0x10040000)
  198. #define DMA2_FLAG_TE5 ((uint32_t)0x10080000)
  199. #define DMA2_FLAG_GL6 ((uint32_t)0x10100000)
  200. #define DMA2_FLAG_TC6 ((uint32_t)0x10200000)
  201. #define DMA2_FLAG_HT6 ((uint32_t)0x10400000)
  202. #define DMA2_FLAG_TE6 ((uint32_t)0x10800000)
  203. #define DMA2_FLAG_GL7 ((uint32_t)0x11000000)
  204. #define DMA2_FLAG_TC7 ((uint32_t)0x12000000)
  205. #define DMA2_FLAG_HT7 ((uint32_t)0x14000000)
  206. #define DMA2_FLAG_TE7 ((uint32_t)0x18000000)
  207. #define DMA2_FLAG_GL8 ((uint32_t)0x20000001)
  208. #define DMA2_FLAG_TC8 ((uint32_t)0x20000002)
  209. #define DMA2_FLAG_HT8 ((uint32_t)0x20000004)
  210. #define DMA2_FLAG_TE8 ((uint32_t)0x20000008)
  211. #define DMA2_FLAG_GL9 ((uint32_t)0x20000010)
  212. #define DMA2_FLAG_TC9 ((uint32_t)0x20000020)
  213. #define DMA2_FLAG_HT9 ((uint32_t)0x20000040)
  214. #define DMA2_FLAG_TE9 ((uint32_t)0x20000080)
  215. #define DMA2_FLAG_GL10 ((uint32_t)0x20000100)
  216. #define DMA2_FLAG_TC10 ((uint32_t)0x20000200)
  217. #define DMA2_FLAG_HT10 ((uint32_t)0x20000400)
  218. #define DMA2_FLAG_TE10 ((uint32_t)0x20000800)
  219. #define DMA2_FLAG_GL11 ((uint32_t)0x20001000)
  220. #define DMA2_FLAG_TC11 ((uint32_t)0x20002000)
  221. #define DMA2_FLAG_HT11 ((uint32_t)0x20004000)
  222. #define DMA2_FLAG_TE11 ((uint32_t)0x20008000)
  223. void DMA_DeInit(DMA_Channel_TypeDef* DMAy_Channelx);
  224. void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct);
  225. void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct);
  226. void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState);
  227. void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState);
  228. void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx, uint16_t DataNumber);
  229. uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx);
  230. FlagStatus DMA_GetFlagStatus(uint32_t DMAy_FLAG);
  231. void DMA_ClearFlag(uint32_t DMAy_FLAG);
  232. ITStatus DMA_GetITStatus(uint32_t DMAy_IT);
  233. void DMA_ClearITPendingBit(uint32_t DMAy_IT);
  234. #ifdef __cplusplus
  235. }
  236. #endif
  237. #endif