hal_dma.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// @file hal_dma.h
  3. /// @author AE TEAM
  4. /// @brief THIS FILE CONTAINS ALL THE FUNCTIONS PROTOTYPES FOR THE DMA
  5. /// FIRMWARE LIBRARY.
  6. ////////////////////////////////////////////////////////////////////////////////
  7. /// @attention
  8. ///
  9. /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
  10. /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
  11. /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
  12. /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
  13. /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
  14. /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
  15. ///
  16. /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Define to prevent recursive inclusion
  19. #ifndef __HAL_DMA_H
  20. #define __HAL_DMA_H
  21. // Files includes
  22. #include "types.h"
  23. #include "reg_common.h"
  24. #include "reg_dma.h"
  25. ////////////////////////////////////////////////////////////////////////////////
  26. /// @addtogroup MM32_Hardware_Abstract_Layer
  27. /// @{
  28. ////////////////////////////////////////////////////////////////////////////////
  29. /// @defgroup DMA_HAL
  30. /// @brief DMA HAL modules
  31. /// @{
  32. ////////////////////////////////////////////////////////////////////////////////
  33. /// @defgroup DMA_Exported_Types
  34. /// @{
  35. ////////////////////////////////////////////////////////////////////////////////
  36. /// @brief DMA data transfer direction Enumerate definition
  37. /// @anchor DMA_data_transfer_direction
  38. ////////////////////////////////////////////////////////////////////////////////
  39. typedef enum {
  40. DMA_DIR_PeripheralSRC = 0U,
  41. DMA_DIR_PeripheralDST = DMA_CCR_DIR // 0x00000010U
  42. } DMA_data_transfer_direction_TypeDef;
  43. ////////////////////////////////////////////////////////////////////////////////
  44. /// @brief DMA peripheral incremented mode Enumerate definition
  45. /// @anchor DMA_peripheral_incremented_mode
  46. ////////////////////////////////////////////////////////////////////////////////
  47. typedef enum {
  48. DMA_PeripheralInc_Disable = 0U,
  49. DMA_PeripheralInc_Enable = DMA_CCR_PINC // 0x00000040U
  50. } DMA_peripheral_incremented_mode_TypeDef;
  51. ////////////////////////////////////////////////////////////////////////////////
  52. /// @brief DMA memory incremented mode Enumerate definition
  53. /// @anchor DMA_memory_incremented_mode
  54. ////////////////////////////////////////////////////////////////////////////////
  55. typedef enum {
  56. DMA_MemoryInc_Disable = 0U,
  57. DMA_MemoryInc_Enable = DMA_CCR_MINC // 0x00000080U
  58. } DMA_memory_incremented_mode_TypeDef;
  59. ////////////////////////////////////////////////////////////////////////////////
  60. /// @brief DMA peripheral data size Enumerate definition
  61. /// @anchor DMA_peripheral_data_size
  62. ////////////////////////////////////////////////////////////////////////////////
  63. typedef enum {
  64. DMA_PeripheralDataSize_Byte = 0U,
  65. DMA_PeripheralDataSize_HalfWord = DMA_CCR_PSIZE_HALFWORD,
  66. DMA_PeripheralDataSize_Word = DMA_CCR_PSIZE_WORD
  67. } DMA_peripheral_data_size_TypeDef;
  68. ////////////////////////////////////////////////////////////////////////////////
  69. /// @brief DMA memory data size Enumerate definition
  70. /// @anchor DMA_memory_data_size
  71. ////////////////////////////////////////////////////////////////////////////////
  72. typedef enum {
  73. DMA_MemoryDataSize_Byte = 0U,
  74. DMA_MemoryDataSize_HalfWord = DMA_CCR_MSIZE_HALFWORD, // 0x00000400U
  75. DMA_MemoryDataSize_Word = DMA_CCR_MSIZE_WORD // 0x00000800U
  76. } DMA_memory_data_size_TypeDef;
  77. ////////////////////////////////////////////////////////////////////////////////
  78. /// @brief DMA circular normal mode Enumerate definition
  79. /// @anchor DMA_circular_normal_mode
  80. ////////////////////////////////////////////////////////////////////////////////
  81. typedef enum {
  82. DMA_Mode_Normal = 0U,
  83. DMA_Mode_Circular = DMA_CCR_CIRC // 0x00000020U
  84. } DMA_circular_normal_mode_TypeDef;
  85. ////////////////////////////////////////////////////////////////////////////////
  86. /// @brief DMA priority level Enumerate definition
  87. /// @anchor DMA_priority_level
  88. ////////////////////////////////////////////////////////////////////////////////
  89. typedef enum {
  90. DMA_Priority_Low = 0U,
  91. DMA_Priority_Medium = DMA_CCR_PL_Medium, // 0x00001000U
  92. DMA_Priority_High = DMA_CCR_PL_High, // 0x00002000U
  93. DMA_Priority_VeryHigh = DMA_CCR_PL_VeryHigh // 0x00003000U
  94. } DMA_priority_level_TypeDef;
  95. ////////////////////////////////////////////////////////////////////////////////
  96. /// @brief DMA memory to memory Enumerate definition
  97. /// @anchor DMA_memory_to_memory
  98. ////////////////////////////////////////////////////////////////////////////////
  99. typedef enum {
  100. DMA_M2M_Disable = 0U,
  101. DMA_M2M_Enable = DMA_CCR_M2M // 0x00004000U
  102. } DMA_memory_to_memory_TypeDef;
  103. ////////////////////////////////////////////////////////////////////////////////
  104. /// @brief DMA auto reload Enumerate definition
  105. /// @anchor DMA_auto_reload
  106. ////////////////////////////////////////////////////////////////////////////////
  107. typedef enum {
  108. DMA_Auto_Reload_Disable = 0U, //
  109. DMA_Auto_Reload_Enable = DMA_CCR_ARE
  110. } DMA_auto_reload_TypeDef;
  111. /// @brief DMA Interrupt Setting Enumerate definition
  112. /// @anchor DMA_auto_reload
  113. ////////////////////////////////////////////////////////////////////////////////
  114. typedef enum {
  115. DMA_IT_TC = DMA_CCR_TCIE, //(0x00000002UL),
  116. DMA_IT_HT = DMA_CCR_HTIE, //(0x00000004UL),
  117. DMA_IT_TE = DMA_CCR_TEIE, //(0x00000008UL),
  118. } DMA_Interrupt_EN_TypeDef;
  119. ////////////////////////////////////////////////////////////////////////////////
  120. /// @brief DMA interrupts Enumerate definition
  121. /// @anchor DMA_Flags
  122. ////////////////////////////////////////////////////////////////////////////////
  123. typedef enum {
  124. DMAx_IT_GLy = (0x00000001UL),
  125. DMAx_IT_TCy = (0x00000002UL),
  126. DMAx_IT_HTy = (0x00000004UL),
  127. DMAx_IT_TEy = (0x00000008UL),
  128. DMA1_IT_GL1 = (0x00000001UL),
  129. DMA1_IT_TC1 = (0x00000002UL),
  130. DMA1_IT_HT1 = (0x00000004UL),
  131. DMA1_IT_TE1 = (0x00000008UL),
  132. DMA1_IT_GL2 = (0x00000010UL),
  133. DMA1_IT_TC2 = (0x00000020UL),
  134. DMA1_IT_HT2 = (0x00000040UL),
  135. DMA1_IT_TE2 = (0x00000080UL),
  136. DMA1_IT_GL3 = (0x00000100UL),
  137. DMA1_IT_TC3 = (0x00000200UL),
  138. DMA1_IT_HT3 = (0x00000400UL),
  139. DMA1_IT_TE3 = (0x00000800UL),
  140. DMA1_IT_GL4 = (0x00001000UL),
  141. DMA1_IT_TC4 = (0x00002000UL),
  142. DMA1_IT_HT4 = (0x00004000UL),
  143. DMA1_IT_TE4 = (0x00008000UL),
  144. DMA1_IT_GL5 = (0x00010000UL),
  145. DMA1_IT_TC5 = (0x00020000UL),
  146. DMA1_IT_HT5 = (0x00040000UL),
  147. DMA1_IT_TE5 = (0x00080000UL),
  148. DMA1_IT_GL6 = (0x00100000UL),
  149. DMA1_IT_TC6 = (0x00200000UL),
  150. DMA1_IT_HT6 = (0x00400000UL),
  151. DMA1_IT_TE6 = (0x00800000UL),
  152. DMA1_IT_GL7 = (0x01000000UL),
  153. DMA1_IT_TC7 = (0x02000000UL),
  154. DMA1_IT_HT7 = (0x04000000UL),
  155. DMA1_IT_TE7 = (0x08000000UL),
  156. DMA2_IT_GL1 = (0x10000001UL),
  157. DMA2_IT_TC1 = (0x10000002UL),
  158. DMA2_IT_HT1 = (0x10000004UL),
  159. DMA2_IT_TE1 = (0x10000008UL),
  160. DMA2_IT_GL2 = (0x10000010UL),
  161. DMA2_IT_TC2 = (0x10000020UL),
  162. DMA2_IT_HT2 = (0x10000040UL),
  163. DMA2_IT_TE2 = (0x10000080UL),
  164. DMA2_IT_GL3 = (0x10000100UL),
  165. DMA2_IT_TC3 = (0x10000200UL),
  166. DMA2_IT_HT3 = (0x10000400UL),
  167. DMA2_IT_TE3 = (0x10000800UL),
  168. DMA2_IT_GL4 = (0x10001000UL),
  169. DMA2_IT_TC4 = (0x10002000UL),
  170. DMA2_IT_HT4 = (0x10004000UL),
  171. DMA2_IT_TE4 = (0x10008000UL),
  172. DMA2_IT_GL5 = (0x10010000UL),
  173. DMA2_IT_TC5 = (0x10020000UL),
  174. DMA2_IT_HT5 = (0x10040000UL),
  175. DMA2_IT_TE5 = (0x10080000UL),
  176. } DMA_Interrupts_TypeDef;
  177. typedef enum {
  178. DMAx_FLAG_GLy = (0x00000001UL),
  179. DMAx_FLAG_TCy = (0x00000002UL),
  180. DMAx_FLAG_HTy = (0x00000004UL),
  181. DMAx_FLAG_TEy = (0x00000008UL),
  182. DMA1_FLAG_GL1 = (0x00000001UL),
  183. DMA1_FLAG_TC1 = (0x00000002UL),
  184. DMA1_FLAG_HT1 = (0x00000004UL),
  185. DMA1_FLAG_TE1 = (0x00000008UL),
  186. DMA1_FLAG_GL2 = (0x00000010UL),
  187. DMA1_FLAG_TC2 = (0x00000020UL),
  188. DMA1_FLAG_HT2 = (0x00000040UL),
  189. DMA1_FLAG_TE2 = (0x00000080UL),
  190. DMA1_FLAG_GL3 = (0x00000100UL),
  191. DMA1_FLAG_TC3 = (0x00000200UL),
  192. DMA1_FLAG_HT3 = (0x00000400UL),
  193. DMA1_FLAG_TE3 = (0x00000800UL),
  194. DMA1_FLAG_GL4 = (0x00001000UL),
  195. DMA1_FLAG_TC4 = (0x00002000UL),
  196. DMA1_FLAG_HT4 = (0x00004000UL),
  197. DMA1_FLAG_TE4 = (0x00008000UL),
  198. DMA1_FLAG_GL5 = (0x00010000UL),
  199. DMA1_FLAG_TC5 = (0x00020000UL),
  200. DMA1_FLAG_HT5 = (0x00040000UL),
  201. DMA1_FLAG_TE5 = (0x00080000UL),
  202. DMA1_FLAG_GL6 = (0x00100000UL),
  203. DMA1_FLAG_TC6 = (0x00200000UL),
  204. DMA1_FLAG_HT6 = (0x00400000UL),
  205. DMA1_FLAG_TE6 = (0x00800000UL),
  206. DMA1_FLAG_GL7 = (0x01000000UL),
  207. DMA1_FLAG_TC7 = (0x02000000UL),
  208. DMA1_FLAG_HT7 = (0x04000000UL),
  209. DMA1_FLAG_TE7 = (0x08000000UL),
  210. DMA2_FLAG_GL1 = (0x10000001UL),
  211. DMA2_FLAG_TC1 = (0x10000002UL),
  212. DMA2_FLAG_HT1 = (0x10000004UL),
  213. DMA2_FLAG_TE1 = (0x10000008UL),
  214. DMA2_FLAG_GL2 = (0x10000010UL),
  215. DMA2_FLAG_TC2 = (0x10000020UL),
  216. DMA2_FLAG_HT2 = (0x10000040UL),
  217. DMA2_FLAG_TE2 = (0x10000080UL),
  218. DMA2_FLAG_GL3 = (0x10000100UL),
  219. DMA2_FLAG_TC3 = (0x10000200UL),
  220. DMA2_FLAG_HT3 = (0x10000400UL),
  221. DMA2_FLAG_TE3 = (0x10000800UL),
  222. DMA2_FLAG_GL4 = (0x10001000UL),
  223. DMA2_FLAG_TC4 = (0x10002000UL),
  224. DMA2_FLAG_HT4 = (0x10004000UL),
  225. DMA2_FLAG_TE4 = (0x10008000UL),
  226. DMA2_FLAG_GL5 = (0x10010000UL),
  227. DMA2_FLAG_TC5 = (0x10020000UL),
  228. DMA2_FLAG_HT5 = (0x10040000UL),
  229. DMA2_FLAG_TE5 = (0x10080000UL),
  230. } DMA_Flags_TypeDef;
  231. ////////////////////////////////////////////////////////////////////////////////
  232. /// @brief DMA Init structure definition
  233. ////////////////////////////////////////////////////////////////////////////////
  234. typedef struct {
  235. u32 DMA_PeripheralBaseAddr; ///< the peripheral base address for DMA Channeln.
  236. u32 DMA_MemoryBaseAddr; ///< the memory base address for DMA Channeln.
  237. DMA_data_transfer_direction_TypeDef DMA_DIR; ///< the peripheral is the source or destination.
  238. u32 DMA_BufferSize; ///< Specifies the buffer size, in data unit, of the Buffer size
  239. DMA_peripheral_incremented_mode_TypeDef DMA_PeripheralInc; ///< Specifies whether the Peripheral address increment or not
  240. DMA_memory_incremented_mode_TypeDef DMA_MemoryInc; ///< Specifies whether the memory address register is increment or not
  241. DMA_peripheral_data_size_TypeDef DMA_PeripheralDataSize; ///< Specifies the Peripheral data width.
  242. DMA_memory_data_size_TypeDef DMA_MemoryDataSize; ///< Specifies the Memory data width.
  243. DMA_circular_normal_mode_TypeDef DMA_Mode; ///< Specifies the operation mode of the DMA Channeln circular or normal mode.
  244. DMA_priority_level_TypeDef DMA_Priority; ///< Specifies the software priority for the DMA priority level
  245. DMA_memory_to_memory_TypeDef DMA_M2M; ///< Specifies if the DMA Channeln will be used in memory-to-memory transfer.
  246. DMA_auto_reload_TypeDef DMA_Auto_reload; ///< Specifies if the DMA Channeln will auto reload the CNDTR register
  247. } DMA_InitTypeDef;
  248. /// @}
  249. ////////////////////////////////////////////////////////////////////////////////
  250. /// @defgroup DMA_Exported_Variables
  251. /// @{
  252. #ifdef _HAL_DMA_C_
  253. #define GLOBAL
  254. #else
  255. #define GLOBAL extern
  256. #endif
  257. #undef GLOBAL
  258. /// @}
  259. ////////////////////////////////////////////////////////////////////////////////
  260. /// @defgroup DMA_Exported_Functions
  261. /// @{
  262. void DMA_DeInit(DMA_Channel_TypeDef* channel);
  263. void DMA_Init(DMA_Channel_TypeDef* channel, DMA_InitTypeDef* init_struct);
  264. void DMA_StructInit(DMA_InitTypeDef* init_struct);
  265. void DMA_Cmd(DMA_Channel_TypeDef* channel, FunctionalState state);
  266. void DMA_ITConfig(DMA_Channel_TypeDef* channel, DMA_Interrupt_EN_TypeDef it, FunctionalState state);
  267. void DMA_ClearFlag(DMA_Flags_TypeDef flag);
  268. void DMA_ClearITPendingBit(DMA_Interrupts_TypeDef it);
  269. void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* channel, u16 length);
  270. u16 DMA_GetCurrDataCounter(DMA_Channel_TypeDef* channel);
  271. FlagStatus DMA_GetFlagStatus(DMA_Flags_TypeDef flag);
  272. ITStatus DMA_GetITStatus(DMA_Interrupts_TypeDef it);
  273. void exDMA_SetPeripheralAddress(DMA_Channel_TypeDef* channel, u32 addr);
  274. void exDMA_SetTransmitLen(DMA_Channel_TypeDef* channel, u16 len);
  275. void exDMA_SetMemoryAddress(DMA_Channel_TypeDef* channel, u32 addr);
  276. /// @}
  277. /// @}
  278. /// @}
  279. ////////////////////////////////////////////////////////////////////////////////
  280. #endif //__HAL_DMA_H
  281. ////////////////////////////////////////////////////////////////////////////////