stm8l15x_dma.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /**
  2. ******************************************************************************
  3. * @file stm8l15x_dma.h
  4. * @author MCD Application Team
  5. * @version V1.6.1
  6. * @date 30-September-2014
  7. * @brief This file contains all the functions prototypes for the DMA
  8. * firmware library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM8L15x_DMA_H
  30. #define __STM8L15x_DMA_H
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "stm8l15x.h"
  33. /** @addtogroup STM8L15x_StdPeriph_Driver
  34. * @{
  35. */
  36. /** @addtogroup DMA
  37. * @{
  38. */
  39. /* Exported types ------------------------------------------------------------*/
  40. /** @addtogroup DMA_Exported_Types
  41. * @{
  42. */
  43. /** @defgroup DMA_Data_Transfer_Direction
  44. * @{
  45. */
  46. typedef enum
  47. {
  48. DMA_DIR_PeripheralToMemory = ((uint8_t)0x00), /*!< Data transfer direction is Peripheral To Memory */
  49. DMA_DIR_MemoryToPeripheral = ((uint8_t)0x08), /*!< Data transfer direction is Memory To Peripheral */
  50. DMA_DIR_Memory0ToMemory1 = ((uint8_t)0x40) /*!< Data transfer direction is Memory0 To Memory 1 */
  51. }DMA_DIR_TypeDef;
  52. #define IS_DMA_DIR(DIR) (((DIR) == DMA_DIR_MemoryToPeripheral) || \
  53. ((DIR) == DMA_DIR_PeripheralToMemory) || \
  54. ((DIR) == DMA_DIR_Memory0ToMemory1 ))
  55. /**
  56. * @}
  57. */
  58. /** @defgroup DMA_Mode
  59. * @{
  60. */
  61. typedef enum
  62. {
  63. DMA_Mode_Normal = ((uint8_t)0x00), /*!< DMA normal buffer mode*/
  64. DMA_Mode_Circular = ((uint8_t)0x10) /*!< DMA circular buffer mode */
  65. }DMA_Mode_TypeDef;
  66. #define IS_DMA_MODE(MODE) (((MODE) == DMA_Mode_Circular) || \
  67. ((MODE) == DMA_Mode_Normal))
  68. /**
  69. * @}
  70. */
  71. /** @defgroup DMA_Incremented_Mode
  72. * @{
  73. */
  74. typedef enum
  75. {
  76. DMA_MemoryIncMode_Dec = ((uint8_t)0x00), /*!< DMA memory incremented mode is decremental */
  77. DMA_MemoryIncMode_Inc = ((uint8_t)0x20) /*!< DMA memory incremented mode is incremental */
  78. }DMA_MemoryIncMode_TypeDef;
  79. #define IS_DMA_MEMORY_INC_MODE(MODE) (((MODE) == DMA_MemoryIncMode_Inc) || \
  80. ((MODE) == DMA_MemoryIncMode_Dec))
  81. /**
  82. * @}
  83. */
  84. /** @defgroup DMA_Priority
  85. * @{
  86. */
  87. typedef enum
  88. {
  89. DMA_Priority_Low = ((uint8_t)0x00), /*!< Software Priority is Low */
  90. DMA_Priority_Medium = ((uint8_t)0x10), /*!< Software Priority is Medium */
  91. DMA_Priority_High = ((uint8_t)0x20), /*!< Software Priority is High */
  92. DMA_Priority_VeryHigh = ((uint8_t)0x30) /*!< Software Priority is Very High*/
  93. }DMA_Priority_TypeDef;
  94. #define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_Priority_VeryHigh) || \
  95. ((PRIORITY) == DMA_Priority_High) || \
  96. ((PRIORITY) == DMA_Priority_Medium) || \
  97. ((PRIORITY) == DMA_Priority_Low))
  98. /**
  99. * @}
  100. */
  101. /** @defgroup DMA_Memory_Data_Size
  102. * @{
  103. */
  104. typedef enum
  105. {
  106. DMA_MemoryDataSize_Byte = ((uint8_t)0x00),/*!< Memory Data Size is 1 Byte */
  107. DMA_MemoryDataSize_HalfWord = ((uint8_t)0x08) /*!< Memory Data Size is 2 Bytes */
  108. }DMA_MemoryDataSize_TypeDef;
  109. #define IS_DMA_DATA_SIZE(SIZE) (((SIZE) == DMA_MemoryDataSize_Byte) || \
  110. ((SIZE) == DMA_MemoryDataSize_HalfWord))
  111. /**
  112. * @}
  113. */
  114. /** @defgroup DMA_Flags
  115. * @{
  116. */
  117. typedef enum
  118. {
  119. DMA1_FLAG_GB = ((uint16_t)0x0002), /*!< Global Busy Flag */
  120. DMA1_FLAG_IFC0 = ((uint16_t)0x1001), /*!< Global Interrupt Flag Channel 0 */
  121. DMA1_FLAG_IFC1 = ((uint16_t)0x1002), /*!< Global Interrupt Flag Channel 1 */
  122. DMA1_FLAG_IFC2 = ((uint16_t)0x1004), /*!< Global Interrupt Flag Channel 2 */
  123. DMA1_FLAG_IFC3 = ((uint16_t)0x1008), /*!< Global Interrupt Flag Channel 3 */
  124. DMA1_FLAG_TC0 = ((uint16_t)0x0102), /*!< Transaction Complete Interrupt Flag Channel 0 */
  125. DMA1_FLAG_TC1 = ((uint16_t)0x0202), /*!< Transaction Complete Interrupt Flag Channel 1 */
  126. DMA1_FLAG_TC2 = ((uint16_t)0x0402), /*!< Transaction Complete Interrupt Flag Channel 2 */
  127. DMA1_FLAG_TC3 = ((uint16_t)0x0802), /*!< Transaction Complete Interrupt Flag Channel 3 */
  128. DMA1_FLAG_HT0 = ((uint16_t)0x0104), /*!< Half Transaction Interrupt Flag Channel 0 */
  129. DMA1_FLAG_HT1 = ((uint16_t)0x0204), /*!< Half Transaction Interrupt Flag Channel 1 */
  130. DMA1_FLAG_HT2 = ((uint16_t)0x0404), /*!< Half Transaction Interrupt Flag Channel 2 */
  131. DMA1_FLAG_HT3 = ((uint16_t)0x0804), /*!< Half Transaction Interrupt Flag Channel 3 */
  132. DMA1_FLAG_PEND0 = ((uint16_t)0x0140), /*!< DMA Request pending on Channel 0 */
  133. DMA1_FLAG_PEND1 = ((uint16_t)0x0240), /*!< DMA Request pending on Channel 1 */
  134. DMA1_FLAG_PEND2 = ((uint16_t)0x0440), /*!< DMA Request pending on Channel 2 */
  135. DMA1_FLAG_PEND3 = ((uint16_t)0x0840), /*!< DMA Request pending on Channel 3 */
  136. DMA1_FLAG_BUSY0 = ((uint16_t)0x0180), /*!< No DMA transfer on going in Channel 0 */
  137. DMA1_FLAG_BUSY1 = ((uint16_t)0x0280), /*!< No DMA transfer on going in Channel 1 */
  138. DMA1_FLAG_BUSY2 = ((uint16_t)0x0480), /*!< No DMA transfer on going in Channel 2 */
  139. DMA1_FLAG_BUSY3 = ((uint16_t)0x0880) /*!< No DMA transfer on going in Channel 3 */
  140. }DMA_FLAG_TypeDef;
  141. #define IS_DMA_GET_FLAG(FLAG) (((FLAG) == DMA1_FLAG_GB) || \
  142. ((FLAG) == DMA1_FLAG_IFC0) || \
  143. ((FLAG) == DMA1_FLAG_IFC1) || \
  144. ((FLAG) == DMA1_FLAG_IFC2) || \
  145. ((FLAG) == DMA1_FLAG_IFC3) || \
  146. ((FLAG) == DMA1_FLAG_TC0) || \
  147. ((FLAG) == DMA1_FLAG_TC1) || \
  148. ((FLAG) == DMA1_FLAG_TC2) || \
  149. ((FLAG) == DMA1_FLAG_TC3) || \
  150. ((FLAG) == DMA1_FLAG_HT0) || \
  151. ((FLAG) == DMA1_FLAG_HT1) || \
  152. ((FLAG) == DMA1_FLAG_HT2) || \
  153. ((FLAG) == DMA1_FLAG_HT3) || \
  154. ((FLAG) == DMA1_FLAG_PEND0) || \
  155. ((FLAG) == DMA1_FLAG_PEND1) || \
  156. ((FLAG) == DMA1_FLAG_PEND2) || \
  157. ((FLAG) == DMA1_FLAG_PEND3) || \
  158. ((FLAG) == DMA1_FLAG_BUSY0) || \
  159. ((FLAG) == DMA1_FLAG_BUSY1) || \
  160. ((FLAG) == DMA1_FLAG_BUSY2) || \
  161. ((FLAG) == DMA1_FLAG_BUSY3))
  162. #define IS_DMA_CLEAR_FLAG(FLAG) (((FLAG) == DMA1_FLAG_TC0) || \
  163. ((FLAG) == DMA1_FLAG_TC1) || \
  164. ((FLAG) == DMA1_FLAG_TC2) || \
  165. ((FLAG) == DMA1_FLAG_TC3) || \
  166. ((FLAG) == DMA1_FLAG_HT0) || \
  167. ((FLAG) == DMA1_FLAG_HT1) || \
  168. ((FLAG) == DMA1_FLAG_HT2) || \
  169. ((FLAG) == DMA1_FLAG_HT3) || \
  170. ((FLAG) == (DMA1_FLAG_TC0 |DMA1_FLAG_HT0)) || \
  171. ((FLAG) == (DMA1_FLAG_TC1 |DMA1_FLAG_HT1)) || \
  172. ((FLAG) == (DMA1_FLAG_TC2 |DMA1_FLAG_HT2)) || \
  173. ((FLAG) == (DMA1_FLAG_TC3 |DMA1_FLAG_HT3)))
  174. /**
  175. * @}
  176. */
  177. /** @defgroup DMA_One_Channel_Interrupts
  178. * @{
  179. */
  180. typedef enum
  181. {
  182. DMA_ITx_TC = ((uint8_t)0x02),/*!< Transaction Complete Interrupt */
  183. DMA_ITx_HT = ((uint8_t)0x04) /*!< Half Transaction Interrupt*/
  184. }DMA_ITx_TypeDef;
  185. #define IS_DMA_CONFIG_ITX(IT) ((((IT) & 0xF9) == 0x00) && ((IT) != 0x00))
  186. /**
  187. * @}
  188. */
  189. /** @defgroup DMA_Interrupts
  190. * @{
  191. */
  192. typedef enum
  193. {
  194. /* Transaction Complete Interrupts*/
  195. DMA1_IT_TC0 = ((uint8_t)0x12), /*!< Transaction Complete Interrupt Channel 0 */
  196. DMA1_IT_TC1 = ((uint8_t)0x22), /*!< Transaction Complete Interrupt Channel 1 */
  197. DMA1_IT_TC2 = ((uint8_t)0x42), /*!< Transaction Complete Interrupt Channel 2 */
  198. DMA1_IT_TC3 = ((uint8_t)0x82), /*!< Transaction Complete Interrupt Channel 3 */
  199. /* Half Transaction Interrupts */
  200. DMA1_IT_HT0 = ((uint8_t)0x14), /*!< Half Transaction Interrupt Channel 0 */
  201. DMA1_IT_HT1 = ((uint8_t)0x24), /*!< Half Transaction Interrupt Channel 1 */
  202. DMA1_IT_HT2 = ((uint8_t)0x44), /*!< Half Transaction Interrupt Channel 2 */
  203. DMA1_IT_HT3 = ((uint8_t)0x84) /*!< Half Transaction Interrupt Channel 3 */
  204. }DMA_IT_TypeDef;
  205. #define IS_DMA_CLEAR_IT(IT) (((IT) == DMA1_IT_TC0) || \
  206. ((IT) == DMA1_IT_TC1) || \
  207. ((IT) == DMA1_IT_TC2) || \
  208. ((IT) == DMA1_IT_TC3) || \
  209. ((IT) == DMA1_IT_HT0) || \
  210. ((IT) == DMA1_IT_HT1) || \
  211. ((IT) == DMA1_IT_HT2) || \
  212. ((IT) == DMA1_IT_HT3) || \
  213. ((IT) == (DMA1_IT_TC0|DMA1_IT_HT0)) || \
  214. ((IT) == (DMA1_IT_TC1|DMA1_IT_HT1)) || \
  215. ((IT) == (DMA1_IT_TC2|DMA1_IT_HT2)) || \
  216. ((IT) == (DMA1_IT_TC3|DMA1_IT_HT3)))
  217. #define IS_DMA_GET_IT(IT)(((IT) == DMA1_IT_TC0) || \
  218. ((IT) == DMA1_IT_TC1) || \
  219. ((IT) == DMA1_IT_TC2) || \
  220. ((IT) == DMA1_IT_TC3) || \
  221. ((IT) == DMA1_IT_HT0) || \
  222. ((IT) == DMA1_IT_HT1) || \
  223. ((IT) == DMA1_IT_HT2) || \
  224. ((IT) == DMA1_IT_HT3))
  225. /**
  226. * @}
  227. */
  228. /**
  229. * @}
  230. */
  231. /* Exported constants --------------------------------------------------------*/
  232. /* Exported macro ------------------------------------------------------------*/
  233. /** @addtogroup DMA_Exported_Macros
  234. * @{
  235. */
  236. /** @defgroup DMA_Channels
  237. * @{
  238. */
  239. #define IS_DMA_CHANNEL(PERIPH) (((*(uint16_t*)&(PERIPH)) == DMA1_Channel0_BASE) || \
  240. ((*(uint16_t*)&(PERIPH)) == DMA1_Channel1_BASE) || \
  241. ((*(uint16_t*)&(PERIPH)) == DMA1_Channel2_BASE) || \
  242. ((*(uint16_t*)&(PERIPH)) == DMA1_Channel3_BASE))
  243. /**
  244. * @}
  245. */
  246. /** @defgroup DMA_Buffer_Size
  247. * @{
  248. */
  249. #define IS_DMA_BUFFER_SIZE(SIZE) ((SIZE) > (uint8_t)0x0)
  250. /**
  251. * @}
  252. */
  253. /** @defgroup DMA_Timeout
  254. * @{
  255. */
  256. #define IS_DMA_TIMEOUT(TIME) ((TIME) < (uint8_t)0x40)
  257. /**
  258. * @}
  259. */
  260. /**
  261. * @}
  262. */
  263. /* Exported functions ------------------------------------------------------- */
  264. /* Functions used to set the DMA configuration to the default reset state ****/
  265. void DMA_GlobalDeInit(void);
  266. void DMA_DeInit(DMA_Channel_TypeDef* DMA_Channelx);
  267. /* Initialization and Configuration functions *********************************/
  268. void DMA_Init(DMA_Channel_TypeDef* DMA_Channelx,
  269. uint32_t DMA_Memory0BaseAddr,
  270. uint16_t DMA_PeripheralMemory1BaseAddr,
  271. uint8_t DMA_BufferSize,
  272. DMA_DIR_TypeDef DMA_DIR,
  273. DMA_Mode_TypeDef DMA_Mode,
  274. DMA_MemoryIncMode_TypeDef DMA_MemoryIncMode,
  275. DMA_Priority_TypeDef DMA_Priority,
  276. DMA_MemoryDataSize_TypeDef DMA_MemoryDataSize );
  277. void DMA_GlobalCmd(FunctionalState NewState);
  278. void DMA_Cmd(DMA_Channel_TypeDef* DMA_Channelx, FunctionalState NewState);
  279. void DMA_SetTimeOut(uint8_t DMA_TimeOut);
  280. /* Data Counter functions *****************************************************/
  281. void DMA_SetCurrDataCounter(DMA_Channel_TypeDef* DMA_Channelx, uint8_t DataNumber);
  282. uint8_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMA_Channelx);
  283. /* Interrupts and flags management functions **********************************/
  284. void DMA_ITConfig(DMA_Channel_TypeDef* DMA_Channelx, DMA_ITx_TypeDef DMA_ITx, FunctionalState NewState);
  285. FlagStatus DMA_GetFlagStatus(DMA_FLAG_TypeDef DMA_FLAG);
  286. void DMA_ClearFlag(DMA_FLAG_TypeDef DMA_FLAG);
  287. ITStatus DMA_GetITStatus(DMA_IT_TypeDef DMA_IT);
  288. void DMA_ClearITPendingBit(DMA_IT_TypeDef DMA_IT);
  289. #endif /*__STM8L15x_DMA_H */
  290. /**
  291. * @}
  292. */
  293. /**
  294. * @}
  295. */
  296. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/