dma.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. /* Peripheral group ----------------------------------------------------------- */
  29. /** @defgroup GPDMA GPDMA (General Purpose Direct Memory Access)
  30. * @ingroup LPC177x_8xCMSIS_FwLib_Drivers
  31. * @{
  32. */
  33. #ifndef __DMA_H_
  34. #define __DMA_H_
  35. /* Includes ------------------------------------------------------------------- */
  36. #include "ap_cp.h"
  37. #include "common.h"
  38. //#include "lpc_types.h"
  39. #ifdef __cplusplus
  40. extern "C"
  41. {
  42. #endif
  43. /* Public Macros -------------------------------------------------------------- */
  44. /** @defgroup GPDMA_Public_Macros GPDMA Public Macros
  45. * @{
  46. */
  47. /** DMA Connection number definitions */
  48. typedef enum{
  49. DMA_CONN_MEM=0,// ((0)) /*memory*/
  50. DMA_CONN_MCI,// ((1UL)) /** SD card */
  51. DMA_CONN_SSP0_Tx,// ((2UL)) /**< SSP0 Tx */
  52. DMA_CONN_SSP0_Rx,// ((3UL)) /**< SSP0 Rx */
  53. DMA_CONN_SSP1_Tx,// ((4UL)) /**< SSP1 Tx */
  54. DMA_CONN_SSP1_Rx,// ((5UL)) /**< SSP1 Rx */
  55. DMA_CONN_SSP2_Tx,// ((6UL)) /**< SSP2 Tx */
  56. DMA_CONN_SSP2_Rx,// ((7UL)) /**< SSP2 Rx */
  57. DMA_CONN_ADC,// ((8UL)) /**< ADC */
  58. DMA_CONN_DAC,// ((9UL)) /**< DAC */
  59. DMA_CONN_UART0_Tx,// ((10UL)) /**< UART0 Tx */
  60. DMA_CONN_UART0_Rx,// ((11UL)) /**< UART0 Rx */
  61. DMA_CONN_UART1_Tx,// ((12UL)) /**< UART1 Tx */
  62. DMA_CONN_UART1_Rx,// ((13UL)) /**< UART1 Rx */
  63. DMA_CONN_UART2_Tx,// ((14UL)) /**< UART2 Tx */
  64. DMA_CONN_UART2_Rx,// ((15UL)) /**< UART2 Rx */
  65. DMA_CONN_MAT0_0,// ((16UL)) /**< MAT0.0 */
  66. DMA_CONN_MAT0_1,// ((17UL)) /**< MAT0.1 */
  67. DMA_CONN_MAT1_0,// ((18UL)) /**< MAT1.0 */
  68. DMA_CONN_MAT1_1,// ((19UL)) /**< MAT1.1 */
  69. DMA_CONN_MAT2_0,// ((20UL)) /**< MAT2.0 */
  70. DMA_CONN_MAT2_1,// ((21UL)) /**< MAT2.1 */
  71. DMA_CONN_I2S_Channel_0,// ((22UL)) /**< I2S channel 0 */
  72. DMA_CONN_I2S_Channel_1,// ((23UL)) /**< I2S channel 1 */
  73. DMA_CONN_UART3_Tx,// ((26UL)) /**< UART3 Tx */
  74. DMA_CONN_UART3_Rx,// ((27UL)) /**< UART3 Rx */
  75. DMA_CONN_UART4_Tx,// ((28UL)) /**< UART3 Tx */
  76. DMA_CONN_UART4_Rx,// ((29UL)) /**< UART3 Rx */
  77. DMA_CONN_MAT3_0,// ((30UL)) /**< MAT3.0 */
  78. DMA_CONN_MAT3_1// ((31UL)) /**< MAT3.1 */
  79. } dma_conn_t;
  80. /** Burst size in Source and Destination definitions */
  81. #define DMA_BSIZE_1 ((0UL)) /**< Burst size = 1 */
  82. #define DMA_BSIZE_4 ((1UL)) /**< Burst size = 4 */
  83. #define DMA_BSIZE_8 ((2UL)) /**< Burst size = 8 */
  84. #define DMA_BSIZE_16 ((3UL)) /**< Burst size = 16 */
  85. #define DMA_BSIZE_32 ((4UL)) /**< Burst size = 32 */
  86. #define DMA_BSIZE_64 ((5UL)) /**< Burst size = 64 */
  87. #define DMA_BSIZE_128 ((6UL)) /**< Burst size = 128 */
  88. #define DMA_BSIZE_256 ((7UL)) /**< Burst size = 256 */
  89. /** Width in Source transfer width and Destination transfer width definitions */
  90. #define DMA_WIDTH_BYTE ((0UL)) /**< Width = 1 byte */
  91. #define DMA_WIDTH_HALFWORD ((1UL)) /**< Width = 2 bytes */
  92. #define DMA_WIDTH_WORD ((2UL)) /**< Width = 4 bytes */
  93. /** DMA Request Select Mode definitions */
  94. #define DMA_REQSEL_UART ((0UL)) /**< UART TX/RX is selected */
  95. #define DMA_REQSEL_TIMER ((1UL)) /**< Timer match is selected */
  96. /**
  97. * @}
  98. */
  99. /* Private Macros ------------------------------------------------------------- */
  100. /** @defgroup GPDMA_Private_Macros GPDMA Private Macros
  101. * @{
  102. */
  103. /* --------------------- BIT DEFINITIONS -------------------------------------- */
  104. /*********************************************************************//**
  105. * Macro defines for DMA Interrupt Status register
  106. **********************************************************************/
  107. #define DMA_DMACIntStat_Ch(n) (((1UL<<n)&0xFF))
  108. #define DMA_DMACIntStat_BITMASK ((0xFF))
  109. /*********************************************************************//**
  110. * Macro defines for DMA Interrupt Terminal Count Request Status register
  111. **********************************************************************/
  112. #define DMA_DMACIntTCStat_Ch(n) (((1UL<<n)&0xFF))
  113. #define DMA_DMACIntTCStat_BITMASK ((0xFF))
  114. /*********************************************************************//**
  115. * Macro defines for DMA Interrupt Terminal Count Request Clear register
  116. **********************************************************************/
  117. #define DMA_DMACIntTCClear_Ch(n) (((1UL<<n)&0xFF))
  118. #define DMA_DMACIntTCClear_BITMASK ((0xFF))
  119. /*********************************************************************//**
  120. * Macro defines for DMA Interrupt Error Status register
  121. **********************************************************************/
  122. #define DMA_DMACIntErrStat_Ch(n) (((1UL<<n)&0xFF))
  123. #define DMA_DMACIntErrStat_BITMASK ((0xFF))
  124. /*********************************************************************//**
  125. * Macro defines for DMA Interrupt Error Clear register
  126. **********************************************************************/
  127. #define DMA_DMACIntErrClr_Ch(n) (((1UL<<n)&0xFF))
  128. #define DMA_DMACIntErrClr_BITMASK ((0xFF))
  129. /*********************************************************************//**
  130. * Macro defines for DMA Raw Interrupt Terminal Count Status register
  131. **********************************************************************/
  132. #define DMA_DMACRawIntTCStat_Ch(n) (((1UL<<n)&0xFF))
  133. #define DMA_DMACRawIntTCStat_BITMASK ((0xFF))
  134. /*********************************************************************//**
  135. * Macro defines for DMA Raw Error Interrupt Status register
  136. **********************************************************************/
  137. #define DMA_DMACRawIntErrStat_Ch(n) (((1UL<<n)&0xFF))
  138. #define DMA_DMACRawIntErrStat_BITMASK ((0xFF))
  139. /*********************************************************************//**
  140. * Macro defines for DMA Enabled Channel register
  141. **********************************************************************/
  142. #define DMA_DMACEnbldChns_Ch(n) (((1UL<<n)&0xFF))
  143. #define DMA_DMACEnbldChns_BITMASK ((0xFF))
  144. /*********************************************************************//**
  145. * Macro defines for DMA Software Burst Request register
  146. **********************************************************************/
  147. #define DMA_DMACSoftBReq_Src(n) (((1UL<<n)&0xFFFF))
  148. #define DMA_DMACSoftBReq_BITMASK ((0xFFFF))
  149. /*********************************************************************//**
  150. * Macro defines for DMA Software Single Request register
  151. **********************************************************************/
  152. #define DMA_DMACSoftSReq_Src(n) (((1UL<<n)&0xFFFF))
  153. #define DMA_DMACSoftSReq_BITMASK ((0xFFFF))
  154. /*********************************************************************//**
  155. * Macro defines for DMA Software Last Burst Request register
  156. **********************************************************************/
  157. #define DMA_DMACSoftLBReq_Src(n) (((1UL<<n)&0xFFFF))
  158. #define DMA_DMACSoftLBReq_BITMASK ((0xFFFF))
  159. /*********************************************************************//**
  160. * Macro defines for DMA Software Last Single Request register
  161. **********************************************************************/
  162. #define DMA_DMACSoftLSReq_Src(n) (((1UL<<n)&0xFFFF))
  163. #define DMA_DMACSoftLSReq_BITMASK ((0xFFFF))
  164. /*********************************************************************//**
  165. * Macro defines for DMA Configuration register
  166. **********************************************************************/
  167. #define DMA_DMACConfig_E ((0x01)) /**< DMA Controller enable*/
  168. #define DMA_DMACConfig_M ((0x02)) /**< AHB Master endianness configuration*/
  169. #define DMA_DMACConfig_BITMASK ((0x03))
  170. /*********************************************************************//**
  171. * Macro defines for DMA Synchronization register
  172. **********************************************************************/
  173. #define DMA_DMACSync_Src(n) (((1UL<<n)&0xFFFF))
  174. #define DMA_DMACSync_BITMASK ((0xFFFF))
  175. /*********************************************************************//**
  176. * Macro defines for DMA Request Select register
  177. **********************************************************************/
  178. #define DMA_DMAReqSel_Input(n) (((1UL<<(n-8))&0xFF))
  179. #define DMA_DMAReqSel_BITMASK ((0xFF))
  180. /*********************************************************************//**
  181. * Macro defines for DMA Channel Linked List Item registers
  182. **********************************************************************/
  183. /** DMA Channel Linked List Item registers bit mask*/
  184. #define DMA_DMACCxLLI_BITMASK ((0xFFFFFFFC))
  185. /*********************************************************************//**
  186. * Macro defines for DMA channel control registers
  187. **********************************************************************/
  188. /** Transfer size*/
  189. #define DMA_DMACCxControl_TransferSize(n) (((n&0xFFF)<<0))
  190. /** Source burst size*/
  191. #define DMA_DMACCxControl_SBSize(n) (((n&0x07)<<12))
  192. /** Destination burst size*/
  193. #define DMA_DMACCxControl_DBSize(n) (((n&0x07)<<15))
  194. /** Source transfer width*/
  195. #define DMA_DMACCxControl_SWidth(n) (((n&0x07)<<18))
  196. /** Destination transfer width*/
  197. #define DMA_DMACCxControl_DWidth(n) (((n&0x07)<<21))
  198. /** Source increment*/
  199. #define DMA_DMACCxControl_SI ((1UL<<26))
  200. /** Destination increment*/
  201. #define DMA_DMACCxControl_DI ((1UL<<27))
  202. /** Indicates that the access is in user mode or privileged mode*/
  203. #define DMA_DMACCxControl_Prot1 ((1UL<<28))
  204. /** Indicates that the access is bufferable or not bufferable*/
  205. #define DMA_DMACCxControl_Prot2 ((1UL<<29))
  206. /** Indicates that the access is cacheable or not cacheable*/
  207. #define DMA_DMACCxControl_Prot3 ((1UL<<30))
  208. /** Terminal count interrupt enable bit */
  209. #define DMA_DMACCxControl_I ((1UL<<31))
  210. /** DMA channel control registers bit mask */
  211. #define DMA_DMACCxControl_BITMASK ((0xFCFFFFFF))
  212. /*********************************************************************//**
  213. * Macro defines for DMA Channel Configuration registers
  214. **********************************************************************/
  215. /** DMA control enable*/
  216. #define DMA_DMACCxConfig_E ((1UL<<0))
  217. /** Source peripheral*/
  218. #define DMA_DMACCxConfig_SrcPeripheral(n) (((n&0x1F)<<1))
  219. /** Destination peripheral*/
  220. #define DMA_DMACCxConfig_DestPeripheral(n) (((n&0x1F)<<6))
  221. /** This value indicates the type of transfer*/
  222. #define DMA_DMACCxConfig_TransferType(n) (((n&0x7)<<11))
  223. /** Interrupt error mask*/
  224. #define DMA_DMACCxConfig_IE ((1UL<<14))
  225. /** Terminal count interrupt mask*/
  226. #define DMA_DMACCxConfig_ITC ((1UL<<15))
  227. /** Lock*/
  228. #define DMA_DMACCxConfig_L ((1UL<<16))
  229. /** Active*/
  230. #define DMA_DMACCxConfig_A ((1UL<<17))
  231. /** Halt*/
  232. #define DMA_DMACCxConfig_H ((1UL<<18))
  233. /** DMA Channel Configuration registers bit mask */
  234. #define DMA_DMACCxConfig_BITMASK ((0x7FFFF))
  235. /**
  236. * @}
  237. */
  238. #define DMA_TRANSFERTYPE_M2M ((0UL))
  239. /** GPDMA Transfer type definitions: Memory to peripheral - DMA control */
  240. #define DMA_TRANSFERTYPE_M2P ((1UL))
  241. /** GPDMA Transfer type definitions: Peripheral to memory - DMA control */
  242. #define DMA_TRANSFERTYPE_P2M ((2UL))
  243. /** Source peripheral to destination peripheral - DMA control */
  244. #define DMA_TRANSFERTYPE_P2P ((3UL))
  245. /* Public Types --------------------------------------------------------------- */
  246. /** @defgroup GPDMA_Public_Types GPDMA Public Types
  247. * @{
  248. */
  249. /**
  250. * @brief GPDMA Interrupt clear status enumeration
  251. */
  252. typedef enum{
  253. DMA_STATCLR_INTTC, /**< GPDMA Interrupt Terminal Count Request Clear */
  254. DMA_STATCLR_INTERR /**< GPDMA Interrupt Error Clear */
  255. }DMA_StateClear_Type;
  256. typedef void (*dma_hdl_t)(uint8 ev);
  257. /**
  258. * @brief DMA Channel configuration structure type definition
  259. */
  260. typedef struct {
  261. uint32_t transf_size; /**< Length/Size of transfer */
  262. bool si;
  263. uint32_t src_addr;
  264. dma_conn_t src_conn;
  265. bool di;
  266. uint32_t dst_addr;
  267. dma_conn_t dst_conn;
  268. uint32_t lli;
  269. bool enable_int;
  270. dma_hdl_t evt_handler;
  271. } dma_ch_cfg_t;
  272. typedef enum{
  273. DMA_CH_0 = 0,
  274. DMA_CH_1,
  275. DMA_CH_2,
  276. DMA_CH_3,
  277. DMA_CH_4,
  278. DMA_CH_5,
  279. DMA_CH_6,
  280. DMA_CH_7,
  281. DMA_CH_NUM,
  282. } dma_ch_t;
  283. /**
  284. * @brief GPDMA Linker List Item structure type definition
  285. */
  286. typedef struct {
  287. uint32_t src_addr; /**< Source Address */
  288. uint32_t dst_addr; /**< Destination address */
  289. uint32_t lli; /**< Next LLI address, otherwise set to '0' */
  290. uint32_t ctrl; /**< GPDMA Control of this LLI */
  291. } dma_lli_t;
  292. int dma_config_channel(dma_ch_t ch, dma_ch_cfg_t* cfg);
  293. int dma_start_channel(dma_ch_t ch, bool enable);
  294. int dma_wait_channel_complete(dma_ch_t ch);
  295. int dma_init(void);
  296. #ifdef __cplusplus
  297. }
  298. #endif
  299. #endif /* __LPC177X_8X_GPDMA_H_ */
  300. /**
  301. * @}
  302. */
  303. /* --------------------------------- End Of File ------------------------------ */