2 * @brief LPC18xx/43xx DMA driver
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __GPDMA_18XX_43XX_H_
\r
33 #define __GPDMA_18XX_43XX_H_
\r
39 /** @defgroup GPDMA_18XX_43XX CHIP: LPC18xx/43xx General Purpose DMA driver
\r
40 * @ingroup CHIP_18XX_43XX_Drivers
\r
45 * @brief Number of channels on GPDMA
\r
47 #define GPDMA_NUMBER_CHANNELS 8
\r
50 * @brief GPDMA request connections
\r
52 #define GPDMA_CONN_MEMORY ((0UL)) /**< MEMORY */
\r
53 #define GPDMA_CONN_MAT0_0 ((1UL)) /**< MAT0.0 */
\r
54 #define GPDMA_CONN_UART0_Tx ((2UL)) /**< UART0 Tx */
\r
55 #define GPDMA_CONN_MAT0_1 ((3UL)) /**< MAT0.1 */
\r
56 #define GPDMA_CONN_UART0_Rx ((4UL)) /**< UART0 Rx */
\r
57 #define GPDMA_CONN_MAT1_0 ((5UL)) /**< MAT1.0 */
\r
58 #define GPDMA_CONN_UART1_Tx ((6UL)) /**< UART1 Tx */
\r
59 #define GPDMA_CONN_MAT1_1 ((7UL)) /**< MAT1.1 */
\r
60 #define GPDMA_CONN_UART1_Rx ((8UL)) /**< UART1 Rx */
\r
61 #define GPDMA_CONN_MAT2_0 ((9UL)) /**< MAT2.0 */
\r
62 #define GPDMA_CONN_UART2_Tx ((10UL)) /**< UART2 Tx */
\r
63 #define GPDMA_CONN_MAT2_1 ((11UL)) /**< MAT2.1 */
\r
64 #define GPDMA_CONN_UART2_Rx ((12UL)) /**< UART2 Rx */
\r
65 #define GPDMA_CONN_MAT3_0 ((13UL)) /**< MAT3.0 */
\r
66 #define GPDMA_CONN_UART3_Tx ((14UL)) /**< UART3 Tx */
\r
67 #define GPDMA_CONN_SCT_0 ((15UL)) /**< SCT timer channel 0*/
\r
68 #define GPDMA_CONN_MAT3_1 ((16UL)) /**< MAT3.1 */
\r
69 #define GPDMA_CONN_UART3_Rx ((17UL)) /**< UART3 Rx */
\r
70 #define GPDMA_CONN_SCT_1 ((18UL)) /**< SCT timer channel 1*/
\r
71 #define GPDMA_CONN_SSP0_Rx ((19UL)) /**< SSP0 Rx */
\r
72 #define GPDMA_CONN_I2S_Tx_Channel_0 ((20UL)) /**< I2S channel 0 */
\r
73 #define GPDMA_CONN_SSP0_Tx ((21UL)) /**< SSP0 Tx */
\r
74 #define GPDMA_CONN_I2S_Rx_Channel_1 ((22UL)) /**< I2S channel 1 */
\r
75 #define GPDMA_CONN_SSP1_Rx ((23UL)) /**< SSP1 Rx */
\r
76 #define GPDMA_CONN_SSP1_Tx ((24UL)) /**< SSP1 Tx */
\r
77 #define GPDMA_CONN_ADC_0 ((25UL)) /**< ADC 0 */
\r
78 #define GPDMA_CONN_ADC_1 ((26UL)) /**< ADC 1 */
\r
79 #define GPDMA_CONN_DAC ((27UL)) /**< DAC */
\r
80 #define GPDMA_CONN_I2S_Tx_Channel_1 ((28UL)) /**< I2S channel 0 */
\r
81 #define GPDMA_CONN_I2S_Rx_Channel_0 ((29UL)) /**< I2S channel 0 */
\r
84 * @brief GPDMA Burst size in Source and Destination definitions
\r
86 #define GPDMA_BSIZE_1 ((0UL)) /*!< Burst size = 1 */
\r
87 #define GPDMA_BSIZE_4 ((1UL)) /*!< Burst size = 4 */
\r
88 #define GPDMA_BSIZE_8 ((2UL)) /*!< Burst size = 8 */
\r
89 #define GPDMA_BSIZE_16 ((3UL)) /*!< Burst size = 16 */
\r
90 #define GPDMA_BSIZE_32 ((4UL)) /*!< Burst size = 32 */
\r
91 #define GPDMA_BSIZE_64 ((5UL)) /*!< Burst size = 64 */
\r
92 #define GPDMA_BSIZE_128 ((6UL)) /*!< Burst size = 128 */
\r
93 #define GPDMA_BSIZE_256 ((7UL)) /*!< Burst size = 256 */
\r
96 * @brief Width in Source transfer width and Destination transfer width definitions
\r
98 #define GPDMA_WIDTH_BYTE ((0UL)) /*!< Width = 1 byte */
\r
99 #define GPDMA_WIDTH_HALFWORD ((1UL)) /*!< Width = 2 bytes */
\r
100 #define GPDMA_WIDTH_WORD ((2UL)) /*!< Width = 4 bytes */
\r
103 * @brief Flow control definitions
\r
105 #define DMA_CONTROLLER 0 /*!< Flow control is DMA controller*/
\r
106 #define SRC_PER_CONTROLLER 1 /*!< Flow control is Source peripheral controller*/
\r
107 #define DST_PER_CONTROLLER 2 /*!< Flow control is Destination peripheral controller*/
\r
110 * @brief DMA channel handle structure
\r
113 FunctionalState ChannelStatus; /*!< DMA channel status */
\r
114 } DMA_ChannelHandle_t;
\r
117 * @brief Transfer Descriptor structure typedef
\r
119 typedef struct DMA_TransferDescriptor {
\r
120 uint32_t src; /*!< Source address */
\r
121 uint32_t dst; /*!< Destination address */
\r
122 uint32_t lli; /*!< Pointer to next descriptor structure */
\r
123 uint32_t ctrl; /*!< Control word that has transfer size, type etc. */
\r
124 } DMA_TransferDescriptor_t;
\r
127 * @brief Read the status from different registers according to the type
\r
128 * @param pGPDMA : The base of GPDMA on the chip
\r
129 * @param type : Status mode, should be:
\r
130 * - GPDMA_STAT_INT : GPDMA Interrupt Status
\r
131 * - GPDMA_STAT_INTTC : GPDMA Interrupt Terminal Count Request Status
\r
132 * - GPDMA_STAT_INTERR : GPDMA Interrupt Error Status
\r
133 * - GPDMA_STAT_RAWINTTC : GPDMA Raw Interrupt Terminal Count Status
\r
134 * - GPDMA_STAT_RAWINTERR : GPDMA Raw Error Interrupt Status
\r
135 * - GPDMA_STAT_ENABLED_CH : GPDMA Enabled Channel Status
\r
136 * @param channel : The GPDMA channel : 0 - 7
\r
137 * @return SET is interrupt is pending or RESET if not pending
\r
139 STATIC INLINE IntStatus Chip_GPDMA_IntGetStatus(LPC_GPDMA_T *pGPDMA, IP_GPDMA_STATUS_T type, uint8_t channel)
\r
141 return IP_GPDMA_IntGetStatus(pGPDMA, type, channel);
\r
145 * @brief Clear the Interrupt Flag from different registers according to the type
\r
146 * @param pGPDMA : The base of GPDMA on the chip
\r
147 * @param type : Flag mode, should be:
\r
148 * - GPDMA_STATCLR_INTTC : GPDMA Interrupt Terminal Count Request
\r
149 * - GPDMA_STATCLR_INTERR : GPDMA Interrupt Error
\r
150 * @param channel : The GPDMA channel : 0 - 7
\r
153 STATIC INLINE void Chip_GPDMA_ClearIntPending(LPC_GPDMA_T *pGPDMA, IP_GPDMA_STATECLEAR_T type, uint8_t channel)
\r
155 IP_GPDMA_ClearIntPending(pGPDMA, type, channel);
\r
159 * @brief Enable or Disable the GPDMA Channel
\r
160 * @param pGPDMA : The base of GPDMA on the chip
\r
161 * @param channelNum : The GPDMA channel : 0 - 7
\r
162 * @param NewState : ENABLE to enable GPDMA or DISABLE to disable GPDMA
\r
165 STATIC INLINE void Chip_GPDMA_ChannelCmd(LPC_GPDMA_T *pGPDMA, uint8_t channelNum, FunctionalState NewState)
\r
167 IP_GPDMA_ChannelCmd(pGPDMA, channelNum, NewState);
\r
171 * @brief Initialize the GPDMA
\r
172 * @param pGPDMA : The base of GPDMA on the chip
\r
175 void Chip_GPDMA_Init(LPC_GPDMA_T *pGPDMA);
\r
178 * @brief Shutdown the GPDMA
\r
179 * @param pGPDMA : The base of GPDMA on the chip
\r
182 void Chip_GPDMA_DeInit(LPC_GPDMA_T *pGPDMA);
\r
185 * @brief Stop a stream DMA transfer
\r
186 * @param pGPDMA : The base of GPDMA on the chip
\r
187 * @param ChannelNum : Channel Number to be closed
\r
190 void Chip_DMA_Stop(LPC_GPDMA_T *pGPDMA, uint8_t ChannelNum);
\r
193 * @brief The GPDMA stream interrupt status checking
\r
194 * @param pGPDMA : The base of GPDMA on the chip
\r
195 * @param ChannelNum : Channel Number to be checked on interruption
\r
197 * - SUCCESS : DMA transfer success
\r
198 * - ERROR : DMA transfer failed
\r
200 Status Chip_DMA_Interrupt(LPC_GPDMA_T *pGPDMA, uint8_t ChannelNum);
\r
203 * @brief Get a free GPDMA channel for one DMA connection
\r
204 * @param pGPDMA : The base of GPDMA on the chip
\r
205 * @param PeripheralConnection_ID : Some chip fix each peripheral DMA connection on a specified channel ( have not used in 18xx/43xx )
\r
206 * @return The channel number which is selected
\r
208 uint8_t Chip_DMA_GetFreeChannel(LPC_GPDMA_T *pGPDMA, uint32_t PeripheralConnection_ID);
\r
211 * @brief Do a DMA transfer M2M, M2P,P2M or P2P
\r
212 * @param pGPDMA : The base of GPDMA on the chip
\r
213 * @param ChannelNum : Channel used for transfer
\r
214 * @param src : Address of Memory or PeripheralConnection_ID which is the source
\r
215 * @param dst : Address of Memory or PeripheralConnection_ID which is the destination
\r
216 * @param TransferType: Select the transfer controller and the type of transfer. Should be:
\r
217 * - GPDMA_TRANSFERTYPE_M2M_CONTROLLER_DMA
\r
218 * - GPDMA_TRANSFERTYPE_M2P_CONTROLLER_DMA
\r
219 * - GPDMA_TRANSFERTYPE_P2M_CONTROLLER_DMA
\r
220 * - GPDMA_TRANSFERTYPE_P2P_CONTROLLER_DMA
\r
221 * - GPDMA_TRANSFERTYPE_P2P_CONTROLLER_DestPERIPHERAL
\r
222 * - GPDMA_TRANSFERTYPE_M2P_CONTROLLER_PERIPHERAL
\r
223 * - GPDMA_TRANSFERTYPE_P2M_CONTROLLER_PERIPHERAL
\r
224 * - GPDMA_TRANSFERTYPE_P2P_CONTROLLER_SrcPERIPHERAL
\r
225 * @param Size : The number of DMA transfers
\r
226 * @return ERROR on error, SUCCESS on success
\r
228 Status Chip_DMA_Transfer(LPC_GPDMA_T *pGPDMA,
\r
229 uint8_t ChannelNum,
\r
232 IP_GPDMA_FLOW_CONTROL_T TransferType,
\r
236 * @brief Do a DMA transfer using linked list of descriptors
\r
237 * @param pGPDMA : The base of GPDMA on the chip
\r
238 * @param ChannelNum : Channel used for transfer *must be obtained using Chip_DMA_GetFreeChannel()*
\r
239 * @param DMADescriptor : First node in the linked list of descriptors
\r
240 * @param TransferType : Select the transfer controller and the type of transfer. (See, #IP_GPDMA_FLOW_CONTROL_T)
\r
241 * @return ERROR on error, SUCCESS on success
\r
243 Status Chip_DMA_SGTransfer(LPC_GPDMA_T *pGPDMA,
\r
244 uint8_t ChannelNum,
\r
245 const DMA_TransferDescriptor_t *DMADescriptor,
\r
246 IP_GPDMA_FLOW_CONTROL_T TransferType);
\r
249 * @brief Prepare a single DMA descriptor
\r
250 * @param pGPDMA : The base of GPDMA on the chip
\r
251 * @param DMADescriptor : DMA Descriptor to be initialized
\r
252 * @param src : Address of Memory or one of @link #GPDMA_CONN_MEMORY
\r
253 * PeripheralConnection_ID @endlink, which is the source
\r
254 * @param dst : Address of Memory or one of @link #GPDMA_CONN_MEMORY
\r
255 * PeripheralConnection_ID @endlink, which is the destination
\r
256 * @param Size : The number of DMA transfers
\r
257 * @param TransferType : Select the transfer controller and the type of transfer. (See, #IP_GPDMA_FLOW_CONTROL_T)
\r
258 * @param NextDescriptor : Pointer to next descriptor (0 if no more descriptors available)
\r
259 * @return ERROR on error, SUCCESS on success
\r
261 Status Chip_DMA_PrepareDescriptor(LPC_GPDMA_T *pGPDMA,
\r
262 DMA_TransferDescriptor_t *DMADescriptor,
\r
266 IP_GPDMA_FLOW_CONTROL_T TransferType,
\r
267 const DMA_TransferDescriptor_t *NextDescriptor);
\r
270 * @brief Initialize channel configuration strucutre
\r
271 * @param pGPDMA : The base of GPDMA on the chip
\r
272 * @param GPDMACfg : Pointer to configuration structure to be initialized
\r
273 * @param ChannelNum : Channel used for transfer *must be obtained using Chip_DMA_GetFreeChannel()*
\r
274 * @param src : Address of Memory or one of @link #GPDMA_CONN_MEMORY
\r
275 * PeripheralConnection_ID @endlink, which is the source
\r
276 * @param dst : Address of Memory or one of @link #GPDMA_CONN_MEMORY
\r
277 * PeripheralConnection_ID @endlink, which is the destination
\r
278 * @param Size : The number of DMA transfers
\r
279 * @param TransferType : Select the transfer controller and the type of transfer. (See, #IP_GPDMA_FLOW_CONTROL_T)
\r
280 * @return ERROR on error, SUCCESS on success
\r
282 int Chip_DMA_InitChannelCfg(LPC_GPDMA_T *pGPDMA,
\r
283 GPDMA_Channel_CFG_T *GPDMACfg,
\r
284 uint8_t ChannelNum,
\r
288 IP_GPDMA_FLOW_CONTROL_T TransferType);
\r
298 #endif /* __GPDMA_18XX_43XX_H_ */
\r