fh_dma.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * This file is part of FH8620 BSP for RT-Thread distribution.
  3. *
  4. * Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Visit http://www.fullhan.com to get contact with Fullhan.
  22. *
  23. * Change Logs:
  24. * Date Author Notes
  25. */
  26. #ifndef FH_DMA_H_
  27. #define FH_DMA_H_
  28. /****************************************************************************
  29. * #include section
  30. * add #include here if any
  31. ***************************************************************************/
  32. #include <rtthread.h>
  33. /*********************************
  34. *
  35. * DMA SOC define start
  36. *
  37. *********************************/
  38. #define FH81_MAX_CHANNEL (4)
  39. #define FH81_CHANNEL_MAX_TRANSFER_SIZE (4095)
  40. enum DMA_HW_HS_MAP{
  41. ACODEC_RX = 0,
  42. ACODEC_TX,
  43. SPI0_RX,
  44. SPI0_TX,
  45. SPI1_RX,
  46. SPI1_TX,
  47. UART0_RX,
  48. UART0_TX,
  49. UART1_RX,
  50. UART1_TX,
  51. DMA_HW_HS_END,
  52. };
  53. /*********************************
  54. *
  55. * DMA SOC define end
  56. *
  57. *********************************/
  58. //user use the dma could use callback function,when the dma make the work done...
  59. typedef void (*dma_complete_callback)(void *complete_para);
  60. typedef void (*user_prepare)(void *prepare_para);
  61. /**************************** i'm cut-off line ************************************/
  62. //controller private para...
  63. struct fh81_dma;
  64. struct dw_lli {
  65. /* values that are not changed by hardware */
  66. rt_uint32_t sar;
  67. rt_uint32_t dar;
  68. rt_uint32_t llp; /* chain to next lli */
  69. rt_uint32_t ctllo;
  70. /* values that may get written back: */
  71. rt_uint32_t ctlhi;
  72. /* sstat and dstat can snapshot peripheral register state.
  73. * silicon config may discard either or both...
  74. */
  75. rt_uint32_t sstat;
  76. rt_uint32_t dstat;
  77. rt_uint32_t reserve;
  78. };
  79. //transfer use below
  80. struct dma_transfer{
  81. //this is private for the dma drive....app don't touch it,the driver will manger it
  82. //link interface for more transfer to the controller...
  83. rt_list_t transfer_list;
  84. struct fh81_dma *dma_controller;
  85. //this the mem add....the dma controller will load the setting to move data ....
  86. //user don't touch it
  87. struct dw_lli *first_lli;
  88. rt_uint32_t lli_size;
  89. //new add for allign get desc...
  90. rt_uint32_t actual_lli_size;
  91. //user could set paras below~~~
  92. #define AUTO_FIND_CHANNEL (0xff)
  93. //transfer with which dma channel...if the data is 0xff, the driver will auto find a free channel.
  94. rt_uint32_t channel_number;
  95. //which dma you want to use...for fh81....only 0!!!
  96. rt_uint32_t dma_number;
  97. //user should set the para below
  98. #define DMA_M2M (0) // MEM <=> MEM
  99. #define DMA_M2P (1) // MEM => peripheral A
  100. #define DMA_P2M (2) // MEM <= peripheral A
  101. #define DMA_P2P (3) // peripheral A <=> peripheral B
  102. rt_uint32_t fc_mode;//ip->mem. mem->mem. mem->ip
  103. #define DMA_HW_HANDSHAKING (0)
  104. #define DMA_SW_HANDSHAKING (1)
  105. rt_uint32_t src_hs; //src
  106. //if use hw handshaking ,you need to set the hw handshaking number, this SOC defined
  107. rt_uint32_t src_per; //src hw handshake number
  108. //rt_uint32_t irq_mode;//for each transfer,irq maybe not same. suggest for the default(transfer isr)
  109. #define DW_DMA_SLAVE_WIDTH_8BIT (0)
  110. #define DW_DMA_SLAVE_WIDTH_16BIT (1)
  111. #define DW_DMA_SLAVE_WIDTH_32BIT (2)
  112. rt_uint32_t src_width;
  113. //the user should reference the hw handshaking watermark..
  114. #define DW_DMA_SLAVE_MSIZE_1 (0)
  115. #define DW_DMA_SLAVE_MSIZE_4 (1)
  116. #define DW_DMA_SLAVE_MSIZE_8 (2)
  117. #define DW_DMA_SLAVE_MSIZE_16 (3)
  118. #define DW_DMA_SLAVE_MSIZE_32 (4)
  119. #define DW_DMA_SLAVE_MSIZE_64 (5)
  120. #define DW_DMA_SLAVE_MSIZE_128 (6)
  121. #define DW_DMA_SLAVE_MSIZE_256 (7)
  122. rt_uint32_t src_msize;
  123. rt_uint32_t src_add;
  124. #define DW_DMA_SLAVE_INC (0)
  125. #define DW_DMA_SLAVE_DEC (1)
  126. #define DW_DMA_SLAVE_FIX (2)
  127. rt_uint32_t src_inc_mode; //increase mode: increase or not change
  128. //#define DMA_DST_HW_HANDSHAKING (0)
  129. //#define DMA_DST_SW_HANDSHAKING (1)
  130. rt_uint32_t dst_hs; //src
  131. //if use hw handshaking ,you need to set the hw handshaking number, this SOC defined
  132. rt_uint32_t dst_per; //dst hw handshake number
  133. //#define DW_DMA_SLAVE_WIDTH_8BIT (0)
  134. //#define DW_DMA_SLAVE_WIDTH_16BIT (1)
  135. //#define DW_DMA_SLAVE_WIDTH_32BIT (2)
  136. rt_uint32_t dst_width;
  137. //#define DW_DMA_SLAVE_MSIZE_1 (0)
  138. //#define DW_DMA_SLAVE_MSIZE_4 (1)
  139. //#define DW_DMA_SLAVE_MSIZE_8 (2)
  140. //#define DW_DMA_SLAVE_MSIZE_16 (3)
  141. //#define DW_DMA_SLAVE_MSIZE_32 (4)
  142. //#define DW_DMA_SLAVE_MSIZE_64 (5)
  143. //#define DW_DMA_SLAVE_MSIZE_128 (6)
  144. //#define DW_DMA_SLAVE_MSIZE_256 (7)
  145. rt_uint32_t dst_msize;
  146. rt_uint32_t dst_add;
  147. //#define DW_DMA_SLAVE_INC (0)
  148. //#define DW_DMA_SLAVE_DEC (1)
  149. //#define DW_DMA_SLAVE_FIX (2)
  150. rt_uint32_t dst_inc_mode; //increase mode: increase or not change
  151. //total sizes, unit: src_width/DW_DMA_SLAVE_WIDTH_8BIT...
  152. //exg: src_width = DW_DMA_SLAVE_WIDTH_32BIT. trans_len = 2...means that: the dma will transfer 2*4 bytes..
  153. //exg: src_width = DW_DMA_SLAVE_WIDTH_8BIT. trans_len = 6...means that: the dma will transfer 1*6 bytes..
  154. rt_uint32_t trans_len;
  155. //this is used when dma finish transfer job
  156. dma_complete_callback complete_callback;
  157. void *complete_para; //for the driver data use the dma driver.
  158. //this is used when dma before work..the user maybe need to set his own private para..
  159. user_prepare prepare_callback;
  160. void *prepare_para;
  161. //add cyclic para...
  162. //period len..
  163. rt_uint32_t period_len;
  164. };
  165. /****************************************************************************
  166. * #define section
  167. * add constant #define here if any
  168. ***************************************************************************/
  169. /****************************************************************************
  170. * ADT section
  171. * add Abstract Data Type definition here
  172. ***************************************************************************/
  173. /****************************************************************************
  174. * extern variable declaration section
  175. ***************************************************************************/
  176. /****************************************************************************
  177. * section
  178. * add function prototype here if any
  179. ***************************************************************************/
  180. rt_err_t fh81_dma_register(struct fh81_dma * fh81_dma_p,
  181. char * dma_name);
  182. void rt_fh_dma_init(void);
  183. /********************************End Of File********************************/
  184. #endif /* FH81_DMA_H_ */