HAL_DMA.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. ******************************************************************************
  3. * @file HAL_DMA.h
  4. * @version V1.0.0
  5. * @date 2020
  6. * @brief Header file of DMA HAL module.
  7. ******************************************************************************
  8. */
  9. #ifndef __HAL_DMA_H__
  10. #define __HAL_DMA_H__
  11. #include "ACM32Fxx_HAL.h"
  12. #define DMA_CHANNEL_NUM (8)
  13. /******************************************************************************/
  14. /* Peripheral Registers Bits Definition */
  15. /******************************************************************************/
  16. /**************** Bit definition for DMA CONFIG register ***********************/
  17. #define DMA_CONFIG_M2ENDIAN BIT2
  18. #define DMA_CONFIG_M1ENDIAN BIT1
  19. #define DMA_CONFIG_EN BIT0
  20. /**************** Bit definition for DMA Channel CTRL register ***********************/
  21. #define DMA_CHANNEL_CTRL_ITC BIT31
  22. #define DMA_CHANNEL_CTRL_DI BIT27
  23. #define DMA_CHANNEL_CTRL_SI BIT26
  24. /**************** Bit definition for DMA Channel CONFIG register ***********************/
  25. #define DMA_CHANNEL_CONFIG_DEST_PERIPH (BIT19|BIT20|BIT21|BIT22|BIT23|BIT24)
  26. #define DMA_CHANNEL_CONFIG_DEST_PERIPH_POS (19)
  27. #define DMA_CHANNEL_CONFIG_HALT BIT18
  28. #define DMA_CHANNEL_CONFIG_ACTIVE BIT17
  29. #define DMA_CHANNEL_CONFIG_LOCK BIT16
  30. #define DMA_CHANNEL_CONFIG_ITC BIT15
  31. #define DMA_CHANNEL_CONFIG_IE BIT14
  32. #define DMA_CHANNEL_CONFIG_FLOW_CTRL (BIT11|BIT12|BIT13)
  33. #define DMA_CHANNEL_CONFIG_SRC_PERIPH (BIT1|BIT2|BIT3|BIT4|BIT5|BIT6)
  34. #define DMA_CHANNEL_CONFIG_SRC_PERIPH_POS (1)
  35. #define DMA_CHANNEL_CONFIG_EN BIT0
  36. /** @defgroup DMA_DATA_FLOW
  37. * @{
  38. */
  39. #define DMA_DATA_FLOW_M2M (0x00000000)
  40. #define DMA_DATA_FLOW_M2P (0x00000800)
  41. #define DMA_DATA_FLOW_P2M (0x00001000)
  42. /**
  43. * @}
  44. */
  45. /** @defgroup REQUEST_ID
  46. * @{
  47. */
  48. #define REG_M2M (0)
  49. #define REQ0_ADC (0)
  50. #define REQ1_SPI1_SEND (1)
  51. #define REQ2_SPI1_RECV (2)
  52. #define REQ3_SPI2_SEND (3)
  53. #define REQ4_SPI2_RECV (4)
  54. #define REQ5_UART1_SEND (5)
  55. #define REQ6_UART1_RECV (6)
  56. #define REQ7_UART2_SEND (7)
  57. #define REQ8_UART2_RECV (8)
  58. #define REQ9_I2C1_SEND (9)
  59. #define REQ10_I2C1_RECV (10)
  60. #define REQ11_I2C2_SEND (11)
  61. #define REQ12_I2C2_RECV (12)
  62. #define REQ13_TIM1_CH1 (13)
  63. #define REQ14_TIM1_CH2 (14)
  64. #define REQ15_TIM1_CH3 (15)
  65. #define REQ16_TIM1_CH4 (16)
  66. #define REQ17_TIM1_UP (17)
  67. #define REQ18_TIM1_TRIG_COM (18)
  68. #define REQ19_TIM3_CH3 (19)
  69. #define REQ20_TIM3_CH4_OR_UP (20)
  70. #define REQ21_TIM3_CH1_OR_TRIG (21)
  71. #define REQ22_TIM3_CH2 (22)
  72. #define REQ23_TIM6_UP (23)
  73. #define REQ24_TIM15_CH1_UP_TRIG_COM (24)
  74. #define REQ25_TIM15_CH2 (25)
  75. #define REQ26_TIM16_CH1_UP (26)
  76. #define REQ27_TIM16_TRIG_COM (27)
  77. #define REQ27_UART3_SEND (27)
  78. #define REQ28_TIM17_CH1_UP (28)
  79. #define REQ29_TIM17_TRIG_COM (29)
  80. #define REQ29_UART3_RECV (29)
  81. #define REQ30_LPUART_SEND (30)
  82. #define REQ31_LPUART_RECV (31)
  83. #define REQ32_TIM2_CH3 (32)
  84. #define REQ33_TIM2_CH4 (33)
  85. #define REQ34_TIM2_CH1 (34)
  86. #define REQ35_TIM2_CH2 (35)
  87. #define REQ36_TIM7_UP (36)
  88. #define REQ37_I2S1_TX (37)
  89. #define REQ38_I2S1_RX (38)
  90. #define REQ39_DAC1_CH1 (39)
  91. #define REQ40_DAC1_CH2 (40)
  92. #define REQ41_TIM4_CH3 (41)
  93. #define REQ42_TIM4_CH4 (42)
  94. #define REQ43_TIM4_CH1 (43)
  95. #define REQ44_TIM4_CH2 (44)
  96. #define REQ45_UART4_SEND (45)
  97. #define REQ46_UART4_RECV (46)
  98. #define REQ47_SPI3_SEND (47)
  99. #define REQ48_SPI3_RECV (48)
  100. #define REQ49_SPI4_SEND (49)
  101. #define REQ50_SPI4_RECV (50)
  102. #define REQ_MAX_LIMIT (51)
  103. /**
  104. * @}
  105. */
  106. /** @defgroup DMA_SOURCE_ADDR_INCREASE
  107. * @{
  108. */
  109. #define DMA_SOURCE_ADDR_INCREASE_DISABLE (0x00000000)
  110. #define DMA_SOURCE_ADDR_INCREASE_ENABLE (0x04000000)
  111. /**
  112. * @}
  113. */
  114. /** @defgroup DMA_DST_ADDR_INCREASE
  115. * @{
  116. */
  117. #define DMA_DST_ADDR_INCREASE_DISABLE (0x00000000)
  118. #define DMA_DST_ADDR_INCREASE_ENABLE (0x08000000)
  119. /**
  120. * @}
  121. */
  122. /** @defgroup DMA_SRC_WIDTH
  123. * @{
  124. */
  125. #define DMA_SRC_WIDTH_BYTE (0x00000000) /* 8bit */
  126. #define DMA_SRC_WIDTH_HALF_WORD (0x00040000) /* 16bit */
  127. #define DMA_SRC_WIDTH_WORD (0x00080000) /* 36bit */
  128. /**
  129. * @}
  130. */
  131. /** @defgroup DMA_DST_WIDTH
  132. * @{
  133. */
  134. #define DMA_DST_WIDTH_BYTE (0x00000000) /* 8bit */
  135. #define DMA_DST_WIDTH_HALF_WORD (0x00200000) /* 16bit */
  136. #define DMA_DST_WIDTH_WORD (0x00400000) /* 36bit */
  137. /**
  138. * @}
  139. */
  140. /** @defgroup DMA_MODE DMA MODE
  141. * @{
  142. */
  143. #define DMA_NORMAL 0x00000000U /*!< Normal mode */
  144. #define DMA_CIRCULAR 0x00000001U /*!< Circular mode */
  145. /**
  146. * @}
  147. */
  148. /**
  149. * @brief DMA burst length Structure definition
  150. */
  151. typedef enum
  152. {
  153. DMA_BURST_LENGTH_1 = 0,
  154. DMA_BURST_LENGTH_4 = 1,
  155. DMA_BURST_LENGTH_8 = 2,
  156. DMA_BURST_LENGTH_16 = 3,
  157. DMA_BURST_LENGTH_32 = 4,
  158. DMA_BURST_LENGTH_64 = 5,
  159. DMA_BURST_LENGTH_128 = 6,
  160. DMA_BURST_LENGTH_256 = 7,
  161. }DMA_BURST_LENGTH;
  162. /**
  163. * @brief DMA Configuration Structure definition
  164. */
  165. typedef struct
  166. {
  167. uint32_t Mode; /* This parameter can be a value of @ref DMA_MODE */
  168. uint32_t Data_Flow; /* This parameter can be a value of @ref DMA_DATA_FLOW */
  169. uint32_t Request_ID; /* This parameter can be a value of @ref REQUEST_ID */
  170. uint32_t Source_Inc; /* This parameter can be a value of @ref DMA_SOURCE_ADDR_INCREASE */
  171. uint32_t Desination_Inc; /* This parameter can be a value of @ref DMA_DST_ADDR_INCREASE */
  172. uint32_t Source_Width; /* This parameter can be a value of @ref DMA_SRC_WIDTH */
  173. uint32_t Desination_Width; /* This parameter can be a value of @ref DMA_DST_WIDTH */
  174. }DMA_InitParaTypeDef;
  175. /**
  176. * @brief DMA handle Structure definition
  177. */
  178. typedef struct
  179. {
  180. DMA_Channel_TypeDef *Instance; /* DMA registers base address */
  181. DMA_InitParaTypeDef Init; /* DMA initialization parameters */
  182. void (*DMA_ITC_Callback)(void); /* DMA transfer complete callback */
  183. void (*DMA_IE_Callback)(void); /* DMA error complete callback */
  184. }DMA_HandleTypeDef;
  185. /**
  186. * @brief DMA Link List Item Structure
  187. */
  188. typedef struct DMA_NextLink
  189. {
  190. uint32_t SrcAddr; /* source address */
  191. uint32_t DstAddr; /* desination address */
  192. struct DMA_NextLink *Next; /* Next Link */
  193. uint32_t Control; /* Control */
  194. }DMA_LLI_InitTypeDef;
  195. /** @defgroup GPIO Private Macros
  196. * @{
  197. */
  198. #define IS_DMA_MODE(MODE) (((MODE) == DMA_NORMAL ) || \
  199. ((MODE) == DMA_CIRCULAR))
  200. #define IS_DMA_ALL_INSTANCE(INSTANCE) (((INSTANCE) == DMA_Channel0) || \
  201. ((INSTANCE) == DMA_Channel1) || \
  202. ((INSTANCE) == DMA_Channel2) || \
  203. ((INSTANCE) == DMA_Channel3) || \
  204. ((INSTANCE) == DMA_Channel4) || \
  205. ((INSTANCE) == DMA_Channel5) || \
  206. ((INSTANCE) == DMA_Channel6) || \
  207. ((INSTANCE) == DMA_Channel7))
  208. #define IS_DMA_DATA_FLOW(DATA_FLOW) (((DATA_FLOW) == DMA_DATA_FLOW_M2M) || \
  209. ((DATA_FLOW) == DMA_DATA_FLOW_M2P) || \
  210. ((DATA_FLOW) == DMA_DATA_FLOW_P2M))
  211. #define IS_DMA_REQUEST_ID(REQUEST_ID) ((REQUEST_ID < REQ_MAX_LIMIT) ? true : false)
  212. #define IS_DMA_SRC_WIDTH(WIDTH) (((WIDTH) == DMA_SRC_WIDTH_BYTE) || \
  213. ((WIDTH) == DMA_SRC_WIDTH_HALF_WORD) || \
  214. ((WIDTH) == DMA_SRC_WIDTH_WORD))
  215. #define IS_DMA_DST_WIDTH(WIDTH) (((WIDTH) == DMA_DST_WIDTH_BYTE) || \
  216. ((WIDTH) == DMA_DST_WIDTH_HALF_WORD) || \
  217. ((WIDTH) == DMA_DST_WIDTH_WORD))
  218. /**
  219. * @}
  220. */
  221. /* Exported functions --------------------------------------------------------*/
  222. #define __HAL_LINK_DMA(_HANDLE_, _DMA_LINK_, _DMA_HANDLE_) (_HANDLE_._DMA_LINK_ = &_DMA_HANDLE_)
  223. /* HAL_DMA_IRQHandler */
  224. void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma);
  225. /* HAL_DMA_Init */
  226. HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma);
  227. /* HAL_DMA_DeInit */
  228. HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma);
  229. /* HAL_DMA_Start */
  230. HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t fu32_SrcAddr, uint32_t fu32_DstAddr, uint32_t fu32_Size);
  231. /* HAL_DMA_Start */
  232. HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t fu32_SrcAddr, uint32_t fu32_DstAddr, uint32_t fu32_Size);
  233. /* HAL_DMA_Abort */
  234. HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma);
  235. /* HAL_DMA_GetState */
  236. HAL_StatusTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma);
  237. #endif