at32f421_dma.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /**
  2. **************************************************************************
  3. * @file at32f421_dma.h
  4. * @brief at32f421 dma header file
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. /**
  25. at32f421 dma1 channel request(fixed) as folleow :
  26. ------------------------------------------------------------------------------------------------------
  27. peripherals | channel1 | channel2 | channel3 | channel4 | channel5
  28. ------------------------------------------------------------------------------------------------------
  29. adc | adc | | | |
  30. ------------------------------------------------------------------------------------------------------
  31. spi/i2s | | spi1/i2s1_rx | spi1/i2s1_tx | spi2/i2s2_rx | spi2/i2s2_tx
  32. ------------------------------------------------------------------------------------------------------
  33. usart1 | | usart1_tx | usart1_rx | usart1_tx | usart1_rx
  34. ------------------------------------------------------------------------------------------------------
  35. usart2 | | | | usart2_tx | usart2_rx
  36. ------------------------------------------------------------------------------------------------------
  37. i2c | | i2c1_tx | i2c1_rx | i2c2_tx | i2c2_rx
  38. ------------------------------------------------------------------------------------------------------
  39. | | | | tmr1_ch4 | tmr1_ch3
  40. tmr1 | | tmr1_ch1 | tmr1_ch2 | tmr1_trig | tmr1_overflow
  41. | | | | tmr1_hall |
  42. ------------------------------------------------------------------------------------------------------
  43. tmr3 | | tmr3_ch3 | tmr3_ch4 | tmr3_ch1 |
  44. | | | tmr3_overflow | tmr3_trig |
  45. ------------------------------------------------------------------------------------------------------
  46. tmr6 | | | tmr6_overflow | |
  47. ------------------------------------------------------------------------------------------------------
  48. | | | | | tmr15_ch1
  49. | | | | | tmr15_overflow
  50. tmr15 | | | | | tmr15_trig
  51. | | | | | tmr15_hall
  52. | | | | | tmr15_ch2
  53. ------------------------------------------------------------------------------------------------------
  54. tmr16 | | | tmr16_ch1 | tmr16_ch1 |
  55. | | |tmr16_overflow |tmr16_overflow |
  56. ------------------------------------------------------------------------------------------------------
  57. tmr17 | tmr17_ch1 | tmr17_ch1 | | |
  58. |tmr17_overflow | tmr17_overflow | | |
  59. ------------------------------------------------------------------------------------------------------
  60. */
  61. /* Define to prevent recursive inclusion -------------------------------------*/
  62. #ifndef __AT32F421_DMA_H
  63. #define __AT32F421_DMA_H
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif
  67. /* Includes ------------------------------------------------------------------*/
  68. #include "at32f421.h"
  69. /** @addtogroup AT32F421_periph_driver
  70. * @{
  71. */
  72. /** @addtogroup DMA
  73. * @{
  74. */
  75. /** @defgroup DMA_interrupts_definition
  76. * @brief dma interrupt
  77. * @{
  78. */
  79. #define DMA_FDT_INT ((uint32_t)0x00000002) /*!< dma full data transfer interrupt */
  80. #define DMA_HDT_INT ((uint32_t)0x00000004) /*!< dma half data transfer interrupt */
  81. #define DMA_DTERR_INT ((uint32_t)0x00000008) /*!< dma errorr interrupt */
  82. /**
  83. * @}
  84. */
  85. /** @defgroup DMA_flags_definition
  86. * @brief dma flag
  87. * @{
  88. */
  89. #define DMA1_GL1_FLAG ((uint32_t)0x00000001) /*!< dma1 channel1 global flag */
  90. #define DMA1_FDT1_FLAG ((uint32_t)0x00000002) /*!< dma1 channel1 full data transfer flag */
  91. #define DMA1_HDT1_FLAG ((uint32_t)0x00000004) /*!< dma1 channel1 half data transfer flag */
  92. #define DMA1_DTERR1_FLAG ((uint32_t)0x00000008) /*!< dma1 channel1 error flag */
  93. #define DMA1_GL2_FLAG ((uint32_t)0x00000010) /*!< dma1 channel2 global flag */
  94. #define DMA1_FDT2_FLAG ((uint32_t)0x00000020) /*!< dma1 channel2 full data transfer flag */
  95. #define DMA1_HDT2_FLAG ((uint32_t)0x00000040) /*!< dma1 channel2 half data transfer flag */
  96. #define DMA1_DTERR2_FLAG ((uint32_t)0x00000080) /*!< dma1 channel2 error flag */
  97. #define DMA1_GL3_FLAG ((uint32_t)0x00000100) /*!< dma1 channel3 global flag */
  98. #define DMA1_FDT3_FLAG ((uint32_t)0x00000200) /*!< dma1 channel3 full data transfer flag */
  99. #define DMA1_HDT3_FLAG ((uint32_t)0x00000400) /*!< dma1 channel3 half data transfer flag */
  100. #define DMA1_DTERR3_FLAG ((uint32_t)0x00000800) /*!< dma1 channel3 error flag */
  101. #define DMA1_GL4_FLAG ((uint32_t)0x00001000) /*!< dma1 channel4 global flag */
  102. #define DMA1_FDT4_FLAG ((uint32_t)0x00002000) /*!< dma1 channel4 full data transfer flag */
  103. #define DMA1_HDT4_FLAG ((uint32_t)0x00004000) /*!< dma1 channel4 half data transfer flag */
  104. #define DMA1_DTERR4_FLAG ((uint32_t)0x00008000) /*!< dma1 channel4 error flag */
  105. #define DMA1_GL5_FLAG ((uint32_t)0x00010000) /*!< dma1 channel5 global flag */
  106. #define DMA1_FDT5_FLAG ((uint32_t)0x00020000) /*!< dma1 channel5 full data transfer flag */
  107. #define DMA1_HDT5_FLAG ((uint32_t)0x00040000) /*!< dma1 channel5 half data transfer flag */
  108. #define DMA1_DTERR5_FLAG ((uint32_t)0x00080000) /*!< dma1 channel5 error flag */
  109. /**
  110. * @}
  111. */
  112. /** @defgroup DMA_exported_types
  113. * @{
  114. */
  115. /**
  116. * @brief dma direction type
  117. */
  118. typedef enum
  119. {
  120. DMA_DIR_PERIPHERAL_TO_MEMORY = 0x0000, /*!< dma data transfer direction:peripheral to memory */
  121. DMA_DIR_MEMORY_TO_PERIPHERAL = 0x0010, /*!< dma data transfer direction:memory to peripheral */
  122. DMA_DIR_MEMORY_TO_MEMORY = 0x4000 /*!< dma data transfer direction:memory to memory */
  123. } dma_dir_type;
  124. /**
  125. * @brief dma peripheral incremented type
  126. */
  127. typedef enum
  128. {
  129. DMA_PERIPHERAL_INC_DISABLE = 0x00, /*!< dma peripheral increment mode disable */
  130. DMA_PERIPHERAL_INC_ENABLE = 0x01 /*!< dma peripheral increment mode enable */
  131. } dma_peripheral_inc_type;
  132. /**
  133. * @brief dma memory incremented type
  134. */
  135. typedef enum
  136. {
  137. DMA_MEMORY_INC_DISABLE = 0x00, /*!< dma memory increment mode disable */
  138. DMA_MEMORY_INC_ENABLE = 0x01 /*!< dma memory increment mode enable */
  139. } dma_memory_inc_type;
  140. /**
  141. * @brief dma peripheral data size type
  142. */
  143. typedef enum
  144. {
  145. DMA_PERIPHERAL_DATA_WIDTH_BYTE = 0x00, /*!< dma peripheral databus width 8bit */
  146. DMA_PERIPHERAL_DATA_WIDTH_HALFWORD = 0x01, /*!< dma peripheral databus width 16bit */
  147. DMA_PERIPHERAL_DATA_WIDTH_WORD = 0x02 /*!< dma peripheral databus width 32bit */
  148. } dma_peripheral_data_size_type;
  149. /**
  150. * @brief dma memory data size type
  151. */
  152. typedef enum
  153. {
  154. DMA_MEMORY_DATA_WIDTH_BYTE = 0x00, /*!< dma memory databus width 8bit */
  155. DMA_MEMORY_DATA_WIDTH_HALFWORD = 0x01, /*!< dma memory databus width 16bit */
  156. DMA_MEMORY_DATA_WIDTH_WORD = 0x02 /*!< dma memory databus width 32bit */
  157. } dma_memory_data_size_type;
  158. /**
  159. * @brief dma priority level type
  160. */
  161. typedef enum
  162. {
  163. DMA_PRIORITY_LOW = 0x00, /*!< dma channel priority: low */
  164. DMA_PRIORITY_MEDIUM = 0x01, /*!< dma channel priority: mediue */
  165. DMA_PRIORITY_HIGH = 0x02, /*!< dma channel priority: high */
  166. DMA_PRIORITY_VERY_HIGH = 0x03 /*!< dma channel priority: very high */
  167. } dma_priority_level_type;
  168. /**
  169. * @brief dma init type
  170. */
  171. typedef struct
  172. {
  173. uint32_t peripheral_base_addr; /*!< base addrress for peripheral */
  174. uint32_t memory_base_addr; /*!< base addrress for memory */
  175. dma_dir_type direction; /*!< dma transmit direction, peripheral as source or as destnation */
  176. uint16_t buffer_size; /*!< counter to transfer */
  177. confirm_state peripheral_inc_enable; /*!< periphera address increment after one transmit */
  178. confirm_state memory_inc_enable; /*!< memory address increment after one transmit */
  179. dma_peripheral_data_size_type peripheral_data_width; /*!< peripheral data width for transmit */
  180. dma_memory_data_size_type memory_data_width; /*!< memory data width for transmit */
  181. confirm_state loop_mode_enable; /*!< when circular mode enable, buffer size will reload if count to 0 */
  182. dma_priority_level_type priority; /*!< dma priority can choose from very high, high, dedium or low */
  183. } dma_init_type;
  184. /**
  185. * @brief type define dma register
  186. */
  187. typedef struct
  188. {
  189. /**
  190. * @brief dma sts register, offset:0x00
  191. */
  192. union
  193. {
  194. __IO uint32_t sts;
  195. struct
  196. {
  197. __IO uint32_t gf1 : 1; /* [0] */
  198. __IO uint32_t fdtf1 : 1; /* [1] */
  199. __IO uint32_t hdtf1 : 1; /* [2] */
  200. __IO uint32_t dterrf1 : 1; /* [3] */
  201. __IO uint32_t gf2 : 1; /* [4] */
  202. __IO uint32_t fdtf2 : 1; /* [5] */
  203. __IO uint32_t hdtf2 : 1; /* [6] */
  204. __IO uint32_t dterrf2 : 1; /* [7] */
  205. __IO uint32_t gf3 : 1; /* [8] */
  206. __IO uint32_t fdtf3 : 1; /* [9] */
  207. __IO uint32_t hdtf3 : 1; /* [10] */
  208. __IO uint32_t dterrf3 : 1; /* [11] */
  209. __IO uint32_t gf4 : 1; /* [12] */
  210. __IO uint32_t fdtf4 : 1; /* [13] */
  211. __IO uint32_t hdtf4 : 1; /* [14] */
  212. __IO uint32_t dterrf4 : 1; /* [15] */
  213. __IO uint32_t gf5 : 1; /* [16] */
  214. __IO uint32_t fdtf5 : 1; /* [17] */
  215. __IO uint32_t hdtf5 : 1; /* [18] */
  216. __IO uint32_t dterrf5 : 1; /* [19] */
  217. __IO uint32_t reserved1 : 12; /* [31:20] */
  218. } sts_bit;
  219. };
  220. /**
  221. * @brief dma clr register, offset:0x04
  222. */
  223. union
  224. {
  225. __IO uint32_t clr;
  226. struct
  227. {
  228. __IO uint32_t gfc1 : 1; /* [0] */
  229. __IO uint32_t fdtfc1 : 1; /* [1] */
  230. __IO uint32_t hdtfc1 : 1; /* [2] */
  231. __IO uint32_t dterrfc1 : 1; /* [3] */
  232. __IO uint32_t gfc2 : 1; /* [4] */
  233. __IO uint32_t fdtfc2 : 1; /* [5] */
  234. __IO uint32_t hdtfc2 : 1; /* [6] */
  235. __IO uint32_t dterrfc2 : 1; /* [7] */
  236. __IO uint32_t gfc3 : 1; /* [8] */
  237. __IO uint32_t fdtfc3 : 1; /* [9] */
  238. __IO uint32_t hdtfc3 : 1; /* [10] */
  239. __IO uint32_t dterrfc3 : 1; /* [11] */
  240. __IO uint32_t gfc4 : 1; /* [12] */
  241. __IO uint32_t fdtfc4 : 1; /* [13] */
  242. __IO uint32_t hdtfc4 : 1; /* [14] */
  243. __IO uint32_t dterrfc4 : 1; /* [15] */
  244. __IO uint32_t gfc5 : 1; /* [16] */
  245. __IO uint32_t fdtfc5 : 1; /* [17] */
  246. __IO uint32_t hdtfc5 : 1; /* [18] */
  247. __IO uint32_t dterrfc5 : 1; /* [19] */
  248. __IO uint32_t reserved1 : 12; /* [31:20] */
  249. } clr_bit;
  250. };
  251. } dma_type;
  252. /**
  253. * @brief type define dma channel register all
  254. */
  255. typedef struct
  256. {
  257. /**
  258. * @brief dma ctrl register, offset:0x08+20*(x-1) x=1...5
  259. */
  260. union
  261. {
  262. __IO uint32_t ctrl;
  263. struct
  264. {
  265. __IO uint32_t chen : 1; /* [0] */
  266. __IO uint32_t fdtien : 1; /* [1] */
  267. __IO uint32_t hdtien : 1; /* [2] */
  268. __IO uint32_t dterrien : 1; /* [3] */
  269. __IO uint32_t dtd : 1; /* [4] */
  270. __IO uint32_t lm : 1; /* [5] */
  271. __IO uint32_t pincm : 1; /* [6] */
  272. __IO uint32_t mincm : 1; /* [7] */
  273. __IO uint32_t pwidth : 2; /* [9:8] */
  274. __IO uint32_t mwidth : 2; /* [11:10] */
  275. __IO uint32_t chpl : 2; /* [13:12] */
  276. __IO uint32_t m2m : 1; /* [14] */
  277. __IO uint32_t reserved1 : 17;/* [31:15] */
  278. } ctrl_bit;
  279. };
  280. /**
  281. * @brief dma dtcnt register, offset:0x0C+20*(x-1) x=1...5
  282. */
  283. union
  284. {
  285. __IO uint32_t dtcnt;
  286. struct
  287. {
  288. __IO uint32_t cnt : 16;/* [15:0] */
  289. __IO uint32_t reserved1 : 16;/* [31:16] */
  290. } dtcnt_bit;
  291. };
  292. /**
  293. * @brief dma cpba register, offset:0x10+20*(x-1) x=1...5
  294. */
  295. union
  296. {
  297. __IO uint32_t paddr;
  298. struct
  299. {
  300. __IO uint32_t paddr : 32;/* [31:0] */
  301. } paddr_bit;
  302. };
  303. /**
  304. * @brief dma cmba register, offset:0x14+20*(x-1) x=1...5
  305. */
  306. union
  307. {
  308. __IO uint32_t maddr;
  309. struct
  310. {
  311. __IO uint32_t maddr : 32;/* [31:0] */
  312. } maddr_bit;
  313. };
  314. } dma_channel_type;
  315. /**
  316. * @}
  317. */
  318. #define DMA1 ((dma_type *) DMA1_BASE)
  319. #define DMA1_CHANNEL1 ((dma_channel_type *) DMA1_CHANNEL1_BASE)
  320. #define DMA1_CHANNEL2 ((dma_channel_type *) DMA1_CHANNEL2_BASE)
  321. #define DMA1_CHANNEL3 ((dma_channel_type *) DMA1_CHANNEL3_BASE)
  322. #define DMA1_CHANNEL4 ((dma_channel_type *) DMA1_CHANNEL4_BASE)
  323. #define DMA1_CHANNEL5 ((dma_channel_type *) DMA1_CHANNEL5_BASE)
  324. /** @defgroup DMA_exported_functions
  325. * @{
  326. */
  327. void dma_reset(dma_channel_type* dmax_channely);
  328. void dma_data_number_set(dma_channel_type* dmax_channely, uint16_t data_number);
  329. uint16_t dma_data_number_get(dma_channel_type* dmax_channely);
  330. void dma_interrupt_enable(dma_channel_type* dmax_channely, uint32_t dma_int, confirm_state new_state);
  331. void dma_channel_enable(dma_channel_type* dmax_channely, confirm_state new_state);
  332. flag_status dma_flag_get(uint32_t dmax_flag);
  333. void dma_flag_clear(uint32_t dmax_flag);
  334. void dma_default_para_init(dma_init_type* dma_init_struct);
  335. void dma_init(dma_channel_type* dmax_channely, dma_init_type* dma_init_struct);
  336. /**
  337. * @}
  338. */
  339. /**
  340. * @}
  341. */
  342. /**
  343. * @}
  344. */
  345. #ifdef __cplusplus
  346. }
  347. #endif
  348. #endif