apm32f4xx_dma.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*!
  2. * @file apm32f4xx_dma.h
  3. *
  4. * @brief This file contains all the functions prototypes for the DMA firmware library.
  5. *
  6. * @version V1.0.2
  7. *
  8. * @date 2022-06-23
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2021-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be usefull and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32F4XX_DMA_H
  27. #define __APM32F4XX_DMA_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Includes */
  32. #include "apm32f4xx.h"
  33. /** @addtogroup APM32F4xx_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup DMA_Driver
  37. @{
  38. */
  39. /** @defgroup DMA_Enumerations
  40. @{
  41. */
  42. /**
  43. * @brief DMA channel
  44. */
  45. typedef enum
  46. {
  47. DMA_CHANNEL_0, /*!< Select DMA channel 0 */
  48. DMA_CHANNEL_1, /*!< Select DMA channel 1 */
  49. DMA_CHANNEL_2, /*!< Select DMA channel 2 */
  50. DMA_CHANNEL_3, /*!< Select DMA channel 3 */
  51. DMA_CHANNEL_4, /*!< Select DMA channel 4 */
  52. DMA_CHANNEL_5, /*!< Select DMA channel 5 */
  53. DMA_CHANNEL_6, /*!< Select DMA channel 6 */
  54. DMA_CHANNEL_7 /*!< Select DMA channel 7 */
  55. } DMA_CHANNEL_T;
  56. /**
  57. * @brief DMA Transmission direction
  58. */
  59. typedef enum
  60. {
  61. DMA_DIR_PERIPHERALTOMEMORY, /*!< Peripheral to memory */
  62. DMA_DIR_MEMORYTOPERIPHERAL, /*!< Memory to peripheral */
  63. DMA_DIR_MEMORYTOMEMORY /*!< Memory to memory */
  64. } DMA_DIR_T;
  65. /**
  66. * @brief DMA Peripheral address increment
  67. */
  68. typedef enum
  69. {
  70. DMA_PERIPHERAL_INC_DISABLE, /*!< Disable peripheral increment mode */
  71. DMA_PERIPHERAL_INC_ENABLE /*!< Enable peripheral increment mode */
  72. } DMA_PERIPHERAL_INC_T;
  73. /**
  74. * @brief DMA Memory address increment
  75. */
  76. typedef enum
  77. {
  78. DMA_MEMORY_INC_DISABLE, /*!< Disable memory increment mode */
  79. DMA_MEMORY_INC_ENABLE /*!< Enable memory increment mode */
  80. } DMA_MEMORY_INC_T;
  81. /**
  82. * @brief DMA Peripheral Data Size
  83. */
  84. typedef enum
  85. {
  86. DMA_PERIPHERAL_DATA_SIZE_BYTE, /*!< Set peripheral data size to byte */
  87. DMA_PERIPHERAL_DATA_SIZE_HALFWORD, /*!< Set peripheral data size to half-word */
  88. DMA_PERIPHERAL_DATA_SIZE_WORD /*!< Set peripheral data size to word */
  89. } DMA_PERIPHERAL_DATA_SIZE_T;
  90. /**
  91. * @brief DMA Memory Data Size
  92. */
  93. typedef enum
  94. {
  95. DMA_MEMORY_DATA_SIZE_BYTE, /*!< Set memory data size to byte */
  96. DMA_MEMORY_DATA_SIZE_HALFWORD, /*!< Set memory data size to half-word */
  97. DMA_MEMORY_DATA_SIZE_WORD /*!< Set memory data size to word */
  98. } DMA_MEMORY_DATA_SIZE_T;
  99. /**
  100. * @brief DMA Mode
  101. */
  102. typedef enum
  103. {
  104. DMA_MODE_NORMAL, /*!< Disable circular mode */
  105. DMA_MODE_CIRCULAR /*!< Enable circular mode */
  106. } DMA_LOOP_MODE_T;
  107. /**
  108. * @brief DMA priority level
  109. */
  110. typedef enum
  111. {
  112. DMA_PRIORITY_LOW, /*!< Set priority level to low */
  113. DMA_PRIORITY_MEDIUM, /*!< Set priority level to medium */
  114. DMA_PRIORITY_HIGH, /*!< Set priority level to high */
  115. DMA_PRIORITY_VERYHIGH /*!< Set priority level to very high */
  116. } DMA_PRIORITY_T;
  117. /**
  118. * @brief DMA fifo direct mode
  119. */
  120. typedef enum
  121. {
  122. DMA_FIFOMODE_DISABLE, /*!< Enable fifo mode */
  123. DMA_FIFOMODE_ENABLE /*!< Disable fifo mode */
  124. } DMA_FIFOMODE_T;
  125. /**
  126. * @brief DMA fifo threshold select
  127. */
  128. typedef enum
  129. {
  130. DMA_FIFOTHRESHOLD_QUARTER, /*!< Select quarter FIFO threshold */
  131. DMA_FIFOTHRESHOLD_HALFFULL, /*!< Select half-full FIFO threshold */
  132. DMA_FIFOTHRESHOLD_3QUARTERS, /*!< Select three quarters FIFO threshold */
  133. DMA_FIFOTHRESHOLD_FULL /*!< Select full FIFO threshold */
  134. } DMA_FIFOTHRESHOLD_T;
  135. /**
  136. * @brief DMA memory burst
  137. */
  138. typedef enum
  139. {
  140. DMA_MEMORYBURST_SINGLE, /*!< Single memory burst transfer */
  141. DMA_MEMORYBURST_INC4, /*!< INC4 memory burst transfer */
  142. DMA_MEMORYBURST_INC8, /*!< INC8 memory burst transfer */
  143. DMA_MEMORYBURST_INC16 /*!< INC16 memory burst transfer */
  144. } DMA_MEMORYBURST_T;
  145. /**
  146. * @brief DMA peripheral burst
  147. */
  148. typedef enum
  149. {
  150. DMA_PERIPHERALBURST_SINGLE, /*!< Single peripheral burst transfer */
  151. DMA_PERIPHERALBURST_INC4, /*!< INC4 peripheral burst transfer */
  152. DMA_PERIPHERALBURST_INC8, /*!< INC8 peripheral burst transfer */
  153. DMA_PERIPHERALBURST_INC16 /*!< INC16 peripheral burst transfer */
  154. } DMA_PERIPHERALBURST_T;
  155. /**
  156. * @brief DMA fifo status level
  157. */
  158. typedef enum
  159. {
  160. DMA_FIFOSTATUS_LESS1QUARTER, /*!< When FIFO is less than 1 quarter-full and not empty */
  161. DMA_FIFOSTATUS_1QUARTER, /*!< If more than 1 quarter-full */
  162. DMA_FIFOSTATUS_HalfFull, /*!< If more than 1 half-full */
  163. DMA_FIFOSTATUS_3QUARTERS, /*!< If more than 3 quarters-full */
  164. DMA_FIFOSTATUS_EMPTY, /*!< When FIFO is empty */
  165. DMA_FIFOSTATUS_FULL /*!< When FIFO is full */
  166. } DMA_FIFOSTATUS_T;
  167. /**
  168. * @brief DMA Flag
  169. */
  170. typedef enum
  171. {
  172. DMA_FLAG_FEIFLG0 = 0x10000001, /*!< Channel0 FIFO error flag */
  173. DMA_FLAG_DMEIFLG0 = 0x10000004, /*!< Channel0 direct mode error flag */
  174. DMA_FLAG_TEIFLG0 = 0x10000008, /*!< Channel0 transfer error flag */
  175. DMA_FLAG_HTIFLG0 = 0x10000010, /*!< Channel0 half transfer complete flag */
  176. DMA_FLAG_TCIFLG0 = 0x10000020, /*!< Channel0 transfer complete flag */
  177. DMA_FLAG_FEIFLG1 = 0x10000040, /*!< Channel1 FIFO error flag */
  178. DMA_FLAG_DMEIFLG1 = 0x10000100, /*!< Channel1 direct mode error flag */
  179. DMA_FLAG_TEIFLG1 = 0x10000200, /*!< Channel1 transfer error flag */
  180. DMA_FLAG_HTIFLG1 = 0x10000400, /*!< Channel1 half transfer complete flag */
  181. DMA_FLAG_TCIFLG1 = 0x10000800, /*!< Channel1 transfer complete flag */
  182. DMA_FLAG_FEIFLG2 = 0x10010000, /*!< Channel2 FIFO error flag */
  183. DMA_FLAG_DMEIFLG2 = 0x10040000, /*!< Channel2 direct mode error flag */
  184. DMA_FLAG_TEIFLG2 = 0x10080000, /*!< Channel2 transfer error flag */
  185. DMA_FLAG_HTIFLG2 = 0x10100000, /*!< Channel2 half transfer complete flag */
  186. DMA_FLAG_TCIFLG2 = 0x10200000, /*!< Channel2 transfer complete flag */
  187. DMA_FLAG_FEIFLG3 = 0x10400000, /*!< Channel3 FIFO error flag */
  188. DMA_FLAG_DMEIFLG3 = 0x11000000, /*!< Channel3 direct mode error flag */
  189. DMA_FLAG_TEIFLG3 = 0x12000000, /*!< Channel3 transfer error flag */
  190. DMA_FLAG_HTIFLG3 = 0x14000000, /*!< Channel3 half transfer complete flag */
  191. DMA_FLAG_TCIFLG3 = 0x18000000, /*!< Channel3 transfer complete flag */
  192. DMA_FLAG_FEIFLG4 = 0x20000001, /*!< Channel4 FIFO error flag */
  193. DMA_FLAG_DMEIFLG4 = 0x20000004, /*!< Channel4 direct mode error flag */
  194. DMA_FLAG_TEIFLG4 = 0x20000008, /*!< Channel4 transfer error flag */
  195. DMA_FLAG_HTIFLG4 = 0x20000010, /*!< Channel4 half transfer complete flag */
  196. DMA_FLAG_TCIFLG4 = 0x20000020, /*!< Channel4 transfer complete flag */
  197. DMA_FLAG_FEIFLG5 = 0x20000040, /*!< Channel5 FIFO error flag */
  198. DMA_FLAG_DMEIFLG5 = 0x20000100, /*!< Channel5 direct mode error flag */
  199. DMA_FLAG_TEIFLG5 = 0x20000200, /*!< Channel5 transfer error flag */
  200. DMA_FLAG_HTIFLG5 = 0x20000400, /*!< Channel5 half transfer complete flag */
  201. DMA_FLAG_TCIFLG5 = 0x20000800, /*!< Channel5 transfer complete flag */
  202. DMA_FLAG_FEIFLG6 = 0x20010000, /*!< Channel6 FIFO error flag */
  203. DMA_FLAG_DMEIFLG6 = 0x20040000, /*!< Channel6 direct mode error flag */
  204. DMA_FLAG_TEIFLG6 = 0x20080000, /*!< Channel6 transfer error flag */
  205. DMA_FLAG_HTIFLG6 = 0x20100000, /*!< Channel6 half transfer complete flag */
  206. DMA_FLAG_TCIFLG6 = 0x20200000, /*!< Channel6 transfer complete flag */
  207. DMA_FLAG_FEIFLG7 = 0x20400000, /*!< Channel7 FIFO error flag */
  208. DMA_FLAG_DMEIFLG7 = 0x21000000, /*!< Channel7 direct mode error flag */
  209. DMA_FLAG_TEIFLG7 = 0x22000000, /*!< Channel7 transfer error flag */
  210. DMA_FLAG_HTIFLG7 = 0x24000000, /*!< Channel7 half transfer complete flag */
  211. DMA_FLAG_TCIFLG7 = 0x28000000 /*!< Channel7 transfer complete flag */
  212. } DMA_FLAG_T;
  213. /**
  214. * @brief DMA Interrupt Flag
  215. */
  216. typedef enum
  217. {
  218. DMA_INT_FEIFLG = 0x01, /*!< FIFO error interrupt mask */
  219. DMA_INT_DMEIFLG = 0x02, /*!< Direct mode error interrupt mask */
  220. DMA_INT_TEIFLG = 0x04, /*!< Transfer error interrupt mask */
  221. DMA_INT_HTIFLG = 0x08, /*!< Half transfer complete interrupt mask */
  222. DMA_INT_TCIFLG = 0x10 /*!< Transfer complete interrupt mask */
  223. } DMA_INT_T;
  224. /**
  225. * @brief DMA Interrupts Flag
  226. */
  227. typedef enum
  228. {
  229. DMA_INT_FEIFLG0 = 0x20000001, /*!< Stream0 FIFO error flag */
  230. DMA_INT_DMEIFLG0 = 0x00001004, /*!< Stream0 direct mode error flag */
  231. DMA_INT_TEIFLG0 = 0x00002008, /*!< Stream0 transfer error flag */
  232. DMA_INT_HTIFLG0 = 0x00004010, /*!< Stream0 half transfer complete flag */
  233. DMA_INT_TCIFLG0 = 0x00008020, /*!< Stream0 transfer complete flag */
  234. DMA_INT_FEIFLG1 = 0x20000040, /*!< Stream1 FIFO error flag */
  235. DMA_INT_DMEIFLG1 = 0x00001100, /*!< Stream1 direct mode error flag */
  236. DMA_INT_TEIFLG1 = 0x00002200, /*!< Stream1 transfer error flag */
  237. DMA_INT_HTIFLG1 = 0x00004400, /*!< Stream1 half transfer complete flag */
  238. DMA_INT_TCIFLG1 = 0x00008800, /*!< Stream1 transfer complete flag */
  239. DMA_INT_FEIFLG2 = 0x20010000, /*!< Stream2 FIFO error flag */
  240. DMA_INT_DMEIFLG2 = 0x00041000, /*!< Stream2 direct mode error flag */
  241. DMA_INT_TEIFLG2 = 0x00082000, /*!< Stream2 transfer error flag */
  242. DMA_INT_HTIFLG2 = 0x00104000, /*!< Stream2 half transfer complete flag */
  243. DMA_INT_TCIFLG2 = 0x00208000, /*!< Stream2 transfer complete flag */
  244. DMA_INT_FEIFLG3 = 0x20400000, /*!< Stream3 FIFO error flag */
  245. DMA_INT_DMEIFLG3 = 0x01001000, /*!< Stream3 direct mode error flag */
  246. DMA_INT_TEIFLG3 = 0x02002000, /*!< Stream3 transfer error flag */
  247. DMA_INT_HTIFLG3 = 0x04004000, /*!< Stream3 half transfer complete flag */
  248. DMA_INT_TCIFLG3 = 0x08008000, /*!< Stream3 transfer complete flag */
  249. DMA_INT_FEIFLG4 = 0x50000001, /*!< Stream4 FIFO error flag */
  250. DMA_INT_DMEIFLG4 = 0x10001004, /*!< Stream4 direct mode error flag */
  251. DMA_INT_TEIFLG4 = 0x10002008, /*!< Stream4 transfer error flag */
  252. DMA_INT_HTIFLG4 = 0x10004010, /*!< Stream4 half transfer complete flag */
  253. DMA_INT_TCIFLG4 = 0x10008020, /*!< Stream4 transfer complete flag */
  254. DMA_INT_FEIFLG5 = 0x50000040, /*!< Stream5 FIFO error flag */
  255. DMA_INT_DMEIFLG5 = 0x10001100, /*!< Stream5 direct mode error flag */
  256. DMA_INT_TEIFLG5 = 0x10002200, /*!< Stream5 transfer error flag */
  257. DMA_INT_HTIFLG5 = 0x10004400, /*!< Stream5 half transfer complete flag */
  258. DMA_INT_TCIFLG5 = 0x10008800, /*!< Stream5 transfer complete flag */
  259. DMA_INT_FEIFLG6 = 0x50010000, /*!< Stream6 FIFO error flag */
  260. DMA_INT_DMEIFLG6 = 0x10041000, /*!< Stream6 direct mode error flag */
  261. DMA_INT_TEIFLG6 = 0x10082000, /*!< Stream6 transfer error flag */
  262. DMA_INT_HTIFLG6 = 0x10104000, /*!< Stream6 half transfer complete flag */
  263. DMA_INT_TCIFLG6 = 0x10208000, /*!< Stream6 transfer complete flag */
  264. DMA_INT_FEIFLG7 = 0x50400000, /*!< Stream7 FIFO error flag */
  265. DMA_INT_DMEIFLG7 = 0x11001000, /*!< Stream7 direct mode error flag */
  266. DMA_INT_TEIFLG7 = 0x12002000, /*!< Stream7 transfer error flag */
  267. DMA_INT_HTIFLG7 = 0x14004000, /*!< Stream7 half transfer complete flag */
  268. DMA_INT_TCIFLG7 = 0x18008000 /*!< Stream7 transfer complete flag */
  269. } DMA_INT_FLAG_T;
  270. /**
  271. * @brief DMA peripheral increment offset
  272. */
  273. typedef enum
  274. {
  275. DMA_PERIOSIZE_PSIZE, /*!< Peripheral address increment is done
  276. accordingly to PSIZE parameter */
  277. DMA_PERIOSIZE_WORDALIGNED /*!< Peripheral address increment offset is
  278. fixed to 4 (32-bit aligned addresses). */
  279. } DMA_PERIOSIZE_T;
  280. /**
  281. * @brief DMA flow controller
  282. */
  283. typedef enum
  284. {
  285. DMA_FLOWCTRL_MEMORY, /*!< DMAy_Channelx transactions flow controller is
  286. the DMA controller */
  287. DMA_FLOWCTRL_PERIPHERAL /*!< DMAy_Channelx transactions flow controller
  288. is the peripheral */
  289. } DMA_FLOWCTRL_T;
  290. /**
  291. * @brief DMA memory targets
  292. */
  293. typedef enum
  294. {
  295. DMA_MEMORY_0, /*!< Memory 0 Address */
  296. DMA_MEMORY_1 /*!< Memory 1 Address */
  297. } DMA_MEMORY_T;
  298. /**@} end of group DMA_Enumerations*/
  299. /** @addtogroup DMA_Structure Data Structure
  300. @{
  301. */
  302. /**
  303. * @brief DMA Config struct definition
  304. */
  305. typedef struct
  306. {
  307. DMA_CHANNEL_T channel; /*!< Channel selection */
  308. uint32_t peripheralBaseAddr; /*!< Peripheral base address */
  309. uint32_t memoryBaseAddr; /*!< Memory base address */
  310. DMA_DIR_T dir; /*!< Direction */
  311. uint32_t bufferSize; /*!< Buffer size */
  312. DMA_PERIPHERAL_INC_T peripheralInc; /*!< Peripheral increment mode selection */
  313. DMA_MEMORY_INC_T memoryInc; /*!< Memory increment mode selection */
  314. DMA_PERIPHERAL_DATA_SIZE_T peripheralDataSize; /*!< Peripheral data size */
  315. DMA_MEMORY_DATA_SIZE_T memoryDataSize; /*!< Memory data size */
  316. DMA_LOOP_MODE_T loopMode; /*!< Loop mode */
  317. DMA_PRIORITY_T priority; /*!< DMA priority level */
  318. DMA_FIFOMODE_T fifoMode; /*!< FIFO mode selection */
  319. DMA_FIFOTHRESHOLD_T fifoThreshold; /*!< FIFO threshold configuration */
  320. DMA_MEMORYBURST_T memoryBurst; /*!< Memory burst configuration */
  321. DMA_PERIPHERALBURST_T peripheralBurst; /*!< Peripheral burst configuration */
  322. } DMA_Config_T;
  323. /**@} end of group DMA_Structure*/
  324. /** @defgroup DMA_Functions
  325. @{
  326. */
  327. /* DMA Reset and Configuration */
  328. void DMA_Reset(DMA_Stream_T* stream);
  329. void DMA_Config(DMA_Stream_T* stream, DMA_Config_T* dmaConfig);
  330. void DMA_ConfigStructInit( DMA_Config_T* dmaConfig);
  331. void DMA_Enable(DMA_Stream_T* stream);
  332. void DMA_Disable(DMA_Stream_T* stream);
  333. /* Stream Configuration */
  334. void DMA_ConfigPeriphIncOffsetSize(DMA_Stream_T* stream, DMA_PERIOSIZE_T perioSize);
  335. void DMA_ConfigFlowController(DMA_Stream_T* stream, DMA_FLOWCTRL_T flowController);
  336. /* DMA Data Number */
  337. void DMA_ConfigDataNumber(DMA_Stream_T* stream, uint16_t dataNumber);
  338. uint16_t DMA_ReadDataNumber(DMA_Stream_T* stream);
  339. /* DMA Double Buffer mode */
  340. void DMA_ConfigBufferMode(DMA_Stream_T* stream, uint32_t memory1BaseAddr, DMA_MEMORY_T currentMemory);
  341. void DMA_EnableDoubleBufferMode(DMA_Stream_T* stream);
  342. void DMA_DisableDoubleBufferMode(DMA_Stream_T* stream);
  343. void DMA_ConfigMemoryTarget(DMA_Stream_T* stream, uint32_t memoryBaseAddr, DMA_MEMORY_T memoryTarget);
  344. uint32_t DMA_ReadCurrentMemoryTarget(DMA_Stream_T* stream);
  345. /* DMA Interrupts and flags */
  346. uint8_t DMA_ReadCmdStatus(DMA_Stream_T* stream);
  347. uint32_t DMA_ReadFIFOFlag(DMA_Stream_T* stream);
  348. uint8_t DMA_ReadStatusFlag(DMA_Stream_T* stream, DMA_FLAG_T flag);
  349. void DMA_ClearStatusFlag(DMA_Stream_T* stream, uint32_t flag);
  350. void DMA_EnableInterrupt(DMA_Stream_T* stream, uint32_t interrupt);
  351. void DMA_DisableInterrupt(DMA_Stream_T* stream, uint32_t interrupt);
  352. uint8_t DMA_ReadIntFlag(DMA_Stream_T* stream, DMA_INT_FLAG_T flag);
  353. void DMA_ClearIntFlag(DMA_Stream_T* stream, uint32_t flag);
  354. #ifdef __cplusplus
  355. }
  356. #endif
  357. #endif /*__APM32F4XX_DMA_H */
  358. /**@} end of group DMA_Enumerations */
  359. /**@} end of group DMA_Driver */
  360. /**@} end of group APM32F4xx_StdPeriphDriver */