air105_dma.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef __AIR105_DMA_H
  22. #define __AIR105_DMA_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "air105.h"
  28. typedef struct
  29. {
  30. uint32_t DMA_Peripheral;
  31. uint32_t DMA_PeripheralBaseAddr; /*!< Specifies the peripheral base address for DMAy Channelx. */
  32. uint32_t DMA_MemoryBaseAddr; /*!< Specifies the memory base address for DMAy Channelx. */
  33. uint32_t DMA_DIR; /*!< Specifies if the peripheral is the source or destination.
  34. This parameter can be a value of @ref DMA_data_transfer_direction */
  35. uint32_t DMA_PeripheralInc; /*!< Specifies whether the Peripheral address register is incremented or not.
  36. This parameter can be a value of @ref DMA_incremented_mode */
  37. uint32_t DMA_MemoryInc; /*!< Specifies whether the memory address register is incremented or not.
  38. This parameter can be a value of @ref DMA_incremented_mode */
  39. uint32_t DMA_PeripheralDataSize; /*!< Specifies the Peripheral data item width.
  40. This parameter can be a value of @ref DMA_data_size */
  41. uint32_t DMA_MemoryDataSize; /*!< Specifies the Memory data item width.
  42. This parameter can be a value of @ref DMA_data_size */
  43. uint32_t DMA_PeripheralBurstSize; /*!< Specifies the Peripheral Number of data items during per burst transaction.
  44. read or write from the Peripheral every time a burst transaction request
  45. This parameter can be a value of @ref DMA_burst_size */
  46. uint32_t DMA_MemoryBurstSize; /*!< Specifies the Memory Number of data items during per burst transaction.
  47. read or write from the Memory every time a burst transaction request
  48. This parameter can be a value of @ref DMA_burst_size */
  49. uint32_t DMA_PeripheralHandShake; /*!< Specifies the HandShake to control the DMA transacation.
  50. This parameter can be a value of @ref DMA_peripheral_handshake */
  51. uint32_t DMA_BlockSize; /*!< Specifies the Total Number of data items during the transaction. */
  52. uint32_t DMA_Priority; /*!< Specifies the software priority for the DMAy Channelx.
  53. This parameter can be a value of @ref DMA_priority_level */
  54. }DMA_InitTypeDef;
  55. /**
  56. * DMA多块传输内存表
  57. *
  58. */
  59. typedef struct _lli
  60. {
  61. uint32_t SAR;
  62. uint32_t DAR;
  63. uint32_t LLP;
  64. uint32_t CTL_L;
  65. uint32_t CTL_H;
  66. uint32_t DSTAT;
  67. }LLI;
  68. /**多块传输模式
  69. * @}
  70. */
  71. #define Multi_Block_MODE01 (uint8_t)0x00 /*Single-block or last transfer of multi-block*/
  72. #define Multi_Block_MODE02 (uint8_t)0x01 /*Auto-reload multi-block transfer with contiguous SAR*/
  73. #define Multi_Block_MODE03 (uint8_t)0x02 /*Auto-reload multi-block transfer with contiguous DAR*/
  74. #define Multi_Block_MODE04 (uint8_t)0x03 /*Auto-reload multi-block transfer*/
  75. #define Multi_Block_MODE05 (uint8_t)0x04 /*Single-block or last transfer of multi-block*/
  76. #define Multi_Block_MODE06 (uint8_t)0x05 /*Linked list multi-block transfer with contiguous SAR*/
  77. #define Multi_Block_MODE07 (uint8_t)0x06 /*Linked list multi-block transfer with auto-reload SAR*/
  78. #define Multi_Block_MODE08 (uint8_t)0x07 /*Linked list multi-block transfer with contiguous DAR*/
  79. #define Multi_Block_MODE09 (uint8_t)0x08 /*Linked list multi-block transfer with auto-reload DAR*/
  80. #define Multi_Block_MODE10 (uint8_t)0x09 /*Linked list multi-block transfer*/
  81. /** @defgroup DMA_data_transfer_direction
  82. * @{
  83. */
  84. #define DMA_DIR_Memory_To_Memory ((uint32_t)0x0000)
  85. #define DMA_DIR_Memory_To_Peripheral ((uint32_t)0x0001)
  86. #define DMA_DIR_Peripheral_To_Memory ((uint32_t)0x0002)
  87. /**
  88. * @}
  89. */
  90. /** @defgroup DMA_incremented_mode
  91. * @{
  92. */
  93. #define DMA_Inc_Increment ((uint32_t)0x00000000)
  94. #define DMA_Inc_Decrement ((uint32_t)0x00000001)
  95. #define DMA_Inc_Nochange ((uint32_t)0x00000002)
  96. #define IS_DMA_INC_STATE(STATE) (((STATE) == DMA_Inc_Increment) || \
  97. ((STATE) == DMA_Inc_Decrement) || \
  98. ((STATE) == DMA_Inc_Nochange))
  99. /**
  100. * @}
  101. */
  102. /** @defgroup DMA_data_size
  103. * @{
  104. */
  105. #define DMA_DataSize_Byte ((uint32_t)0x0000)
  106. #define DMA_DataSize_HalfWord ((uint32_t)0x0001)
  107. #define DMA_DataSize_Word ((uint32_t)0x0002)
  108. #define IS_DMA_DATA_SIZE(SIZE) (((SIZE) == DMA_DataSize_Byte) || \
  109. ((SIZE) == DMA_DataSize_HalfWord) || \
  110. ((SIZE) == DMA_DataSize_Word))
  111. /**
  112. * @}
  113. */
  114. /** @defgroup DMA_burst_size
  115. * @{
  116. */
  117. #define DMA_BurstSize_1 ((uint32_t)0x00)
  118. #define DMA_BurstSize_4 ((uint32_t)0x01)
  119. #define DMA_BurstSize_8 ((uint32_t)0x02)
  120. #define DMA_BurstSize_16 ((uint32_t)0x03)
  121. #define DMA_BurstSize_32 ((uint32_t)0x04)
  122. /**
  123. * @}
  124. */
  125. /** @defgroup DMA_peripheral_handshake
  126. * @{
  127. */
  128. #define DMA_PeripheralHandShake_Hardware ((uint32_t)0x0000)
  129. #define DMA_PeripheralHandShake_Software ((uint32_t)0x0001)
  130. /**
  131. * @}
  132. */
  133. /** @defgroup DMA_Priority
  134. * @{
  135. */
  136. #define DMA_Priority_0 ((uint32_t)0x00000000)
  137. #define DMA_Priority_1 ((uint32_t)0x00000020)
  138. #define DMA_Priority_2 ((uint32_t)0x00000040)
  139. #define DMA_Priority_3 ((uint32_t)0x00000060)
  140. #define DMA_Priority_4 ((uint32_t)0x00000080)
  141. #define DMA_Priority_5 ((uint32_t)0x000000A0)
  142. #define DMA_Priority_6 ((uint32_t)0x000000C0)
  143. /**
  144. * @}
  145. */
  146. /** @defgroup DMA_IT
  147. * @{
  148. */
  149. #define DMA_IT_BlockTransferComplete ((uint32_t)0x01)
  150. #define DMA_IT_DestinationTransactionComplete ((uint32_t)0x02)
  151. #define DMA_IT_Error ((uint32_t)0x04)
  152. #define DMA_IT_SourceTransactionComplete ((uint32_t)0x08)
  153. #define DMA_IT_DMATransferComplete ((uint32_t)0x10)
  154. /**
  155. * @}
  156. */
  157. void DMA_Init(DMA_TypeDef* DMA_Channelx, DMA_InitTypeDef* DMA_InitStruct);
  158. void DMA_ChannelCmd(DMA_TypeDef* DMA_Channelx, FunctionalState NewState);
  159. void DMA_Cmd(FunctionalState NewState);
  160. void DMA_ChannelConfig(DMA_TypeDef* DMA_Channelx, uint32_t DMA_Peripheral, uint32_t DMA_DIR);
  161. void DMA_SetSRCAddress(DMA_TypeDef* DMA_Channelx, uint32_t Address);
  162. void DMA_SetDSRAddress(DMA_TypeDef* DMA_Channelx, uint32_t Address);
  163. void DMA_ITConfig(DMA_TypeDef* DMA_Channelx, uint32_t DMA_IT, FunctionalState NewState);
  164. FlagStatus DMA_GetFlagStatus(uint32_t DMA_FLAG);
  165. void DMA_ClearFlag(uint32_t DMA_FLAG);
  166. FunctionalState DMA_IsChannelEnabled(DMA_TypeDef* DMA_Channelx);
  167. ITStatus DMA_GetITStatus(DMA_TypeDef* DMA_Channelx,uint32_t DMA_IT);
  168. FlagStatus DMA_GetRawStatus(DMA_TypeDef* DMA_Channelx,uint32_t DMA_IT);
  169. void DMA_ClearITPendingBit(DMA_TypeDef* DMA_Channelx,uint32_t DMA_IT);
  170. void DMA_MultiBlockInit(DMA_TypeDef* DMA_Channelx, DMA_InitTypeDef* DMA_InitStruct ,\
  171. LLI *first_lli,uint8_t Multi_Block_Mode);
  172. void DMA_InitLLI(DMA_TypeDef* DMA_Channelx,LLI *lli,LLI *next_lli,
  173. void *src_addr,void *dest_addr,uint16_t btsize);
  174. uint32_t DMA_GetTransferNum(DMA_TypeDef* DMA_Channelx, uint32_t first_adr);
  175. #ifdef __cplusplus
  176. }
  177. #endif
  178. #endif
  179. /************************** (C) COPYRIGHT Megahunt *****END OF FILE****/