1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  *   of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  *   list of conditions and the following disclaimer in the documentation and/or
13  *   other materials provided with the distribution.
14  *
15  * o Neither the name of the copyright holder nor the names of its
16  *   contributors may be used to endorse or promote products derived from this
17  *   software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _FSL_DMA_H_
32 #define _FSL_DMA_H_
33 
34 #include "fsl_common.h"
35 
36 /*!
37  * @addtogroup dma
38  * @{
39  */
40 
41 
42 /*******************************************************************************
43  * Definitions
44  ******************************************************************************/
45 
46 /*! @name Driver version */
47 /*@{*/
48 /*! @brief DMA driver version 2.0.1. */
49 #define FSL_DMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
50 /*@}*/
51 
52 /*! @brief status flag for the DMA driver. */
53 enum _dma_channel_status_flags
54 {
55     kDMA_TransactionsBCRFlag = DMA_DSR_BCR_BCR_MASK,       /*!< Contains the number of bytes yet to be
56                                                                 transferred for a given block */
57     kDMA_TransactionsDoneFlag = DMA_DSR_BCR_DONE_MASK,     /*!< Transactions Done */
58     kDMA_TransactionsBusyFlag = DMA_DSR_BCR_BSY_MASK,      /*!< Transactions Busy */
59     kDMA_TransactionsRequestFlag = DMA_DSR_BCR_REQ_MASK,   /*!< Transactions Request */
60     kDMA_BusErrorOnDestinationFlag = DMA_DSR_BCR_BED_MASK, /*!< Bus Error on Destination */
61     kDMA_BusErrorOnSourceFlag = DMA_DSR_BCR_BES_MASK,      /*!< Bus Error on Source */
62     kDMA_ConfigurationErrorFlag = DMA_DSR_BCR_CE_MASK,     /*!< Configuration Error */
63 };
64 
65 /*! @brief DMA transfer size type*/
66 typedef enum _dma_transfer_size
67 {
68     kDMA_Transfersize32bits = 0x0U, /*!< 32 bits are transferred for every read/write */
69     kDMA_Transfersize8bits,         /*!< 8 bits are transferred for every read/write */
70     kDMA_Transfersize16bits,        /*!< 16b its are transferred for every read/write */
71 } dma_transfer_size_t;
72 
73 /*! @brief Configuration type for the DMA modulo */
74 typedef enum _dma_modulo
75 {
76     kDMA_ModuloDisable = 0x0U, /*!< Buffer disabled */
77     kDMA_Modulo16Bytes,        /*!< Circular buffer size is 16 bytes. */
78     kDMA_Modulo32Bytes,        /*!< Circular buffer size is 32 bytes. */
79     kDMA_Modulo64Bytes,        /*!< Circular buffer size is 64 bytes. */
80     kDMA_Modulo128Bytes,       /*!< Circular buffer size is 128 bytes. */
81     kDMA_Modulo256Bytes,       /*!< Circular buffer size is 256 bytes. */
82     kDMA_Modulo512Bytes,       /*!< Circular buffer size is 512 bytes. */
83     kDMA_Modulo1KBytes,        /*!< Circular buffer size is 1 KB. */
84     kDMA_Modulo2KBytes,        /*!< Circular buffer size is 2 KB. */
85     kDMA_Modulo4KBytes,        /*!< Circular buffer size is 4 KB. */
86     kDMA_Modulo8KBytes,        /*!< Circular buffer size is 8 KB. */
87     kDMA_Modulo16KBytes,       /*!< Circular buffer size is 16 KB. */
88     kDMA_Modulo32KBytes,       /*!< Circular buffer size is 32 KB. */
89     kDMA_Modulo64KBytes,       /*!< Circular buffer size is 64 KB. */
90     kDMA_Modulo128KBytes,      /*!< Circular buffer size is 128 KB. */
91     kDMA_Modulo256KBytes,      /*!< Circular buffer size is 256 KB. */
92 } dma_modulo_t;
93 
94 /*! @brief DMA channel link type */
95 typedef enum _dma_channel_link_type
96 {
97     kDMA_ChannelLinkDisable = 0x0U,      /*!< No channel link. */
98     kDMA_ChannelLinkChannel1AndChannel2, /*!< Perform a link to channel LCH1 after each cycle-steal transfer.
99                                               followed by a link to LCH2 after the BCR decrements to 0. */
100     kDMA_ChannelLinkChannel1,            /*!< Perform a link to LCH1 after each cycle-steal transfer. */
101     kDMA_ChannelLinkChannel1AfterBCR0,   /*!< Perform a link to LCH1 after the BCR decrements. */
102 } dma_channel_link_type_t;
103 
104 /*! @brief DMA transfer type */
105 typedef enum _dma_transfer_type
106 {
107     kDMA_MemoryToMemory = 0x0U, /*!< Memory to Memory transfer. */
108     kDMA_PeripheralToMemory,    /*!< Peripheral to Memory transfer. */
109     kDMA_MemoryToPeripheral,    /*!< Memory to Peripheral transfer. */
110 } dma_transfer_type_t;
111 
112 /*! @brief DMA transfer options */
113 typedef enum _dma_transfer_options
114 {
115     kDMA_NoOptions = 0x0U, /*!< Transfer without options. */
116     kDMA_EnableInterrupt,  /*!< Enable interrupt while transfer complete. */
117 } dma_transfer_options_t;
118 
119 /*! @brief DMA transfer status */
120 enum _dma_transfer_status
121 {
122     kStatus_DMA_Busy = MAKE_STATUS(kStatusGroup_DMA, 0),
123 };
124 
125 /*! @brief DMA transfer configuration structure */
126 typedef struct _dma_transfer_config
127 {
128     uint32_t srcAddr;             /*!< DMA transfer source address. */
129     uint32_t destAddr;            /*!< DMA destination address.*/
130     bool enableSrcIncrement;      /*!< Source address increase after each transfer. */
131     dma_transfer_size_t srcSize;  /*!< Source transfer size unit. */
132     bool enableDestIncrement;     /*!< Destination address increase after each transfer. */
133     dma_transfer_size_t destSize; /*!< Destination transfer unit.*/
134     uint32_t transferSize;        /*!< The number of bytes to be transferred. */
135 } dma_transfer_config_t;
136 
137 /*! @brief DMA transfer configuration structure */
138 typedef struct _dma_channel_link_config
139 {
140     dma_channel_link_type_t linkType; /*!< Channel link type. */
141     uint32_t channel1;                /*!< The index of channel 1. */
142     uint32_t channel2;                /*!< The index of channel 2. */
143 } dma_channel_link_config_t;
144 
145 struct _dma_handle;
146 /*! @brief Callback function prototype for the DMA driver. */
147 typedef void (*dma_callback)(struct _dma_handle *handle, void *userData);
148 
149 /*! @brief DMA DMA handle structure */
150 typedef struct _dma_handle
151 {
152     DMA_Type *base;        /*!< DMA peripheral address. */
153     uint8_t channel;       /*!< DMA channel used. */
154     dma_callback callback; /*!< DMA callback function.*/
155     void *userData;        /*!< Callback parameter. */
156 } dma_handle_t;
157 
158 /*******************************************************************************
159  * API
160  ******************************************************************************/
161 #if defined(__cplusplus)
162 extern "C" {
163 #endif /* __cplusplus */
164 
165 /*!
166  * @name DMA Initialization and De-initialization
167  * @{
168  */
169 
170 /*!
171  * @brief Initializes the DMA peripheral.
172  *
173  * This function ungates the DMA clock.
174  *
175  * @param base DMA peripheral base address.
176  */
177 void DMA_Init(DMA_Type *base);
178 
179 /*!
180  * @brief Deinitializes the DMA peripheral.
181  *
182  * This function gates the DMA clock.
183  *
184  * @param base DMA peripheral base address.
185  */
186 void DMA_Deinit(DMA_Type *base);
187 
188 /* @} */
189 /*!
190  * @name DMA Channel Operation
191  * @{
192  */
193 
194 /*!
195  * @brief Resets the DMA channel.
196  *
197  * Sets all register values to reset values and enables
198  * the cycle steal and auto stop channel request features.
199  *
200  * @param base DMA peripheral base address.
201  * @param channel DMA channel number.
202  */
203 void DMA_ResetChannel(DMA_Type *base, uint32_t channel);
204 
205 /*!
206  * @brief Configures the DMA transfer attribute.
207  *
208  * This function configures the transfer attribute including the source address,
209  * destination address, transfer size, and so on.
210  * This example shows how to set up the the dma_transfer_config_t
211  * parameters and how to call the DMA_ConfigBasicTransfer function.
212  * @code
213  *   dma_transfer_config_t transferConfig;
214  *   memset(&transferConfig, 0, sizeof(transferConfig));
215  *   transferConfig.srcAddr = (uint32_t)srcAddr;
216  *   transferConfig.destAddr = (uint32_t)destAddr;
217  *   transferConfig.enbaleSrcIncrement = true;
218  *   transferConfig.enableDestIncrement = true;
219  *   transferConfig.srcSize = kDMA_Transfersize32bits;
220  *   transferConfig.destSize = kDMA_Transfersize32bits;
221  *   transferConfig.transferSize = sizeof(uint32_t) * BUFF_LENGTH;
222  *   DMA_SetTransferConfig(DMA0, 0, &transferConfig);
223  * @endcode
224  *
225  * @param base DMA peripheral base address.
226  * @param channel DMA channel number.
227  * @param config Pointer to the DMA transfer configuration structure.
228  */
229 void DMA_SetTransferConfig(DMA_Type *base, uint32_t channel, const dma_transfer_config_t *config);
230 
231 /*!
232  * @brief Configures the DMA channel link feature.
233  *
234  * This function allows DMA channels to have their transfers linked. The current DMA channel
235  * triggers a DMA request to the linked channels (LCH1 or LCH2) depending on the channel link
236  * type.
237  * Perform a link to channel LCH1 after each cycle-steal transfer followed by a link to LCH2
238  * after the BCR decrements to 0 if the type is kDMA_ChannelLinkChannel1AndChannel2.
239  * Perform a link to LCH1 after each cycle-steal transfer if the type is kDMA_ChannelLinkChannel1.
240  * Perform a link to LCH1 after the BCR decrements to 0 if the type is kDMA_ChannelLinkChannel1AfterBCR0.
241  *
242  * @param base DMA peripheral base address.
243  * @param channel DMA channel number.
244  * @param config Pointer to the channel link configuration structure.
245  */
246 void DMA_SetChannelLinkConfig(DMA_Type *base, uint32_t channel, const dma_channel_link_config_t *config);
247 
248 /*!
249  * @brief Sets the DMA source address for the DMA transfer.
250  *
251  * @param base DMA peripheral base address.
252  * @param channel DMA channel number.
253  * @param srcAddr DMA source address.
254  */
DMA_SetSourceAddress(DMA_Type * base,uint32_t channel,uint32_t srcAddr)255 static inline void DMA_SetSourceAddress(DMA_Type *base, uint32_t channel, uint32_t srcAddr)
256 {
257     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
258 
259     base->DMA[channel].SAR = srcAddr;
260 }
261 
262 /*!
263  * @brief Sets the DMA destination address for the DMA transfer.
264  *
265  * @param base DMA peripheral base address.
266  * @param channel DMA channel number.
267  * @param destAddr DMA destination address.
268  */
DMA_SetDestinationAddress(DMA_Type * base,uint32_t channel,uint32_t destAddr)269 static inline void DMA_SetDestinationAddress(DMA_Type *base, uint32_t channel, uint32_t destAddr)
270 {
271     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
272 
273     base->DMA[channel].DAR = destAddr;
274 }
275 
276 /*!
277  * @brief Sets the DMA transfer size for the DMA transfer.
278  *
279  * @param base DMA peripheral base address.
280  * @param channel DMA channel number.
281  * @param size The number of bytes to be transferred.
282  */
DMA_SetTransferSize(DMA_Type * base,uint32_t channel,uint32_t size)283 static inline void DMA_SetTransferSize(DMA_Type *base, uint32_t channel, uint32_t size)
284 {
285     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
286 
287     base->DMA[channel].DSR_BCR = DMA_DSR_BCR_BCR(size);
288 }
289 
290 /*!
291  * @brief Sets the DMA modulo for the DMA transfer.
292  *
293  * This function defines a specific address range specified to be the value after (SAR + SSIZE)/(DAR + DSIZE)
294  * calculation is performed or the original register value. It provides the ability to implement a circular
295  * data queue easily.
296  *
297  * @param base DMA peripheral base address.
298  * @param channel DMA channel number.
299  * @param srcModulo source address modulo.
300  * @param destModulo destination address modulo.
301  */
302 void DMA_SetModulo(DMA_Type *base, uint32_t channel, dma_modulo_t srcModulo, dma_modulo_t destModulo);
303 
304 /*!
305  * @brief Enables the DMA cycle steal for the DMA transfer.
306  *
307  * If the cycle steal feature is enabled (true), the DMA controller forces a single read/write transfer per request,
308  *  or it continuously makes read/write transfers until the BCR decrements to 0.
309  *
310  * @param base DMA peripheral base address.
311  * @param channel DMA channel number.
312  * @param enable The command for enable (true) or disable (false).
313  */
DMA_EnableCycleSteal(DMA_Type * base,uint32_t channel,bool enable)314 static inline void DMA_EnableCycleSteal(DMA_Type *base, uint32_t channel, bool enable)
315 {
316     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
317 
318     base->DMA[channel].DCR = (base->DMA[channel].DCR & (~DMA_DCR_CS_MASK)) | DMA_DCR_CS(enable);
319 }
320 
321 /*!
322  * @brief Enables the DMA auto align for the DMA transfer.
323  *
324  * If the auto align feature is enabled (true), the appropriate address register increments
325  * regardless of DINC or SINC.
326  *
327  * @param base DMA peripheral base address.
328  * @param channel DMA channel number.
329  * @param enable The command for enable (true) or disable (false).
330  */
DMA_EnableAutoAlign(DMA_Type * base,uint32_t channel,bool enable)331 static inline void DMA_EnableAutoAlign(DMA_Type *base, uint32_t channel, bool enable)
332 {
333     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
334 
335     base->DMA[channel].DCR = (base->DMA[channel].DCR & (~DMA_DCR_AA_MASK)) | DMA_DCR_AA(enable);
336 }
337 
338 /*!
339  * @brief Enables the DMA async request for the DMA transfer.
340  *
341  * If the async request feature is enabled (true), the DMA supports asynchronous DREQs
342  * while the MCU is in stop mode.
343  *
344  * @param base DMA peripheral base address.
345  * @param channel DMA channel number.
346  * @param enable The command for enable (true) or disable (false).
347  */
DMA_EnableAsyncRequest(DMA_Type * base,uint32_t channel,bool enable)348 static inline void DMA_EnableAsyncRequest(DMA_Type *base, uint32_t channel, bool enable)
349 {
350     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
351 
352     base->DMA[channel].DCR = (base->DMA[channel].DCR & (~DMA_DCR_EADREQ_MASK)) | DMA_DCR_EADREQ(enable);
353 }
354 
355 /*!
356  * @brief Enables an interrupt for the DMA transfer.
357  *
358  * @param base DMA peripheral base address.
359  * @param channel DMA channel number.
360  */
DMA_EnableInterrupts(DMA_Type * base,uint32_t channel)361 static inline void DMA_EnableInterrupts(DMA_Type *base, uint32_t channel)
362 {
363     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
364 
365     base->DMA[channel].DCR |= DMA_DCR_EINT(true);
366 }
367 
368 /*!
369  * @brief Disables an interrupt for the DMA transfer.
370  *
371  * @param base DMA peripheral base address.
372  * @param channel DMA channel number.
373  */
DMA_DisableInterrupts(DMA_Type * base,uint32_t channel)374 static inline void DMA_DisableInterrupts(DMA_Type *base, uint32_t channel)
375 {
376     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
377 
378     base->DMA[channel].DCR &= ~DMA_DCR_EINT_MASK;
379 }
380 
381 /* @} */
382 /*!
383  * @name DMA Channel Transfer Operation
384  * @{
385  */
386 
387 /*!
388  * @brief Enables the DMA hardware channel request.
389  *
390  * @param base DMA peripheral base address.
391  * @param channel The DMA channel number.
392  */
DMA_EnableChannelRequest(DMA_Type * base,uint32_t channel)393 static inline void DMA_EnableChannelRequest(DMA_Type *base, uint32_t channel)
394 {
395     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
396 
397     base->DMA[channel].DCR |= DMA_DCR_ERQ_MASK;
398 }
399 
400 /*!
401  * @brief Disables the DMA hardware channel request.
402  *
403  * @param base DMA peripheral base address.
404  * @param channel DMA channel number.
405  */
DMA_DisableChannelRequest(DMA_Type * base,uint32_t channel)406 static inline void DMA_DisableChannelRequest(DMA_Type *base, uint32_t channel)
407 {
408     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
409 
410     base->DMA[channel].DCR &= ~DMA_DCR_ERQ_MASK;
411 }
412 
413 /*!
414  * @brief Starts the DMA transfer with a software trigger.
415  *
416  * This function starts only one read/write iteration.
417  *
418  * @param base DMA peripheral base address.
419  * @param channel The DMA channel number.
420  */
DMA_TriggerChannelStart(DMA_Type * base,uint32_t channel)421 static inline void DMA_TriggerChannelStart(DMA_Type *base, uint32_t channel)
422 {
423     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
424 
425     base->DMA[channel].DCR |= DMA_DCR_START_MASK;
426 }
427 
428 /* @} */
429 /*!
430  * @name DMA Channel Status Operation
431  * @{
432  */
433 
434 /*!
435  * @brief Gets the remaining bytes of the current DMA transfer.
436  *
437  * @param base DMA peripheral base address.
438  * @param channel DMA channel number.
439  * @return The number of bytes which have not been transferred yet.
440  */
DMA_GetRemainingBytes(DMA_Type * base,uint32_t channel)441 static inline uint32_t DMA_GetRemainingBytes(DMA_Type *base, uint32_t channel)
442 {
443     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
444 
445     return (base->DMA[channel].DSR_BCR & DMA_DSR_BCR_BCR_MASK) >> DMA_DSR_BCR_BCR_SHIFT;
446 }
447 
448 /*!
449  * @brief Gets the DMA channel status flags.
450  *
451  * @param base DMA peripheral base address.
452  * @param channel DMA channel number.
453  * @return The mask of the channel status. Use the _dma_channel_status_flags
454  *         type to decode the return 32 bit variables.
455  */
DMA_GetChannelStatusFlags(DMA_Type * base,uint32_t channel)456 static inline uint32_t DMA_GetChannelStatusFlags(DMA_Type *base, uint32_t channel)
457 {
458     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
459 
460     return base->DMA[channel].DSR_BCR;
461 }
462 
463 /*!
464  * @brief Clears the DMA channel status flags.
465  *
466  * @param base DMA peripheral base address.
467  * @param channel DMA channel number.
468  * @param mask The mask of the channel status to be cleared. Use
469  *             the defined _dma_channel_status_flags type.
470  */
DMA_ClearChannelStatusFlags(DMA_Type * base,uint32_t channel,uint32_t mask)471 static inline void DMA_ClearChannelStatusFlags(DMA_Type *base, uint32_t channel, uint32_t mask)
472 {
473     assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
474 
475     if (mask != 0U)
476     {
477         base->DMA[channel].DSR_BCR |= DMA_DSR_BCR_DONE(true);
478     }
479 }
480 
481 /* @} */
482 /*!
483  * @name DMA Channel Transactional Operation
484  * @{
485  */
486 
487 /*!
488  * @brief Creates the DMA handle.
489  *
490  * This function is called first if using the transactional API for the DMA. This function
491  * initializes the internal state of the DMA handle.
492  *
493  * @param handle DMA handle pointer. The DMA handle stores callback function and
494  *               parameters.
495  * @param base DMA peripheral base address.
496  * @param channel DMA channel number.
497  */
498 void DMA_CreateHandle(dma_handle_t *handle, DMA_Type *base, uint32_t channel);
499 
500 /*!
501  * @brief Sets the DMA callback function.
502  *
503  * This callback is called in the DMA IRQ handler. Use the callback to do something
504  * after the current transfer complete.
505  *
506  * @param handle DMA handle pointer.
507  * @param callback DMA callback function pointer.
508  * @param userData Parameter for callback function. If it is not needed, just set to NULL.
509  */
510 void DMA_SetCallback(dma_handle_t *handle, dma_callback callback, void *userData);
511 
512 /*!
513  * @brief Prepares the DMA transfer configuration structure.
514  *
515  * This function prepares the transfer configuration structure according to the user input.
516  *
517  * @param config Pointer to the user configuration structure of type dma_transfer_config_t.
518  * @param srcAddr DMA transfer source address.
519  * @param srcWidth DMA transfer source address width (byte).
520  * @param destAddr DMA transfer destination address.
521  * @param destWidth DMA transfer destination address width (byte).
522  * @param transferBytes DMA transfer bytes to be transferred.
523  * @param type DMA transfer type.
524  */
525 void DMA_PrepareTransfer(dma_transfer_config_t *config,
526                          void *srcAddr,
527                          uint32_t srcWidth,
528                          void *destAddr,
529                          uint32_t destWidth,
530                          uint32_t transferBytes,
531                          dma_transfer_type_t type);
532 
533 /*!
534  * @brief Submits the DMA transfer request.
535  *
536  * This function submits the DMA transfer request according to the transfer configuration structure.
537  *
538  * @param handle DMA handle pointer.
539  * @param config Pointer to DMA transfer configuration structure.
540  * @param options Additional configurations for transfer. Use
541  *                the defined dma_transfer_options_t type.
542  * @retval kStatus_DMA_Success It indicates that the DMA submit transfer request succeeded.
543  * @retval kStatus_DMA_Busy It indicates that the DMA is busy. Submit transfer request is not allowed.
544  * @note This function can't process multi transfer request.
545  */
546 status_t DMA_SubmitTransfer(dma_handle_t *handle, const dma_transfer_config_t *config, uint32_t options);
547 
548 /*!
549  * @brief DMA starts a transfer.
550  *
551  * This function enables the channel request. Call this function
552  * after submitting a transfer request.
553  *
554  * @param handle DMA handle pointer.
555  * @retval kStatus_DMA_Success It indicates that the DMA start transfer succeed.
556  * @retval kStatus_DMA_Busy It indicates that the DMA has started a transfer.
557  */
DMA_StartTransfer(dma_handle_t * handle)558 static inline void DMA_StartTransfer(dma_handle_t *handle)
559 {
560     assert(handle != NULL);
561 
562     handle->base->DMA[handle->channel].DCR |= DMA_DCR_ERQ_MASK;
563 }
564 
565 /*!
566  * @brief DMA stops a transfer.
567  *
568  * This function disables the channel request to stop a DMA transfer.
569  * The transfer can be resumed by calling the DMA_StartTransfer.
570  *
571  * @param handle DMA handle pointer.
572  */
DMA_StopTransfer(dma_handle_t * handle)573 static inline void DMA_StopTransfer(dma_handle_t *handle)
574 {
575     assert(handle != NULL);
576 
577     handle->base->DMA[handle->channel].DCR &= ~DMA_DCR_ERQ_MASK;
578 }
579 
580 /*!
581  * @brief DMA aborts a transfer.
582  *
583  * This function disables the channel request and clears all status bits.
584  * Submit another transfer after calling this API.
585  *
586  * @param handle DMA handle pointer.
587  */
588 void DMA_AbortTransfer(dma_handle_t *handle);
589 
590 /*!
591  * @brief DMA IRQ handler for current transfer complete.
592  *
593  * This function clears the channel interrupt flag and calls
594  * the callback function if it is not NULL.
595  *
596  * @param handle DMA handle pointer.
597  */
598 void DMA_HandleIRQ(dma_handle_t *handle);
599 
600 /* @} */
601 
602 #if defined(__cplusplus)
603 }
604 #endif /* __cplusplus */
605 
606 /* @}*/
607 
608 #endif /* _FSL_DMA_H_ */
609