wm_dma.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /**
  2. * @file wm_dma.h
  3. *
  4. * @brief DMA Driver Module
  5. *
  6. * @author dave
  7. *
  8. * Copyright (c) 2014 Winner Microelectronics Co., Ltd.
  9. */
  10. #ifndef __WM_DMA_H_
  11. #define __WM_DMA_H_
  12. #define TLS_DMA_SEL_UART_RX 0
  13. #define TLS_DMA_SEL_UART_TX 1
  14. #define TLS_DMA_SEL_PWM_CAP0 2
  15. #define TLS_DMA_SEL_PWM_CAP1 3
  16. #define TLS_DMA_SEL_LSSPI_RX 4
  17. #define TLS_DMA_SEL_LSSPI_TX 5
  18. #define TLS_DMA_SEL_SDADC_CH0 6
  19. #define TLS_DMA_SEL_SDADC_CH1 7
  20. #define TLS_DMA_SEL_SDADC_CH2 8
  21. #define TLS_DMA_SEL_SDADC_CH3 9
  22. #define TLS_DMA_SEL_I2S_RX 10
  23. #define TLS_DMA_SEL_I2S_TX 11
  24. #define TLS_DMA_SEL_SDIO_HOST 12
  25. #define TLS_DMA_FLAGS_HARD_MODE (1 << 0)
  26. #define TLS_DMA_FLAGS_CHAIN_MODE (1 << 1)
  27. #define TLS_DMA_FLAGS_CHANNEL_SEL(n) ((n) << 2)
  28. #define TLS_DMA_FLAGS_CHAIN_LINK_EN (1 << 6)
  29. #define TLS_DMA_FLAGS_CHANNEL_VALID (1 << 7)
  30. #define TLS_DMA_DESC_VALID (1U << 31)
  31. #define TLS_DMA_DESC_CTRL_SRC_ADD_INC (1 << 0)
  32. #define TLS_DMA_DESC_CTRL_DEST_ADD_INC (1 << 2)
  33. #define TLS_DMA_DESC_CTRL_DATA_SIZE_BYTE (0 << 4)
  34. #define TLS_DMA_DESC_CTRL_DATA_SIZE_SHORT (1 << 4)
  35. #define TLS_DMA_DESC_CTRL_DATA_SIZE_WORD (2 << 4)
  36. #define TLS_DMA_DESC_CTRL_BURST_SIZE1 (0 << 6)
  37. #define TLS_DMA_DESC_CTRL_BURST_SIZE4 (1 << 6)
  38. #define TLS_DMA_DESC_CTRL_TOTAL_BYTES(n) ((n) << 7)
  39. /* dma interrupt flags */
  40. #define TLS_DMA_IRQ_BURST_DONE (1 << 0)
  41. #define TLS_DMA_IRQ_TRANSFER_DONE (1 << 1)
  42. #define TLS_DMA_IRQ_BOTH_DONE (TLS_DMA_IRQ_BURST_DONE | TLS_DMA_IRQ_TRANSFER_DONE)
  43. struct tls_dma_descriptor {
  44. unsigned int valid;
  45. unsigned int dma_ctrl;
  46. unsigned int src_addr;
  47. unsigned int dest_addr;
  48. struct tls_dma_descriptor *next; /**< next dms descriptor */
  49. };
  50. /**
  51. * @defgroup Driver_APIs Driver APIs
  52. * @brief Driver APIs
  53. */
  54. /**
  55. * @addtogroup Driver_APIs
  56. * @{
  57. */
  58. /**
  59. * @defgroup DMA_Driver_APIs DMA Driver APIs
  60. * @brief DMA driver APIs
  61. */
  62. /**
  63. * @addtogroup DMA_Driver_APIs
  64. * @{
  65. */
  66. /**
  67. * @brief This function is used to clear dma interrupt flag.
  68. *
  69. * @param[in] ch Channel no.[0~7]
  70. * @param[in] flags Flags setted to TLS_DMA_IRQ_BURST_DONE, TLS_DMA_IRQ_TRANSFER_DONE, TLS_DMA_IRQ_BOTH_DONE.
  71. *
  72. * @return None
  73. *
  74. * @note None
  75. */
  76. void tls_dma_irq_clr(unsigned char ch, unsigned char flags);
  77. /**
  78. * @brief This function is used to register dma interrupt callback function.
  79. *
  80. * @param[in] ch Channel no.[0~7]
  81. * @param[in] callback is the dma interrupt call back function.
  82. * @param[in] arg the param of the callback function.
  83. * @param[in] flags Flags setted to TLS_DMA_IRQ_BURST_DONE, TLS_DMA_IRQ_TRANSFER_DONE, TLS_DMA_IRQ_BOTH_DONE.
  84. *
  85. * @return None
  86. *
  87. * @note None
  88. */
  89. void tls_dma_irq_register(unsigned char ch, void (*callback)(void *p), void *arg, unsigned char flags);
  90. /**
  91. * @brief This function is used to register dma interrupt
  92. *
  93. * @param[in] ch DMA channel no.[0~7]
  94. *
  95. * @return None
  96. *
  97. * @note None
  98. */
  99. int tls_dma_wait_complt(unsigned char ch);
  100. /**
  101. * @brief This function is used to Start the DMA controller by Wrap
  102. *
  103. * @param[in] autoReload Does restart when current transfer complete?
  104. * @param[in] ch Channel no.[0~7]
  105. * @param[in] pDmaDesc Pointer to DMA channel descriptor structure.
  106. *
  107. * @retval Always STATUS_SUCCESS.
  108. *
  109. * @note
  110. * DMA Descriptor:
  111. * +--------------------------------------------------------------+
  112. * |Vld[31] | RSV |
  113. * +--------------------------------------------------------------+
  114. * | RSV | Dma_Ctrl[16:0] |
  115. * +--------------------------------------------------------------+
  116. * | Src_Addr[31:0] |
  117. * +--------------------------------------------------------------+
  118. * | Dest_Addr[31:0] |
  119. * +--------------------------------------------------------------+
  120. * | Next_Desc_Add[31:0] |
  121. * +--------------------------------------------------------------+
  122. */
  123. unsigned char tls_dma_start_by_wrap(unsigned char ch, struct tls_dma_descriptor *dma_desc,
  124. unsigned char auto_reload, unsigned short src_zize,
  125. unsigned short dest_zize);
  126. /**
  127. * @brief This function is used to Wait until DMA operation completes
  128. *
  129. * @param[in] autoReload Does restart when current transfer complete?
  130. * @param[in] ch Channel no.[0~7]
  131. * @param[in] pDmaDesc Pointer to DMA channel descriptor structure.
  132. *
  133. * @retval Always STATUS_SUCCESS.
  134. *
  135. * @note
  136. * DMA Descriptor:
  137. * +--------------------------------------------------------------+
  138. * |Vld[31] | RSV |
  139. * +--------------------------------------------------------------+
  140. * | RSV | Dma_Ctrl[16:0] |
  141. * +--------------------------------------------------------------+
  142. * | Src_Addr[31:0] |
  143. * +--------------------------------------------------------------+
  144. * | Dest_Addr[31:0] |
  145. * +--------------------------------------------------------------+
  146. * | Next_Desc_Add[31:0] |
  147. * +--------------------------------------------------------------+
  148. */
  149. unsigned char tls_dma_start(unsigned char ch, struct tls_dma_descriptor *dma_desc,
  150. unsigned char auto_reload);
  151. /**
  152. * @brief This function is used to To stop current DMA channel transfer
  153. *
  154. * @param[in] ch channel no. to be stopped
  155. *
  156. * @retval Always STATUS_SUCCESS
  157. *
  158. * @note If channel stop, DMA_CHNL_CTRL_CHNL_ON bit in DMA_CHNLCTRL_REG is cleared.
  159. */
  160. unsigned char tls_dma_stop(unsigned char ch);
  161. /**
  162. * @brief This function is used to Request a free dma channel
  163. * If ch is out of range [0,7] or valid but used, the function will select another free channel.
  164. * else return the selected channel no.
  165. * @param[in] ch specified channel when ch is valid and not used.
  166. * @param[in] flags flags setted to selected channel
  167. *
  168. * @return Real DMA Channel No: if there is free dma channel.
  169. * 0xFF: when DMA channels are all used.
  170. *
  171. * @note If ch is invalid or valid but used, the function will select another free channel.
  172. * else return the selected channel no.
  173. */
  174. unsigned char tls_dma_request(unsigned char ch, unsigned char flags);
  175. /**
  176. * @brief This function is used to Free the DMA channel when not use
  177. *
  178. * @param[in] ch channel no. that is ready to free
  179. *
  180. * @return None
  181. *
  182. * @note None
  183. */
  184. void tls_dma_free(unsigned char ch);
  185. /**
  186. * @brief This function is used to Initialize DMA Control
  187. *
  188. * @param[in] None
  189. *
  190. * @return None
  191. *
  192. * @note None
  193. */
  194. void tls_dma_init(void);
  195. /**
  196. * @}
  197. */
  198. /**
  199. * @}
  200. */
  201. #endif /* __TLS_DMA_H_151606__ */