1
0

lpc_gpdma.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /**********************************************************************
  2. * $Id$ lpc_gpdma.h 2011-06-02
  3. *//**
  4. * @file lpc_gpdma.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for GPDMA firmware library on LPC
  7. * @version 1.0
  8. * @date 02. June. 2011
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2011, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @defgroup GPDMA GPDMA (General Purpose Direct Memory Access)
  34. * @ingroup LPC_CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef __LPC_GPDMA_H_
  38. #define __LPC_GPDMA_H_
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC407x_8x_177x_8x.h"
  41. #include "lpc_types.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /* Public Macros -------------------------------------------------------------- */
  47. /** @defgroup GPDMA_Public_Macros GPDMA Public Macros
  48. * @{
  49. */
  50. /** DMA Connection number definitions */
  51. #define GPDMA_CONN_MCI ((1UL)) /** SD card */
  52. #define GPDMA_CONN_SSP0_Tx ((2UL)) /**< SSP0 Tx */
  53. #define GPDMA_CONN_SSP0_Rx ((3UL)) /**< SSP0 Rx */
  54. #define GPDMA_CONN_SSP1_Tx ((4UL)) /**< SSP1 Tx */
  55. #define GPDMA_CONN_SSP1_Rx ((5UL)) /**< SSP1 Rx */
  56. #define GPDMA_CONN_SSP2_Tx ((6UL)) /**< SSP2 Tx */
  57. #define GPDMA_CONN_SSP2_Rx ((7UL)) /**< SSP2 Rx */
  58. #define GPDMA_CONN_ADC ((8UL)) /**< ADC */
  59. #define GPDMA_CONN_DAC ((9UL)) /**< DAC */
  60. #define GPDMA_CONN_UART0_Tx ((10UL)) /**< UART0 Tx */
  61. #define GPDMA_CONN_UART0_Rx ((11UL)) /**< UART0 Rx */
  62. #define GPDMA_CONN_UART1_Tx ((12UL)) /**< UART1 Tx */
  63. #define GPDMA_CONN_UART1_Rx ((13UL)) /**< UART1 Rx */
  64. #define GPDMA_CONN_UART2_Tx ((14UL)) /**< UART2 Tx */
  65. #define GPDMA_CONN_UART2_Rx ((15UL)) /**< UART2 Rx */
  66. #define GPDMA_CONN_MAT0_0 ((16UL)) /**< MAT0.0 */
  67. #define GPDMA_CONN_MAT0_1 ((17UL)) /**< MAT0.1 */
  68. #define GPDMA_CONN_MAT1_0 ((18UL)) /**< MAT1.0 */
  69. #define GPDMA_CONN_MAT1_1 ((19UL)) /**< MAT1.1 */
  70. #define GPDMA_CONN_MAT2_0 ((20UL)) /**< MAT2.0 */
  71. #define GPDMA_CONN_MAT2_1 ((21UL)) /**< MAT2.1 */
  72. #define GPDMA_CONN_I2S_Channel_0 ((22UL)) /**< I2S channel 0 */
  73. #define GPDMA_CONN_I2S_Channel_1 ((23UL)) /**< I2S channel 1 */
  74. #define GPDMA_CONN_UART3_Tx ((26UL)) /**< UART3 Tx */
  75. #define GPDMA_CONN_UART3_Rx ((27UL)) /**< UART3 Rx */
  76. #define GPDMA_CONN_UART4_Tx ((28UL)) /**< UART3 Tx */
  77. #define GPDMA_CONN_UART4_Rx ((29UL)) /**< UART3 Rx */
  78. #define GPDMA_CONN_MAT3_0 ((30UL)) /**< MAT3.0 */
  79. #define GPDMA_CONN_MAT3_1 ((31UL)) /**< MAT3.1 */
  80. /** GPDMA Transfer type definitions: Memory to memory - DMA control */
  81. #define GPDMA_TRANSFERTYPE_M2M ((0UL))
  82. /** GPDMA Transfer type definitions: Memory to peripheral - DMA control */
  83. #define GPDMA_TRANSFERTYPE_M2P ((1UL))
  84. /** GPDMA Transfer type definitions: Peripheral to memory - DMA control */
  85. #define GPDMA_TRANSFERTYPE_P2M ((2UL))
  86. /** Source peripheral to destination peripheral - DMA control */
  87. #define GPDMA_TRANSFERTYPE_P2P ((3UL))
  88. /** Memory to peripheral - Destination peripheral control */
  89. #define GPDMA_TRANSFERTYPE_M2P_DEST_CTRL ((5UL))
  90. /** Peripheral to memory - Source peripheral control */
  91. #define GPDMA_TRANSFERTYPE_P2M_SRC_CTRL ((6UL))
  92. /** Burst size in Source and Destination definitions */
  93. #define GPDMA_BSIZE_1 ((0UL)) /**< Burst size = 1 */
  94. #define GPDMA_BSIZE_4 ((1UL)) /**< Burst size = 4 */
  95. #define GPDMA_BSIZE_8 ((2UL)) /**< Burst size = 8 */
  96. #define GPDMA_BSIZE_16 ((3UL)) /**< Burst size = 16 */
  97. #define GPDMA_BSIZE_32 ((4UL)) /**< Burst size = 32 */
  98. #define GPDMA_BSIZE_64 ((5UL)) /**< Burst size = 64 */
  99. #define GPDMA_BSIZE_128 ((6UL)) /**< Burst size = 128 */
  100. #define GPDMA_BSIZE_256 ((7UL)) /**< Burst size = 256 */
  101. /** Width in Source transfer width and Destination transfer width definitions */
  102. #define GPDMA_WIDTH_BYTE ((0UL)) /**< Width = 1 byte */
  103. #define GPDMA_WIDTH_HALFWORD ((1UL)) /**< Width = 2 bytes */
  104. #define GPDMA_WIDTH_WORD ((2UL)) /**< Width = 4 bytes */
  105. /** DMA Request Select Mode definitions */
  106. #define GPDMA_REQSEL_UART ((0UL)) /**< UART TX/RX is selected */
  107. #define GPDMA_REQSEL_TIMER ((1UL)) /**< Timer match is selected */
  108. /**
  109. * @}
  110. */
  111. /* Private Macros ------------------------------------------------------------- */
  112. /** @defgroup GPDMA_Private_Macros GPDMA Private Macros
  113. * @{
  114. */
  115. /* --------------------- BIT DEFINITIONS -------------------------------------- */
  116. /*********************************************************************//**
  117. * Macro defines for DMA Interrupt Status register
  118. **********************************************************************/
  119. #define GPDMA_DMACIntStat_Ch(n) (((1UL<<n)&0xFF))
  120. #define GPDMA_DMACIntStat_BITMASK ((0xFF))
  121. /*********************************************************************//**
  122. * Macro defines for DMA Interrupt Terminal Count Request Status register
  123. **********************************************************************/
  124. #define GPDMA_DMACIntTCStat_Ch(n) (((1UL<<n)&0xFF))
  125. #define GPDMA_DMACIntTCStat_BITMASK ((0xFF))
  126. /*********************************************************************//**
  127. * Macro defines for DMA Interrupt Terminal Count Request Clear register
  128. **********************************************************************/
  129. #define GPDMA_DMACIntTCClear_Ch(n) (((1UL<<n)&0xFF))
  130. #define GPDMA_DMACIntTCClear_BITMASK ((0xFF))
  131. /*********************************************************************//**
  132. * Macro defines for DMA Interrupt Error Status register
  133. **********************************************************************/
  134. #define GPDMA_DMACIntErrStat_Ch(n) (((1UL<<n)&0xFF))
  135. #define GPDMA_DMACIntErrStat_BITMASK ((0xFF))
  136. /*********************************************************************//**
  137. * Macro defines for DMA Interrupt Error Clear register
  138. **********************************************************************/
  139. #define GPDMA_DMACIntErrClr_Ch(n) (((1UL<<n)&0xFF))
  140. #define GPDMA_DMACIntErrClr_BITMASK ((0xFF))
  141. /*********************************************************************//**
  142. * Macro defines for DMA Raw Interrupt Terminal Count Status register
  143. **********************************************************************/
  144. #define GPDMA_DMACRawIntTCStat_Ch(n) (((1UL<<n)&0xFF))
  145. #define GPDMA_DMACRawIntTCStat_BITMASK ((0xFF))
  146. /*********************************************************************//**
  147. * Macro defines for DMA Raw Error Interrupt Status register
  148. **********************************************************************/
  149. #define GPDMA_DMACRawIntErrStat_Ch(n) (((1UL<<n)&0xFF))
  150. #define GPDMA_DMACRawIntErrStat_BITMASK ((0xFF))
  151. /*********************************************************************//**
  152. * Macro defines for DMA Enabled Channel register
  153. **********************************************************************/
  154. #define GPDMA_DMACEnbldChns_Ch(n) (((1UL<<n)&0xFF))
  155. #define GPDMA_DMACEnbldChns_BITMASK ((0xFF))
  156. /*********************************************************************//**
  157. * Macro defines for DMA Software Burst Request register
  158. **********************************************************************/
  159. #define GPDMA_DMACSoftBReq_Src(n) (((1UL<<n)&0xFFFF))
  160. #define GPDMA_DMACSoftBReq_BITMASK ((0xFFFF))
  161. /*********************************************************************//**
  162. * Macro defines for DMA Software Single Request register
  163. **********************************************************************/
  164. #define GPDMA_DMACSoftSReq_Src(n) (((1UL<<n)&0xFFFF))
  165. #define GPDMA_DMACSoftSReq_BITMASK ((0xFFFF))
  166. /*********************************************************************//**
  167. * Macro defines for DMA Software Last Burst Request register
  168. **********************************************************************/
  169. #define GPDMA_DMACSoftLBReq_Src(n) (((1UL<<n)&0xFFFF))
  170. #define GPDMA_DMACSoftLBReq_BITMASK ((0xFFFF))
  171. /*********************************************************************//**
  172. * Macro defines for DMA Software Last Single Request register
  173. **********************************************************************/
  174. #define GPDMA_DMACSoftLSReq_Src(n) (((1UL<<n)&0xFFFF))
  175. #define GPDMA_DMACSoftLSReq_BITMASK ((0xFFFF))
  176. /*********************************************************************//**
  177. * Macro defines for DMA Configuration register
  178. **********************************************************************/
  179. #define GPDMA_DMACConfig_E ((0x01)) /**< DMA Controller enable*/
  180. #define GPDMA_DMACConfig_M ((0x02)) /**< AHB Master endianness configuration*/
  181. #define GPDMA_DMACConfig_BITMASK ((0x03))
  182. /*********************************************************************//**
  183. * Macro defines for DMA Synchronization register
  184. **********************************************************************/
  185. #define GPDMA_DMACSync_Src(n) (((1UL<<n)&0xFFFF))
  186. #define GPDMA_DMACSync_BITMASK ((0xFFFF))
  187. /*********************************************************************//**
  188. * Macro defines for DMA Request Select register
  189. **********************************************************************/
  190. #define GPDMA_DMAReqSel_Input(n) (((1UL<<(n-8))&0xFF))
  191. #define GPDMA_DMAReqSel_BITMASK ((0xFF))
  192. /*********************************************************************//**
  193. * Macro defines for DMA Channel Linked List Item registers
  194. **********************************************************************/
  195. /** DMA Channel Linked List Item registers bit mask*/
  196. #define GPDMA_DMACCxLLI_BITMASK ((0xFFFFFFFC))
  197. /*********************************************************************//**
  198. * Macro defines for DMA channel control registers
  199. **********************************************************************/
  200. /** Transfer size*/
  201. #define GPDMA_DMACCxControl_TransferSize(n) (((n&0xFFF)<<0))
  202. /** Source burst size*/
  203. #define GPDMA_DMACCxControl_SBSize(n) (((n&0x07)<<12))
  204. /** Destination burst size*/
  205. #define GPDMA_DMACCxControl_DBSize(n) (((n&0x07)<<15))
  206. /** Source transfer width*/
  207. #define GPDMA_DMACCxControl_SWidth(n) (((n&0x07)<<18))
  208. /** Destination transfer width*/
  209. #define GPDMA_DMACCxControl_DWidth(n) (((n&0x07)<<21))
  210. /** Source increment*/
  211. #define GPDMA_DMACCxControl_SI ((1UL<<26))
  212. /** Destination increment*/
  213. #define GPDMA_DMACCxControl_DI ((1UL<<27))
  214. /** Indicates that the access is in user mode or privileged mode*/
  215. #define GPDMA_DMACCxControl_Prot1 ((1UL<<28))
  216. /** Indicates that the access is bufferable or not bufferable*/
  217. #define GPDMA_DMACCxControl_Prot2 ((1UL<<29))
  218. /** Indicates that the access is cacheable or not cacheable*/
  219. #define GPDMA_DMACCxControl_Prot3 ((1UL<<30))
  220. /** Terminal count interrupt enable bit */
  221. #define GPDMA_DMACCxControl_I ((1UL<<31))
  222. /** DMA channel control registers bit mask */
  223. #define GPDMA_DMACCxControl_BITMASK ((0xFCFFFFFF))
  224. /*********************************************************************//**
  225. * Macro defines for DMA Channel Configuration registers
  226. **********************************************************************/
  227. /** DMA control enable*/
  228. #define GPDMA_DMACCxConfig_E ((1UL<<0))
  229. /** Source peripheral*/
  230. #define GPDMA_DMACCxConfig_SrcPeripheral(n) (((n&0x1F)<<1))
  231. /** Destination peripheral*/
  232. #define GPDMA_DMACCxConfig_DestPeripheral(n) (((n&0x1F)<<6))
  233. /** This value indicates the type of transfer*/
  234. #define GPDMA_DMACCxConfig_TransferType(n) (((n&0x7)<<11))
  235. /** Interrupt error mask*/
  236. #define GPDMA_DMACCxConfig_IE ((1UL<<14))
  237. /** Terminal count interrupt mask*/
  238. #define GPDMA_DMACCxConfig_ITC ((1UL<<15))
  239. /** Lock*/
  240. #define GPDMA_DMACCxConfig_L ((1UL<<16))
  241. /** Active*/
  242. #define GPDMA_DMACCxConfig_A ((1UL<<17))
  243. /** Halt*/
  244. #define GPDMA_DMACCxConfig_H ((1UL<<18))
  245. /** DMA Channel Configuration registers bit mask */
  246. #define GPDMA_DMACCxConfig_BITMASK ((0x7FFFF))
  247. /**
  248. * @}
  249. */
  250. /* Public Types --------------------------------------------------------------- */
  251. /** @defgroup GPDMA_Public_Types GPDMA Public Types
  252. * @{
  253. */
  254. /**
  255. * @brief GPDMA Status enumeration
  256. */
  257. typedef enum {
  258. GPDMA_STAT_INT, /**< GPDMA Interrupt Status */
  259. GPDMA_STAT_INTTC, /**< GPDMA Interrupt Terminal Count Request Status */
  260. GPDMA_STAT_INTERR, /**< GPDMA Interrupt Error Status */
  261. GPDMA_STAT_RAWINTTC, /**< GPDMA Raw Interrupt Terminal Count Status */
  262. GPDMA_STAT_RAWINTERR, /**< GPDMA Raw Error Interrupt Status */
  263. GPDMA_STAT_ENABLED_CH /**< GPDMA Enabled Channel Status */
  264. } GPDMA_Status_Type;
  265. /**
  266. * @brief GPDMA Interrupt clear status enumeration
  267. */
  268. typedef enum{
  269. GPDMA_STATCLR_INTTC, /**< GPDMA Interrupt Terminal Count Request Clear */
  270. GPDMA_STATCLR_INTERR /**< GPDMA Interrupt Error Clear */
  271. }GPDMA_StateClear_Type;
  272. /**
  273. * @brief GPDMA Channel configuration structure type definition
  274. */
  275. typedef struct {
  276. uint32_t ChannelNum; /**< DMA channel number, should be in
  277. range from 0 to 7.
  278. Note: DMA channel 0 has the highest priority
  279. and DMA channel 7 the lowest priority.
  280. */
  281. uint32_t TransferSize; /**< Length/Size of transfer */
  282. uint32_t TransferWidth; /**< Transfer width - used for TransferType is GPDMA_TRANSFERTYPE_M2M only */
  283. uint32_t SrcMemAddr; /**< Physical Source Address, used in case TransferType is chosen as
  284. GPDMA_TRANSFERTYPE_M2M or GPDMA_TRANSFERTYPE_M2P */
  285. uint32_t DstMemAddr; /**< Physical Destination Address, used in case TransferType is chosen as
  286. GPDMA_TRANSFERTYPE_M2M or GPDMA_TRANSFERTYPE_P2M */
  287. uint32_t TransferType; /**< Transfer Type, should be one of the following:
  288. - GPDMA_TRANSFERTYPE_M2M: Memory to memory - DMA control
  289. - GPDMA_TRANSFERTYPE_M2P: Memory to peripheral - DMA control
  290. - GPDMA_TRANSFERTYPE_P2M: Peripheral to memory - DMA control
  291. - GPDMA_TRANSFERTYPE_P2P: Source peripheral to destination peripheral - DMA control
  292. */
  293. uint32_t SrcConn; /**< Peripheral Source Connection type, used in case TransferType is chosen as
  294. GPDMA_TRANSFERTYPE_P2M or GPDMA_TRANSFERTYPE_P2P, should be one of
  295. following:
  296. - GPDMA_CONN_SSP0_Tx: SSP0, Tx
  297. - GPDMA_CONN_SSP0_Rx: SSP0, Rx
  298. - GPDMA_CONN_SSP1_Tx: SSP1, Tx
  299. - GPDMA_CONN_SSP1_Rx: SSP1, Rx
  300. - GPDMA_CONN_ADC: ADC
  301. - GPDMA_CONN_I2S_Channel_0: I2S Channel 0
  302. - GPDMA_CONN_I2S_Channel_1: I2S Channel 1
  303. - GPDMA_CONN_DAC: DAC
  304. - GPDMA_CONN_UART0_Tx_MAT0_0: UART0 Tx / MAT0.0
  305. - GPDMA_CONN_UART0_Rx_MAT0_1: UART0 Rx / MAT0.1
  306. - GPDMA_CONN_UART1_Tx_MAT1_0: UART1 Tx / MAT1.0
  307. - GPDMA_CONN_UART1_Rx_MAT1_1: UART1 Rx / MAT1.1
  308. - GPDMA_CONN_UART2_Tx_MAT2_0: UART2 Tx / MAT2.0
  309. - GPDMA_CONN_UART2_Rx_MAT2_1: UART2 Rx / MAT2.1
  310. - GPDMA_CONN_UART3_Tx_MAT3_0: UART3 Tx / MAT3.0
  311. - GPDMA_CONN_UART3_Rx_MAT3_1: UART3 Rx / MAT3.1
  312. */
  313. uint32_t DstConn; /**< Peripheral Destination Connection type, used in case TransferType is chosen as
  314. GPDMA_TRANSFERTYPE_M2P or GPDMA_TRANSFERTYPE_P2P, should be one of
  315. following:
  316. - GPDMA_CONN_SSP0_Tx: SSP0, Tx
  317. - GPDMA_CONN_SSP0_Rx: SSP0, Rx
  318. - GPDMA_CONN_SSP1_Tx: SSP1, Tx
  319. - GPDMA_CONN_SSP1_Rx: SSP1, Rx
  320. - GPDMA_CONN_ADC: ADC
  321. - GPDMA_CONN_I2S_Channel_0: I2S Channel 0
  322. - GPDMA_CONN_I2S_Channel_1: I2S Channel 1
  323. - GPDMA_CONN_DAC: DAC
  324. - GPDMA_CONN_UART0_Tx_MAT0_0: UART0 Tx / MAT0.0
  325. - GPDMA_CONN_UART0_Rx_MAT0_1: UART0 Rx / MAT0.1
  326. - GPDMA_CONN_UART1_Tx_MAT1_0: UART1 Tx / MAT1.0
  327. - GPDMA_CONN_UART1_Rx_MAT1_1: UART1 Rx / MAT1.1
  328. - GPDMA_CONN_UART2_Tx_MAT2_0: UART2 Tx / MAT2.0
  329. - GPDMA_CONN_UART2_Rx_MAT2_1: UART2 Rx / MAT2.1
  330. - GPDMA_CONN_UART3_Tx_MAT3_0: UART3 Tx / MAT3.0
  331. - GPDMA_CONN_UART3_Rx_MAT3_1: UART3 Rx / MAT3.1
  332. */
  333. uint32_t DMALLI; /**< Linker List Item structure data address
  334. if there's no Linker List, set as '0'
  335. */
  336. } GPDMA_Channel_CFG_Type;
  337. /**
  338. * @brief GPDMA Linker List Item structure type definition
  339. */
  340. typedef struct {
  341. uint32_t SrcAddr; /**< Source Address */
  342. uint32_t DstAddr; /**< Destination address */
  343. uint32_t NextLLI; /**< Next LLI address, otherwise set to '0' */
  344. uint32_t Control; /**< GPDMA Control of this LLI */
  345. } GPDMA_LLI_Type;
  346. /**
  347. * @}
  348. */
  349. /* Public Functions ----------------------------------------------------------- */
  350. /** @defgroup GPDMA_Public_Functions GPDMA Public Functions
  351. * @{
  352. */
  353. void GPDMA_Init(void);
  354. Status GPDMA_Setup(GPDMA_Channel_CFG_Type *GPDMAChannelConfig);
  355. IntStatus GPDMA_IntGetStatus(GPDMA_Status_Type type, uint8_t channel);
  356. void GPDMA_ClearIntPending(GPDMA_StateClear_Type type, uint8_t channel);
  357. void GPDMA_ChannelCmd(uint8_t channelNum, FunctionalState NewState);
  358. //void GPDMA_IntHandler(void);
  359. /**
  360. * @}
  361. */
  362. #ifdef __cplusplus
  363. }
  364. #endif
  365. #endif /* __LPC_GPDMA_H_ */
  366. /**
  367. * @}
  368. */
  369. /* --------------------------------- End Of File ------------------------------ */