The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
AnnaBridge 143:86740a56073b 3 * Copyright 2016-2017 NXP
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 143:86740a56073b 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 143:86740a56073b 13 * other materials provided with the distribution.
AnnaBridge 143:86740a56073b 14 *
AnnaBridge 143:86740a56073b 15 * o Neither the name of the copyright holder nor the names of its
AnnaBridge 143:86740a56073b 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 143:86740a56073b 17 * software without specific prior written permission.
AnnaBridge 143:86740a56073b 18 *
AnnaBridge 143:86740a56073b 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 29 */
AnnaBridge 143:86740a56073b 30
AnnaBridge 143:86740a56073b 31 #ifndef _FSL_EDMA_H_
AnnaBridge 143:86740a56073b 32 #define _FSL_EDMA_H_
AnnaBridge 143:86740a56073b 33
AnnaBridge 143:86740a56073b 34 #include "fsl_common.h"
AnnaBridge 143:86740a56073b 35
AnnaBridge 143:86740a56073b 36 /*!
AnnaBridge 143:86740a56073b 37 * @addtogroup edma
AnnaBridge 143:86740a56073b 38 * @{
AnnaBridge 143:86740a56073b 39 */
AnnaBridge 143:86740a56073b 40
AnnaBridge 143:86740a56073b 41 /*******************************************************************************
AnnaBridge 143:86740a56073b 42 * Definitions
AnnaBridge 143:86740a56073b 43 ******************************************************************************/
AnnaBridge 143:86740a56073b 44
AnnaBridge 143:86740a56073b 45 /*! @name Driver version */
AnnaBridge 143:86740a56073b 46 /*@{*/
AnnaBridge 143:86740a56073b 47 /*! @brief eDMA driver version */
AnnaBridge 143:86740a56073b 48 #define FSL_EDMA_DRIVER_VERSION (MAKE_VERSION(2, 1, 1)) /*!< Version 2.1.1. */
AnnaBridge 143:86740a56073b 49 /*@}*/
AnnaBridge 143:86740a56073b 50
AnnaBridge 143:86740a56073b 51 /*! @brief Compute the offset unit from DCHPRI3 */
AnnaBridge 143:86740a56073b 52 #define DMA_DCHPRI_INDEX(channel) (((channel) & ~0x03U) | (3 - ((channel)&0x03U)))
AnnaBridge 143:86740a56073b 53
AnnaBridge 143:86740a56073b 54 /*! @brief Get the pointer of DCHPRIn */
AnnaBridge 143:86740a56073b 55 #define DMA_DCHPRIn(base, channel) ((volatile uint8_t *)&(base->DCHPRI3))[DMA_DCHPRI_INDEX(channel)]
AnnaBridge 143:86740a56073b 56
AnnaBridge 143:86740a56073b 57 /*! @brief eDMA transfer configuration */
AnnaBridge 143:86740a56073b 58 typedef enum _edma_transfer_size
AnnaBridge 143:86740a56073b 59 {
AnnaBridge 143:86740a56073b 60 kEDMA_TransferSize1Bytes = 0x0U, /*!< Source/Destination data transfer size is 1 byte every time */
AnnaBridge 143:86740a56073b 61 kEDMA_TransferSize2Bytes = 0x1U, /*!< Source/Destination data transfer size is 2 bytes every time */
AnnaBridge 143:86740a56073b 62 kEDMA_TransferSize4Bytes = 0x2U, /*!< Source/Destination data transfer size is 4 bytes every time */
AnnaBridge 143:86740a56073b 63 kEDMA_TransferSize16Bytes = 0x4U, /*!< Source/Destination data transfer size is 16 bytes every time */
AnnaBridge 143:86740a56073b 64 kEDMA_TransferSize32Bytes = 0x5U, /*!< Source/Destination data transfer size is 32 bytes every time */
AnnaBridge 143:86740a56073b 65 } edma_transfer_size_t;
AnnaBridge 143:86740a56073b 66
AnnaBridge 143:86740a56073b 67 /*! @brief eDMA modulo configuration */
AnnaBridge 143:86740a56073b 68 typedef enum _edma_modulo
AnnaBridge 143:86740a56073b 69 {
AnnaBridge 143:86740a56073b 70 kEDMA_ModuloDisable = 0x0U, /*!< Disable modulo */
AnnaBridge 143:86740a56073b 71 kEDMA_Modulo2bytes, /*!< Circular buffer size is 2 bytes. */
AnnaBridge 143:86740a56073b 72 kEDMA_Modulo4bytes, /*!< Circular buffer size is 4 bytes. */
AnnaBridge 143:86740a56073b 73 kEDMA_Modulo8bytes, /*!< Circular buffer size is 8 bytes. */
AnnaBridge 143:86740a56073b 74 kEDMA_Modulo16bytes, /*!< Circular buffer size is 16 bytes. */
AnnaBridge 143:86740a56073b 75 kEDMA_Modulo32bytes, /*!< Circular buffer size is 32 bytes. */
AnnaBridge 143:86740a56073b 76 kEDMA_Modulo64bytes, /*!< Circular buffer size is 64 bytes. */
AnnaBridge 143:86740a56073b 77 kEDMA_Modulo128bytes, /*!< Circular buffer size is 128 bytes. */
AnnaBridge 143:86740a56073b 78 kEDMA_Modulo256bytes, /*!< Circular buffer size is 256 bytes. */
AnnaBridge 143:86740a56073b 79 kEDMA_Modulo512bytes, /*!< Circular buffer size is 512 bytes. */
AnnaBridge 143:86740a56073b 80 kEDMA_Modulo1Kbytes, /*!< Circular buffer size is 1 K bytes. */
AnnaBridge 143:86740a56073b 81 kEDMA_Modulo2Kbytes, /*!< Circular buffer size is 2 K bytes. */
AnnaBridge 143:86740a56073b 82 kEDMA_Modulo4Kbytes, /*!< Circular buffer size is 4 K bytes. */
AnnaBridge 143:86740a56073b 83 kEDMA_Modulo8Kbytes, /*!< Circular buffer size is 8 K bytes. */
AnnaBridge 143:86740a56073b 84 kEDMA_Modulo16Kbytes, /*!< Circular buffer size is 16 K bytes. */
AnnaBridge 143:86740a56073b 85 kEDMA_Modulo32Kbytes, /*!< Circular buffer size is 32 K bytes. */
AnnaBridge 143:86740a56073b 86 kEDMA_Modulo64Kbytes, /*!< Circular buffer size is 64 K bytes. */
AnnaBridge 143:86740a56073b 87 kEDMA_Modulo128Kbytes, /*!< Circular buffer size is 128 K bytes. */
AnnaBridge 143:86740a56073b 88 kEDMA_Modulo256Kbytes, /*!< Circular buffer size is 256 K bytes. */
AnnaBridge 143:86740a56073b 89 kEDMA_Modulo512Kbytes, /*!< Circular buffer size is 512 K bytes. */
AnnaBridge 143:86740a56073b 90 kEDMA_Modulo1Mbytes, /*!< Circular buffer size is 1 M bytes. */
AnnaBridge 143:86740a56073b 91 kEDMA_Modulo2Mbytes, /*!< Circular buffer size is 2 M bytes. */
AnnaBridge 143:86740a56073b 92 kEDMA_Modulo4Mbytes, /*!< Circular buffer size is 4 M bytes. */
AnnaBridge 143:86740a56073b 93 kEDMA_Modulo8Mbytes, /*!< Circular buffer size is 8 M bytes. */
AnnaBridge 143:86740a56073b 94 kEDMA_Modulo16Mbytes, /*!< Circular buffer size is 16 M bytes. */
AnnaBridge 143:86740a56073b 95 kEDMA_Modulo32Mbytes, /*!< Circular buffer size is 32 M bytes. */
AnnaBridge 143:86740a56073b 96 kEDMA_Modulo64Mbytes, /*!< Circular buffer size is 64 M bytes. */
AnnaBridge 143:86740a56073b 97 kEDMA_Modulo128Mbytes, /*!< Circular buffer size is 128 M bytes. */
AnnaBridge 143:86740a56073b 98 kEDMA_Modulo256Mbytes, /*!< Circular buffer size is 256 M bytes. */
AnnaBridge 143:86740a56073b 99 kEDMA_Modulo512Mbytes, /*!< Circular buffer size is 512 M bytes. */
AnnaBridge 143:86740a56073b 100 kEDMA_Modulo1Gbytes, /*!< Circular buffer size is 1 G bytes. */
AnnaBridge 143:86740a56073b 101 kEDMA_Modulo2Gbytes, /*!< Circular buffer size is 2 G bytes. */
AnnaBridge 143:86740a56073b 102 } edma_modulo_t;
AnnaBridge 143:86740a56073b 103
AnnaBridge 143:86740a56073b 104 /*! @brief Bandwidth control */
AnnaBridge 143:86740a56073b 105 typedef enum _edma_bandwidth
AnnaBridge 143:86740a56073b 106 {
AnnaBridge 143:86740a56073b 107 kEDMA_BandwidthStallNone = 0x0U, /*!< No eDMA engine stalls. */
AnnaBridge 143:86740a56073b 108 kEDMA_BandwidthStall4Cycle = 0x2U, /*!< eDMA engine stalls for 4 cycles after each read/write. */
AnnaBridge 143:86740a56073b 109 kEDMA_BandwidthStall8Cycle = 0x3U, /*!< eDMA engine stalls for 8 cycles after each read/write. */
AnnaBridge 143:86740a56073b 110 } edma_bandwidth_t;
AnnaBridge 143:86740a56073b 111
AnnaBridge 143:86740a56073b 112 /*! @brief Channel link type */
AnnaBridge 143:86740a56073b 113 typedef enum _edma_channel_link_type
AnnaBridge 143:86740a56073b 114 {
AnnaBridge 143:86740a56073b 115 kEDMA_LinkNone = 0x0U, /*!< No channel link */
AnnaBridge 143:86740a56073b 116 kEDMA_MinorLink, /*!< Channel link after each minor loop */
AnnaBridge 143:86740a56073b 117 kEDMA_MajorLink, /*!< Channel link while major loop count exhausted */
AnnaBridge 143:86740a56073b 118 } edma_channel_link_type_t;
AnnaBridge 143:86740a56073b 119
AnnaBridge 143:86740a56073b 120 /*!@brief eDMA channel status flags. */
AnnaBridge 143:86740a56073b 121 enum _edma_channel_status_flags
AnnaBridge 143:86740a56073b 122 {
AnnaBridge 143:86740a56073b 123 kEDMA_DoneFlag = 0x1U, /*!< DONE flag, set while transfer finished, CITER value exhausted*/
AnnaBridge 143:86740a56073b 124 kEDMA_ErrorFlag = 0x2U, /*!< eDMA error flag, an error occurred in a transfer */
AnnaBridge 143:86740a56073b 125 kEDMA_InterruptFlag = 0x4U, /*!< eDMA interrupt flag, set while an interrupt occurred of this channel */
AnnaBridge 143:86740a56073b 126 };
AnnaBridge 143:86740a56073b 127
AnnaBridge 143:86740a56073b 128 /*! @brief eDMA channel error status flags. */
AnnaBridge 143:86740a56073b 129 enum _edma_error_status_flags
AnnaBridge 143:86740a56073b 130 {
AnnaBridge 143:86740a56073b 131 kEDMA_DestinationBusErrorFlag = DMA_ES_DBE_MASK, /*!< Bus error on destination address */
AnnaBridge 143:86740a56073b 132 kEDMA_SourceBusErrorFlag = DMA_ES_SBE_MASK, /*!< Bus error on the source address */
AnnaBridge 143:86740a56073b 133 kEDMA_ScatterGatherErrorFlag = DMA_ES_SGE_MASK, /*!< Error on the Scatter/Gather address, not 32byte aligned. */
AnnaBridge 143:86740a56073b 134 kEDMA_NbytesErrorFlag = DMA_ES_NCE_MASK, /*!< NBYTES/CITER configuration error */
AnnaBridge 143:86740a56073b 135 kEDMA_DestinationOffsetErrorFlag = DMA_ES_DOE_MASK, /*!< Destination offset not aligned with destination size */
AnnaBridge 143:86740a56073b 136 kEDMA_DestinationAddressErrorFlag = DMA_ES_DAE_MASK, /*!< Destination address not aligned with destination size */
AnnaBridge 143:86740a56073b 137 kEDMA_SourceOffsetErrorFlag = DMA_ES_SOE_MASK, /*!< Source offset not aligned with source size */
AnnaBridge 143:86740a56073b 138 kEDMA_SourceAddressErrorFlag = DMA_ES_SAE_MASK, /*!< Source address not aligned with source size*/
AnnaBridge 143:86740a56073b 139 kEDMA_ErrorChannelFlag = DMA_ES_ERRCHN_MASK, /*!< Error channel number of the cancelled channel number */
AnnaBridge 143:86740a56073b 140 kEDMA_ChannelPriorityErrorFlag = DMA_ES_CPE_MASK, /*!< Channel priority is not unique. */
AnnaBridge 143:86740a56073b 141 kEDMA_TransferCanceledFlag = DMA_ES_ECX_MASK, /*!< Transfer cancelled */
AnnaBridge 143:86740a56073b 142 #if defined(FSL_FEATURE_EDMA_CHANNEL_GROUP_COUNT) && FSL_FEATURE_EDMA_CHANNEL_GROUP_COUNT > 1
AnnaBridge 143:86740a56073b 143 kEDMA_GroupPriorityErrorFlag = DMA_ES_GPE_MASK, /*!< Group priority is not unique. */
AnnaBridge 143:86740a56073b 144 #endif
AnnaBridge 143:86740a56073b 145 kEDMA_ValidFlag = DMA_ES_VLD_MASK, /*!< No error occurred, this bit is 0. Otherwise, it is 1. */
AnnaBridge 143:86740a56073b 146 };
AnnaBridge 143:86740a56073b 147
AnnaBridge 143:86740a56073b 148 /*! @brief eDMA interrupt source */
AnnaBridge 143:86740a56073b 149 typedef enum _edma_interrupt_enable
AnnaBridge 143:86740a56073b 150 {
AnnaBridge 143:86740a56073b 151 kEDMA_ErrorInterruptEnable = 0x1U, /*!< Enable interrupt while channel error occurs. */
AnnaBridge 143:86740a56073b 152 kEDMA_MajorInterruptEnable = DMA_CSR_INTMAJOR_MASK, /*!< Enable interrupt while major count exhausted. */
AnnaBridge 143:86740a56073b 153 kEDMA_HalfInterruptEnable = DMA_CSR_INTHALF_MASK, /*!< Enable interrupt while major count to half value. */
AnnaBridge 143:86740a56073b 154 } edma_interrupt_enable_t;
AnnaBridge 143:86740a56073b 155
AnnaBridge 143:86740a56073b 156 /*! @brief eDMA transfer type */
AnnaBridge 143:86740a56073b 157 typedef enum _edma_transfer_type
AnnaBridge 143:86740a56073b 158 {
AnnaBridge 143:86740a56073b 159 kEDMA_MemoryToMemory = 0x0U, /*!< Transfer from memory to memory */
AnnaBridge 143:86740a56073b 160 kEDMA_PeripheralToMemory, /*!< Transfer from peripheral to memory */
AnnaBridge 143:86740a56073b 161 kEDMA_MemoryToPeripheral, /*!< Transfer from memory to peripheral */
AnnaBridge 143:86740a56073b 162 } edma_transfer_type_t;
AnnaBridge 143:86740a56073b 163
AnnaBridge 143:86740a56073b 164 /*! @brief eDMA transfer status */
AnnaBridge 143:86740a56073b 165 enum _edma_transfer_status
AnnaBridge 143:86740a56073b 166 {
AnnaBridge 143:86740a56073b 167 kStatus_EDMA_QueueFull = MAKE_STATUS(kStatusGroup_EDMA, 0), /*!< TCD queue is full. */
AnnaBridge 143:86740a56073b 168 kStatus_EDMA_Busy = MAKE_STATUS(kStatusGroup_EDMA, 1), /*!< Channel is busy and can't handle the
AnnaBridge 143:86740a56073b 169 transfer request. */
AnnaBridge 143:86740a56073b 170 };
AnnaBridge 143:86740a56073b 171
AnnaBridge 143:86740a56073b 172 /*! @brief eDMA global configuration structure.*/
AnnaBridge 143:86740a56073b 173 typedef struct _edma_config
AnnaBridge 143:86740a56073b 174 {
AnnaBridge 143:86740a56073b 175 bool enableContinuousLinkMode; /*!< Enable (true) continuous link mode. Upon minor loop completion, the channel
AnnaBridge 143:86740a56073b 176 activates again if that channel has a minor loop channel link enabled and
AnnaBridge 143:86740a56073b 177 the link channel is itself. */
AnnaBridge 143:86740a56073b 178 bool enableHaltOnError; /*!< Enable (true) transfer halt on error. Any error causes the HALT bit to set.
AnnaBridge 143:86740a56073b 179 Subsequently, all service requests are ignored until the HALT bit is cleared.*/
AnnaBridge 143:86740a56073b 180 bool enableRoundRobinArbitration; /*!< Enable (true) round robin channel arbitration method or fixed priority
AnnaBridge 143:86740a56073b 181 arbitration is used for channel selection */
AnnaBridge 143:86740a56073b 182 bool enableDebugMode; /*!< Enable(true) eDMA debug mode. When in debug mode, the eDMA stalls the start of
AnnaBridge 143:86740a56073b 183 a new channel. Executing channels are allowed to complete. */
AnnaBridge 143:86740a56073b 184 } edma_config_t;
AnnaBridge 143:86740a56073b 185
AnnaBridge 143:86740a56073b 186 /*!
AnnaBridge 143:86740a56073b 187 * @brief eDMA transfer configuration
AnnaBridge 143:86740a56073b 188 *
AnnaBridge 143:86740a56073b 189 * This structure configures the source/destination transfer attribute.
AnnaBridge 143:86740a56073b 190 * This figure shows the eDMA's transfer model:
AnnaBridge 143:86740a56073b 191 * _________________________________________________
AnnaBridge 143:86740a56073b 192 * | Transfer Size | |
AnnaBridge 143:86740a56073b 193 * Minor Loop |_______________| Major loop Count 1 |
AnnaBridge 143:86740a56073b 194 * Bytes | Transfer Size | |
AnnaBridge 143:86740a56073b 195 * ____________|_______________|____________________|--> Minor loop complete
AnnaBridge 143:86740a56073b 196 * ____________________________________
AnnaBridge 143:86740a56073b 197 * | | |
AnnaBridge 143:86740a56073b 198 * |_______________| Major Loop Count 2 |
AnnaBridge 143:86740a56073b 199 * | | |
AnnaBridge 143:86740a56073b 200 * |_______________|____________________|--> Minor loop Complete
AnnaBridge 143:86740a56073b 201 *
AnnaBridge 143:86740a56073b 202 * ---------------------------------------------------------> Transfer complete
AnnaBridge 143:86740a56073b 203 */
AnnaBridge 143:86740a56073b 204 typedef struct _edma_transfer_config
AnnaBridge 143:86740a56073b 205 {
AnnaBridge 143:86740a56073b 206 uint32_t srcAddr; /*!< Source data address. */
AnnaBridge 143:86740a56073b 207 uint32_t destAddr; /*!< Destination data address. */
AnnaBridge 143:86740a56073b 208 edma_transfer_size_t srcTransferSize; /*!< Source data transfer size. */
AnnaBridge 143:86740a56073b 209 edma_transfer_size_t destTransferSize; /*!< Destination data transfer size. */
AnnaBridge 143:86740a56073b 210 int16_t srcOffset; /*!< Sign-extended offset applied to the current source address to
AnnaBridge 143:86740a56073b 211 form the next-state value as each source read is completed. */
AnnaBridge 143:86740a56073b 212 int16_t destOffset; /*!< Sign-extended offset applied to the current destination address to
AnnaBridge 143:86740a56073b 213 form the next-state value as each destination write is completed. */
AnnaBridge 143:86740a56073b 214 uint32_t minorLoopBytes; /*!< Bytes to transfer in a minor loop*/
AnnaBridge 143:86740a56073b 215 uint32_t majorLoopCounts; /*!< Major loop iteration count. */
AnnaBridge 143:86740a56073b 216 } edma_transfer_config_t;
AnnaBridge 143:86740a56073b 217
AnnaBridge 143:86740a56073b 218 /*! @brief eDMA channel priority configuration */
AnnaBridge 143:86740a56073b 219 typedef struct _edma_channel_Preemption_config
AnnaBridge 143:86740a56073b 220 {
AnnaBridge 143:86740a56073b 221 bool enableChannelPreemption; /*!< If true: a channel can be suspended by other channel with higher priority */
AnnaBridge 143:86740a56073b 222 bool enablePreemptAbility; /*!< If true: a channel can suspend other channel with low priority */
AnnaBridge 143:86740a56073b 223 uint8_t channelPriority; /*!< Channel priority */
AnnaBridge 143:86740a56073b 224 } edma_channel_Preemption_config_t;
AnnaBridge 143:86740a56073b 225
AnnaBridge 143:86740a56073b 226 /*! @brief eDMA minor offset configuration */
AnnaBridge 143:86740a56073b 227 typedef struct _edma_minor_offset_config
AnnaBridge 143:86740a56073b 228 {
AnnaBridge 143:86740a56073b 229 bool enableSrcMinorOffset; /*!< Enable(true) or Disable(false) source minor loop offset. */
AnnaBridge 143:86740a56073b 230 bool enableDestMinorOffset; /*!< Enable(true) or Disable(false) destination minor loop offset. */
AnnaBridge 143:86740a56073b 231 uint32_t minorOffset; /*!< Offset for a minor loop mapping. */
AnnaBridge 143:86740a56073b 232 } edma_minor_offset_config_t;
AnnaBridge 143:86740a56073b 233
AnnaBridge 143:86740a56073b 234 /*!
AnnaBridge 143:86740a56073b 235 * @brief eDMA TCD.
AnnaBridge 143:86740a56073b 236 *
AnnaBridge 143:86740a56073b 237 * This structure is same as TCD register which is described in reference manual,
AnnaBridge 143:86740a56073b 238 * and is used to configure the scatter/gather feature as a next hardware TCD.
AnnaBridge 143:86740a56073b 239 */
AnnaBridge 143:86740a56073b 240 typedef struct _edma_tcd
AnnaBridge 143:86740a56073b 241 {
AnnaBridge 143:86740a56073b 242 __IO uint32_t SADDR; /*!< SADDR register, used to save source address */
AnnaBridge 143:86740a56073b 243 __IO uint16_t SOFF; /*!< SOFF register, save offset bytes every transfer */
AnnaBridge 143:86740a56073b 244 __IO uint16_t ATTR; /*!< ATTR register, source/destination transfer size and modulo */
AnnaBridge 143:86740a56073b 245 __IO uint32_t NBYTES; /*!< Nbytes register, minor loop length in bytes */
AnnaBridge 143:86740a56073b 246 __IO uint32_t SLAST; /*!< SLAST register */
AnnaBridge 143:86740a56073b 247 __IO uint32_t DADDR; /*!< DADDR register, used for destination address */
AnnaBridge 143:86740a56073b 248 __IO uint16_t DOFF; /*!< DOFF register, used for destination offset */
AnnaBridge 143:86740a56073b 249 __IO uint16_t CITER; /*!< CITER register, current minor loop numbers, for unfinished minor loop.*/
AnnaBridge 143:86740a56073b 250 __IO uint32_t DLAST_SGA; /*!< DLASTSGA register, next stcd address used in scatter-gather mode */
AnnaBridge 143:86740a56073b 251 __IO uint16_t CSR; /*!< CSR register, for TCD control status */
AnnaBridge 143:86740a56073b 252 __IO uint16_t BITER; /*!< BITER register, begin minor loop count. */
AnnaBridge 143:86740a56073b 253 } edma_tcd_t;
AnnaBridge 143:86740a56073b 254
AnnaBridge 143:86740a56073b 255 /*! @brief Callback for eDMA */
AnnaBridge 143:86740a56073b 256 struct _edma_handle;
AnnaBridge 143:86740a56073b 257
AnnaBridge 143:86740a56073b 258 /*! @brief Define callback function for eDMA. */
AnnaBridge 143:86740a56073b 259 typedef void (*edma_callback)(struct _edma_handle *handle, void *userData, bool transferDone, uint32_t tcds);
AnnaBridge 143:86740a56073b 260
AnnaBridge 143:86740a56073b 261 /*! @brief eDMA transfer handle structure */
AnnaBridge 143:86740a56073b 262 typedef struct _edma_handle
AnnaBridge 143:86740a56073b 263 {
AnnaBridge 143:86740a56073b 264 edma_callback callback; /*!< Callback function for major count exhausted. */
AnnaBridge 143:86740a56073b 265 void *userData; /*!< Callback function parameter. */
AnnaBridge 143:86740a56073b 266 DMA_Type *base; /*!< eDMA peripheral base address. */
AnnaBridge 143:86740a56073b 267 edma_tcd_t *tcdPool; /*!< Pointer to memory stored TCDs. */
AnnaBridge 143:86740a56073b 268 uint8_t channel; /*!< eDMA channel number. */
AnnaBridge 143:86740a56073b 269 volatile int8_t header; /*!< The first TCD index. Should point to the next TCD to be loaded into the eDMA engine. */
AnnaBridge 143:86740a56073b 270 volatile int8_t tail; /*!< The last TCD index. Should point to the next TCD to be stored into the memory pool. */
AnnaBridge 143:86740a56073b 271 volatile int8_t tcdUsed; /*!< The number of used TCD slots. Should reflect the number of TCDs can be used/loaded in
AnnaBridge 143:86740a56073b 272 the memory. */
AnnaBridge 143:86740a56073b 273 volatile int8_t tcdSize; /*!< The total number of TCD slots in the queue. */
AnnaBridge 143:86740a56073b 274 uint8_t flags; /*!< The status of the current channel. */
AnnaBridge 143:86740a56073b 275 } edma_handle_t;
AnnaBridge 143:86740a56073b 276
AnnaBridge 143:86740a56073b 277 /*******************************************************************************
AnnaBridge 143:86740a56073b 278 * APIs
AnnaBridge 143:86740a56073b 279 ******************************************************************************/
AnnaBridge 143:86740a56073b 280 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 281 extern "C" {
AnnaBridge 143:86740a56073b 282 #endif /* __cplusplus */
AnnaBridge 143:86740a56073b 283
AnnaBridge 143:86740a56073b 284 /*!
AnnaBridge 143:86740a56073b 285 * @name eDMA initialization and de-initialization
AnnaBridge 143:86740a56073b 286 * @{
AnnaBridge 143:86740a56073b 287 */
AnnaBridge 143:86740a56073b 288
AnnaBridge 143:86740a56073b 289 /*!
AnnaBridge 143:86740a56073b 290 * @brief Initializes the eDMA peripheral.
AnnaBridge 143:86740a56073b 291 *
AnnaBridge 143:86740a56073b 292 * This function ungates the eDMA clock and configures the eDMA peripheral according
AnnaBridge 143:86740a56073b 293 * to the configuration structure.
AnnaBridge 143:86740a56073b 294 *
AnnaBridge 143:86740a56073b 295 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 296 * @param config A pointer to the configuration structure, see "edma_config_t".
AnnaBridge 143:86740a56073b 297 * @note This function enables the minor loop map feature.
AnnaBridge 143:86740a56073b 298 */
AnnaBridge 143:86740a56073b 299 void EDMA_Init(DMA_Type *base, const edma_config_t *config);
AnnaBridge 143:86740a56073b 300
AnnaBridge 143:86740a56073b 301 /*!
AnnaBridge 143:86740a56073b 302 * @brief Deinitializes the eDMA peripheral.
AnnaBridge 143:86740a56073b 303 *
AnnaBridge 143:86740a56073b 304 * This function gates the eDMA clock.
AnnaBridge 143:86740a56073b 305 *
AnnaBridge 143:86740a56073b 306 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 307 */
AnnaBridge 143:86740a56073b 308 void EDMA_Deinit(DMA_Type *base);
AnnaBridge 143:86740a56073b 309
AnnaBridge 143:86740a56073b 310 /*!
AnnaBridge 143:86740a56073b 311 * @brief Gets the eDMA default configuration structure.
AnnaBridge 143:86740a56073b 312 *
AnnaBridge 143:86740a56073b 313 * This function sets the configuration structure to default values.
AnnaBridge 143:86740a56073b 314 * The default configuration is set to the following values.
AnnaBridge 143:86740a56073b 315 * @code
AnnaBridge 143:86740a56073b 316 * config.enableContinuousLinkMode = false;
AnnaBridge 143:86740a56073b 317 * config.enableHaltOnError = true;
AnnaBridge 143:86740a56073b 318 * config.enableRoundRobinArbitration = false;
AnnaBridge 143:86740a56073b 319 * config.enableDebugMode = false;
AnnaBridge 143:86740a56073b 320 * @endcode
AnnaBridge 143:86740a56073b 321 *
AnnaBridge 143:86740a56073b 322 * @param config A pointer to the eDMA configuration structure.
AnnaBridge 143:86740a56073b 323 */
AnnaBridge 143:86740a56073b 324 void EDMA_GetDefaultConfig(edma_config_t *config);
AnnaBridge 143:86740a56073b 325
AnnaBridge 143:86740a56073b 326 /* @} */
AnnaBridge 143:86740a56073b 327 /*!
AnnaBridge 143:86740a56073b 328 * @name eDMA Channel Operation
AnnaBridge 143:86740a56073b 329 * @{
AnnaBridge 143:86740a56073b 330 */
AnnaBridge 143:86740a56073b 331
AnnaBridge 143:86740a56073b 332 /*!
AnnaBridge 143:86740a56073b 333 * @brief Sets all TCD registers to default values.
AnnaBridge 143:86740a56073b 334 *
AnnaBridge 143:86740a56073b 335 * This function sets TCD registers for this channel to default values.
AnnaBridge 143:86740a56073b 336 *
AnnaBridge 143:86740a56073b 337 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 338 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 339 * @note This function must not be called while the channel transfer is ongoing
AnnaBridge 143:86740a56073b 340 * or it causes unpredictable results.
AnnaBridge 143:86740a56073b 341 * @note This function enables the auto stop request feature.
AnnaBridge 143:86740a56073b 342 */
AnnaBridge 143:86740a56073b 343 void EDMA_ResetChannel(DMA_Type *base, uint32_t channel);
AnnaBridge 143:86740a56073b 344
AnnaBridge 143:86740a56073b 345 /*!
AnnaBridge 143:86740a56073b 346 * @brief Configures the eDMA transfer attribute.
AnnaBridge 143:86740a56073b 347 *
AnnaBridge 143:86740a56073b 348 * This function configures the transfer attribute, including source address, destination address,
AnnaBridge 143:86740a56073b 349 * transfer size, address offset, and so on. It also configures the scatter gather feature if the
AnnaBridge 143:86740a56073b 350 * user supplies the TCD address.
AnnaBridge 143:86740a56073b 351 * Example:
AnnaBridge 143:86740a56073b 352 * @code
AnnaBridge 143:86740a56073b 353 * edma_transfer_t config;
AnnaBridge 143:86740a56073b 354 * edma_tcd_t tcd;
AnnaBridge 143:86740a56073b 355 * config.srcAddr = ..;
AnnaBridge 143:86740a56073b 356 * config.destAddr = ..;
AnnaBridge 143:86740a56073b 357 * ...
AnnaBridge 143:86740a56073b 358 * EDMA_SetTransferConfig(DMA0, channel, &config, &stcd);
AnnaBridge 143:86740a56073b 359 * @endcode
AnnaBridge 143:86740a56073b 360 *
AnnaBridge 143:86740a56073b 361 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 362 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 363 * @param config Pointer to eDMA transfer configuration structure.
AnnaBridge 143:86740a56073b 364 * @param nextTcd Point to TCD structure. It can be NULL if users
AnnaBridge 143:86740a56073b 365 * do not want to enable scatter/gather feature.
AnnaBridge 143:86740a56073b 366 * @note If nextTcd is not NULL, it means scatter gather feature is enabled
AnnaBridge 143:86740a56073b 367 * and DREQ bit is cleared in the previous transfer configuration, which
AnnaBridge 143:86740a56073b 368 * is set in the eDMA_ResetChannel.
AnnaBridge 143:86740a56073b 369 */
AnnaBridge 143:86740a56073b 370 void EDMA_SetTransferConfig(DMA_Type *base,
AnnaBridge 143:86740a56073b 371 uint32_t channel,
AnnaBridge 143:86740a56073b 372 const edma_transfer_config_t *config,
AnnaBridge 143:86740a56073b 373 edma_tcd_t *nextTcd);
AnnaBridge 143:86740a56073b 374
AnnaBridge 143:86740a56073b 375 /*!
AnnaBridge 143:86740a56073b 376 * @brief Configures the eDMA minor offset feature.
AnnaBridge 143:86740a56073b 377 *
AnnaBridge 143:86740a56073b 378 * The minor offset means that the signed-extended value is added to the source address or destination
AnnaBridge 143:86740a56073b 379 * address after each minor loop.
AnnaBridge 143:86740a56073b 380 *
AnnaBridge 143:86740a56073b 381 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 382 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 383 * @param config A pointer to the minor offset configuration structure.
AnnaBridge 143:86740a56073b 384 */
AnnaBridge 143:86740a56073b 385 void EDMA_SetMinorOffsetConfig(DMA_Type *base, uint32_t channel, const edma_minor_offset_config_t *config);
AnnaBridge 143:86740a56073b 386
AnnaBridge 143:86740a56073b 387 /*!
AnnaBridge 143:86740a56073b 388 * @brief Configures the eDMA channel preemption feature.
AnnaBridge 143:86740a56073b 389 *
AnnaBridge 143:86740a56073b 390 * This function configures the channel preemption attribute and the priority of the channel.
AnnaBridge 143:86740a56073b 391 *
AnnaBridge 143:86740a56073b 392 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 393 * @param channel eDMA channel number
AnnaBridge 143:86740a56073b 394 * @param config A pointer to the channel preemption configuration structure.
AnnaBridge 143:86740a56073b 395 */
AnnaBridge 143:86740a56073b 396 static inline void EDMA_SetChannelPreemptionConfig(DMA_Type *base,
AnnaBridge 143:86740a56073b 397 uint32_t channel,
AnnaBridge 143:86740a56073b 398 const edma_channel_Preemption_config_t *config)
AnnaBridge 143:86740a56073b 399 {
AnnaBridge 143:86740a56073b 400 assert(channel < FSL_FEATURE_EDMA_MODULE_CHANNEL);
AnnaBridge 143:86740a56073b 401 assert(config != NULL);
AnnaBridge 143:86740a56073b 402
AnnaBridge 143:86740a56073b 403 DMA_DCHPRIn(base, channel) =
AnnaBridge 143:86740a56073b 404 (DMA_DCHPRI0_DPA(!config->enablePreemptAbility) | DMA_DCHPRI0_ECP(config->enableChannelPreemption) |
AnnaBridge 143:86740a56073b 405 DMA_DCHPRI0_CHPRI(config->channelPriority));
AnnaBridge 143:86740a56073b 406 }
AnnaBridge 143:86740a56073b 407
AnnaBridge 143:86740a56073b 408 /*!
AnnaBridge 143:86740a56073b 409 * @brief Sets the channel link for the eDMA transfer.
AnnaBridge 143:86740a56073b 410 *
AnnaBridge 143:86740a56073b 411 * This function configures either the minor link or the major link mode. The minor link means that the channel link is
AnnaBridge 143:86740a56073b 412 * triggered every time CITER decreases by 1. The major link means that the channel link is triggered when the CITER is
AnnaBridge 143:86740a56073b 413 * exhausted.
AnnaBridge 143:86740a56073b 414 *
AnnaBridge 143:86740a56073b 415 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 416 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 417 * @param type A channel link type, which can be one of the following:
AnnaBridge 143:86740a56073b 418 * @arg kEDMA_LinkNone
AnnaBridge 143:86740a56073b 419 * @arg kEDMA_MinorLink
AnnaBridge 143:86740a56073b 420 * @arg kEDMA_MajorLink
AnnaBridge 143:86740a56073b 421 * @param linkedChannel The linked channel number.
AnnaBridge 143:86740a56073b 422 * @note Users should ensure that DONE flag is cleared before calling this interface, or the configuration is invalid.
AnnaBridge 143:86740a56073b 423 */
AnnaBridge 143:86740a56073b 424 void EDMA_SetChannelLink(DMA_Type *base, uint32_t channel, edma_channel_link_type_t type, uint32_t linkedChannel);
AnnaBridge 143:86740a56073b 425
AnnaBridge 143:86740a56073b 426 /*!
AnnaBridge 143:86740a56073b 427 * @brief Sets the bandwidth for the eDMA transfer.
AnnaBridge 143:86740a56073b 428 *
AnnaBridge 143:86740a56073b 429 * Because the eDMA processes the minor loop, it continuously generates read/write sequences
AnnaBridge 143:86740a56073b 430 * until the minor count is exhausted. The bandwidth forces the eDMA to stall after the completion of
AnnaBridge 143:86740a56073b 431 * each read/write access to control the bus request bandwidth seen by the crossbar switch.
AnnaBridge 143:86740a56073b 432 *
AnnaBridge 143:86740a56073b 433 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 434 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 435 * @param bandWidth A bandwidth setting, which can be one of the following:
AnnaBridge 143:86740a56073b 436 * @arg kEDMABandwidthStallNone
AnnaBridge 143:86740a56073b 437 * @arg kEDMABandwidthStall4Cycle
AnnaBridge 143:86740a56073b 438 * @arg kEDMABandwidthStall8Cycle
AnnaBridge 143:86740a56073b 439 */
AnnaBridge 143:86740a56073b 440 void EDMA_SetBandWidth(DMA_Type *base, uint32_t channel, edma_bandwidth_t bandWidth);
AnnaBridge 143:86740a56073b 441
AnnaBridge 143:86740a56073b 442 /*!
AnnaBridge 143:86740a56073b 443 * @brief Sets the source modulo and the destination modulo for the eDMA transfer.
AnnaBridge 143:86740a56073b 444 *
AnnaBridge 143:86740a56073b 445 * This function defines a specific address range specified to be the value after (SADDR + SOFF)/(DADDR + DOFF)
AnnaBridge 143:86740a56073b 446 * calculation is performed or the original register value. It provides the ability to implement a circular data
AnnaBridge 143:86740a56073b 447 * queue easily.
AnnaBridge 143:86740a56073b 448 *
AnnaBridge 143:86740a56073b 449 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 450 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 451 * @param srcModulo A source modulo value.
AnnaBridge 143:86740a56073b 452 * @param destModulo A destination modulo value.
AnnaBridge 143:86740a56073b 453 */
AnnaBridge 143:86740a56073b 454 void EDMA_SetModulo(DMA_Type *base, uint32_t channel, edma_modulo_t srcModulo, edma_modulo_t destModulo);
AnnaBridge 143:86740a56073b 455
AnnaBridge 143:86740a56073b 456 #if defined(FSL_FEATURE_EDMA_ASYNCHRO_REQUEST_CHANNEL_COUNT) && FSL_FEATURE_EDMA_ASYNCHRO_REQUEST_CHANNEL_COUNT
AnnaBridge 143:86740a56073b 457 /*!
AnnaBridge 143:86740a56073b 458 * @brief Enables an async request for the eDMA transfer.
AnnaBridge 143:86740a56073b 459 *
AnnaBridge 143:86740a56073b 460 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 461 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 462 * @param enable The command to enable (true) or disable (false).
AnnaBridge 143:86740a56073b 463 */
AnnaBridge 143:86740a56073b 464 static inline void EDMA_EnableAsyncRequest(DMA_Type *base, uint32_t channel, bool enable)
AnnaBridge 143:86740a56073b 465 {
AnnaBridge 143:86740a56073b 466 assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
AnnaBridge 143:86740a56073b 467
AnnaBridge 143:86740a56073b 468 base->EARS = (base->EARS & (~(1U << channel))) | ((uint32_t)enable << channel);
AnnaBridge 143:86740a56073b 469 }
AnnaBridge 143:86740a56073b 470 #endif /* FSL_FEATURE_EDMA_ASYNCHRO_REQUEST_CHANNEL_COUNT */
AnnaBridge 143:86740a56073b 471
AnnaBridge 143:86740a56073b 472 /*!
AnnaBridge 143:86740a56073b 473 * @brief Enables an auto stop request for the eDMA transfer.
AnnaBridge 143:86740a56073b 474 *
AnnaBridge 143:86740a56073b 475 * If enabling the auto stop request, the eDMA hardware automatically disables the hardware channel request.
AnnaBridge 143:86740a56073b 476 *
AnnaBridge 143:86740a56073b 477 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 478 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 479 * @param enable The command to enable (true) or disable (false).
AnnaBridge 143:86740a56073b 480 */
AnnaBridge 143:86740a56073b 481 static inline void EDMA_EnableAutoStopRequest(DMA_Type *base, uint32_t channel, bool enable)
AnnaBridge 143:86740a56073b 482 {
AnnaBridge 143:86740a56073b 483 assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
AnnaBridge 143:86740a56073b 484
AnnaBridge 143:86740a56073b 485 base->TCD[channel].CSR = (base->TCD[channel].CSR & (~DMA_CSR_DREQ_MASK)) | DMA_CSR_DREQ(enable);
AnnaBridge 143:86740a56073b 486 }
AnnaBridge 143:86740a56073b 487
AnnaBridge 143:86740a56073b 488 /*!
AnnaBridge 143:86740a56073b 489 * @brief Enables the interrupt source for the eDMA transfer.
AnnaBridge 143:86740a56073b 490 *
AnnaBridge 143:86740a56073b 491 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 492 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 493 * @param mask The mask of interrupt source to be set. Users need to use
AnnaBridge 143:86740a56073b 494 * the defined edma_interrupt_enable_t type.
AnnaBridge 143:86740a56073b 495 */
AnnaBridge 143:86740a56073b 496 void EDMA_EnableChannelInterrupts(DMA_Type *base, uint32_t channel, uint32_t mask);
AnnaBridge 143:86740a56073b 497
AnnaBridge 143:86740a56073b 498 /*!
AnnaBridge 143:86740a56073b 499 * @brief Disables the interrupt source for the eDMA transfer.
AnnaBridge 143:86740a56073b 500 *
AnnaBridge 143:86740a56073b 501 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 502 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 503 * @param mask The mask of the interrupt source to be set. Use
AnnaBridge 143:86740a56073b 504 * the defined edma_interrupt_enable_t type.
AnnaBridge 143:86740a56073b 505 */
AnnaBridge 143:86740a56073b 506 void EDMA_DisableChannelInterrupts(DMA_Type *base, uint32_t channel, uint32_t mask);
AnnaBridge 143:86740a56073b 507
AnnaBridge 143:86740a56073b 508 /* @} */
AnnaBridge 143:86740a56073b 509 /*!
AnnaBridge 143:86740a56073b 510 * @name eDMA TCD Operation
AnnaBridge 143:86740a56073b 511 * @{
AnnaBridge 143:86740a56073b 512 */
AnnaBridge 143:86740a56073b 513
AnnaBridge 143:86740a56073b 514 /*!
AnnaBridge 143:86740a56073b 515 * @brief Sets all fields to default values for the TCD structure.
AnnaBridge 143:86740a56073b 516 *
AnnaBridge 143:86740a56073b 517 * This function sets all fields for this TCD structure to default value.
AnnaBridge 143:86740a56073b 518 *
AnnaBridge 143:86740a56073b 519 * @param tcd Pointer to the TCD structure.
AnnaBridge 143:86740a56073b 520 * @note This function enables the auto stop request feature.
AnnaBridge 143:86740a56073b 521 */
AnnaBridge 143:86740a56073b 522 void EDMA_TcdReset(edma_tcd_t *tcd);
AnnaBridge 143:86740a56073b 523
AnnaBridge 143:86740a56073b 524 /*!
AnnaBridge 143:86740a56073b 525 * @brief Configures the eDMA TCD transfer attribute.
AnnaBridge 143:86740a56073b 526 *
AnnaBridge 143:86740a56073b 527 * The TCD is a transfer control descriptor. The content of the TCD is the same as the hardware TCD registers.
AnnaBridge 143:86740a56073b 528 * The STCD is used in the scatter-gather mode.
AnnaBridge 143:86740a56073b 529 * This function configures the TCD transfer attribute, including source address, destination address,
AnnaBridge 143:86740a56073b 530 * transfer size, address offset, and so on. It also configures the scatter gather feature if the
AnnaBridge 143:86740a56073b 531 * user supplies the next TCD address.
AnnaBridge 143:86740a56073b 532 * Example:
AnnaBridge 143:86740a56073b 533 * @code
AnnaBridge 143:86740a56073b 534 * edma_transfer_t config = {
AnnaBridge 143:86740a56073b 535 * ...
AnnaBridge 143:86740a56073b 536 * }
AnnaBridge 143:86740a56073b 537 * edma_tcd_t tcd __aligned(32);
AnnaBridge 143:86740a56073b 538 * edma_tcd_t nextTcd __aligned(32);
AnnaBridge 143:86740a56073b 539 * EDMA_TcdSetTransferConfig(&tcd, &config, &nextTcd);
AnnaBridge 143:86740a56073b 540 * @endcode
AnnaBridge 143:86740a56073b 541 *
AnnaBridge 143:86740a56073b 542 * @param tcd Pointer to the TCD structure.
AnnaBridge 143:86740a56073b 543 * @param config Pointer to eDMA transfer configuration structure.
AnnaBridge 143:86740a56073b 544 * @param nextTcd Pointer to the next TCD structure. It can be NULL if users
AnnaBridge 143:86740a56073b 545 * do not want to enable scatter/gather feature.
AnnaBridge 143:86740a56073b 546 * @note TCD address should be 32 bytes aligned or it causes an eDMA error.
AnnaBridge 143:86740a56073b 547 * @note If the nextTcd is not NULL, the scatter gather feature is enabled
AnnaBridge 143:86740a56073b 548 * and DREQ bit is cleared in the previous transfer configuration, which
AnnaBridge 143:86740a56073b 549 * is set in the EDMA_TcdReset.
AnnaBridge 143:86740a56073b 550 */
AnnaBridge 143:86740a56073b 551 void EDMA_TcdSetTransferConfig(edma_tcd_t *tcd, const edma_transfer_config_t *config, edma_tcd_t *nextTcd);
AnnaBridge 143:86740a56073b 552
AnnaBridge 143:86740a56073b 553 /*!
AnnaBridge 143:86740a56073b 554 * @brief Configures the eDMA TCD minor offset feature.
AnnaBridge 143:86740a56073b 555 *
AnnaBridge 143:86740a56073b 556 * A minor offset is a signed-extended value added to the source address or a destination
AnnaBridge 143:86740a56073b 557 * address after each minor loop.
AnnaBridge 143:86740a56073b 558 *
AnnaBridge 143:86740a56073b 559 * @param tcd A point to the TCD structure.
AnnaBridge 143:86740a56073b 560 * @param config A pointer to the minor offset configuration structure.
AnnaBridge 143:86740a56073b 561 */
AnnaBridge 143:86740a56073b 562 void EDMA_TcdSetMinorOffsetConfig(edma_tcd_t *tcd, const edma_minor_offset_config_t *config);
AnnaBridge 143:86740a56073b 563
AnnaBridge 143:86740a56073b 564 /*!
AnnaBridge 143:86740a56073b 565 * @brief Sets the channel link for the eDMA TCD.
AnnaBridge 143:86740a56073b 566 *
AnnaBridge 143:86740a56073b 567 * This function configures either a minor link or a major link. The minor link means the channel link is
AnnaBridge 143:86740a56073b 568 * triggered every time CITER decreases by 1. The major link means that the channel link is triggered when the CITER is
AnnaBridge 143:86740a56073b 569 * exhausted.
AnnaBridge 143:86740a56073b 570 *
AnnaBridge 143:86740a56073b 571 * @note Users should ensure that DONE flag is cleared before calling this interface, or the configuration is invalid.
AnnaBridge 143:86740a56073b 572 * @param tcd Point to the TCD structure.
AnnaBridge 143:86740a56073b 573 * @param type Channel link type, it can be one of:
AnnaBridge 143:86740a56073b 574 * @arg kEDMA_LinkNone
AnnaBridge 143:86740a56073b 575 * @arg kEDMA_MinorLink
AnnaBridge 143:86740a56073b 576 * @arg kEDMA_MajorLink
AnnaBridge 143:86740a56073b 577 * @param linkedChannel The linked channel number.
AnnaBridge 143:86740a56073b 578 */
AnnaBridge 143:86740a56073b 579 void EDMA_TcdSetChannelLink(edma_tcd_t *tcd, edma_channel_link_type_t type, uint32_t linkedChannel);
AnnaBridge 143:86740a56073b 580
AnnaBridge 143:86740a56073b 581 /*!
AnnaBridge 143:86740a56073b 582 * @brief Sets the bandwidth for the eDMA TCD.
AnnaBridge 143:86740a56073b 583 *
AnnaBridge 143:86740a56073b 584 * Because the eDMA processes the minor loop, it continuously generates read/write sequences
AnnaBridge 143:86740a56073b 585 * until the minor count is exhausted. The bandwidth forces the eDMA to stall after the completion of
AnnaBridge 143:86740a56073b 586 * each read/write access to control the bus request bandwidth seen by the crossbar switch.
AnnaBridge 143:86740a56073b 587 * @param tcd A pointer to the TCD structure.
AnnaBridge 143:86740a56073b 588 * @param bandWidth A bandwidth setting, which can be one of the following:
AnnaBridge 143:86740a56073b 589 * @arg kEDMABandwidthStallNone
AnnaBridge 143:86740a56073b 590 * @arg kEDMABandwidthStall4Cycle
AnnaBridge 143:86740a56073b 591 * @arg kEDMABandwidthStall8Cycle
AnnaBridge 143:86740a56073b 592 */
AnnaBridge 143:86740a56073b 593 static inline void EDMA_TcdSetBandWidth(edma_tcd_t *tcd, edma_bandwidth_t bandWidth)
AnnaBridge 143:86740a56073b 594 {
AnnaBridge 143:86740a56073b 595 assert(tcd != NULL);
AnnaBridge 143:86740a56073b 596 assert(((uint32_t)tcd & 0x1FU) == 0);
AnnaBridge 143:86740a56073b 597
AnnaBridge 143:86740a56073b 598 tcd->CSR = (tcd->CSR & (~DMA_CSR_BWC_MASK)) | DMA_CSR_BWC(bandWidth);
AnnaBridge 143:86740a56073b 599 }
AnnaBridge 143:86740a56073b 600
AnnaBridge 143:86740a56073b 601 /*!
AnnaBridge 143:86740a56073b 602 * @brief Sets the source modulo and the destination modulo for the eDMA TCD.
AnnaBridge 143:86740a56073b 603 *
AnnaBridge 143:86740a56073b 604 * This function defines a specific address range specified to be the value after (SADDR + SOFF)/(DADDR + DOFF)
AnnaBridge 143:86740a56073b 605 * calculation is performed or the original register value. It provides the ability to implement a circular data
AnnaBridge 143:86740a56073b 606 * queue easily.
AnnaBridge 143:86740a56073b 607 *
AnnaBridge 143:86740a56073b 608 * @param tcd A pointer to the TCD structure.
AnnaBridge 143:86740a56073b 609 * @param srcModulo A source modulo value.
AnnaBridge 143:86740a56073b 610 * @param destModulo A destination modulo value.
AnnaBridge 143:86740a56073b 611 */
AnnaBridge 143:86740a56073b 612 void EDMA_TcdSetModulo(edma_tcd_t *tcd, edma_modulo_t srcModulo, edma_modulo_t destModulo);
AnnaBridge 143:86740a56073b 613
AnnaBridge 143:86740a56073b 614 /*!
AnnaBridge 143:86740a56073b 615 * @brief Sets the auto stop request for the eDMA TCD.
AnnaBridge 143:86740a56073b 616 *
AnnaBridge 143:86740a56073b 617 * If enabling the auto stop request, the eDMA hardware automatically disables the hardware channel request.
AnnaBridge 143:86740a56073b 618 *
AnnaBridge 143:86740a56073b 619 * @param tcd A pointer to the TCD structure.
AnnaBridge 143:86740a56073b 620 * @param enable The command to enable (true) or disable (false).
AnnaBridge 143:86740a56073b 621 */
AnnaBridge 143:86740a56073b 622 static inline void EDMA_TcdEnableAutoStopRequest(edma_tcd_t *tcd, bool enable)
AnnaBridge 143:86740a56073b 623 {
AnnaBridge 143:86740a56073b 624 assert(tcd != NULL);
AnnaBridge 143:86740a56073b 625 assert(((uint32_t)tcd & 0x1FU) == 0);
AnnaBridge 143:86740a56073b 626
AnnaBridge 143:86740a56073b 627 tcd->CSR = (tcd->CSR & (~DMA_CSR_DREQ_MASK)) | DMA_CSR_DREQ(enable);
AnnaBridge 143:86740a56073b 628 }
AnnaBridge 143:86740a56073b 629
AnnaBridge 143:86740a56073b 630 /*!
AnnaBridge 143:86740a56073b 631 * @brief Enables the interrupt source for the eDMA TCD.
AnnaBridge 143:86740a56073b 632 *
AnnaBridge 143:86740a56073b 633 * @param tcd Point to the TCD structure.
AnnaBridge 143:86740a56073b 634 * @param mask The mask of interrupt source to be set. Users need to use
AnnaBridge 143:86740a56073b 635 * the defined edma_interrupt_enable_t type.
AnnaBridge 143:86740a56073b 636 */
AnnaBridge 143:86740a56073b 637 void EDMA_TcdEnableInterrupts(edma_tcd_t *tcd, uint32_t mask);
AnnaBridge 143:86740a56073b 638
AnnaBridge 143:86740a56073b 639 /*!
AnnaBridge 143:86740a56073b 640 * @brief Disables the interrupt source for the eDMA TCD.
AnnaBridge 143:86740a56073b 641 *
AnnaBridge 143:86740a56073b 642 * @param tcd Point to the TCD structure.
AnnaBridge 143:86740a56073b 643 * @param mask The mask of interrupt source to be set. Users need to use
AnnaBridge 143:86740a56073b 644 * the defined edma_interrupt_enable_t type.
AnnaBridge 143:86740a56073b 645 */
AnnaBridge 143:86740a56073b 646 void EDMA_TcdDisableInterrupts(edma_tcd_t *tcd, uint32_t mask);
AnnaBridge 143:86740a56073b 647
AnnaBridge 143:86740a56073b 648 /*! @} */
AnnaBridge 143:86740a56073b 649 /*!
AnnaBridge 143:86740a56073b 650 * @name eDMA Channel Transfer Operation
AnnaBridge 143:86740a56073b 651 * @{
AnnaBridge 143:86740a56073b 652 */
AnnaBridge 143:86740a56073b 653
AnnaBridge 143:86740a56073b 654 /*!
AnnaBridge 143:86740a56073b 655 * @brief Enables the eDMA hardware channel request.
AnnaBridge 143:86740a56073b 656 *
AnnaBridge 143:86740a56073b 657 * This function enables the hardware channel request.
AnnaBridge 143:86740a56073b 658 *
AnnaBridge 143:86740a56073b 659 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 660 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 661 */
AnnaBridge 143:86740a56073b 662 static inline void EDMA_EnableChannelRequest(DMA_Type *base, uint32_t channel)
AnnaBridge 143:86740a56073b 663 {
AnnaBridge 143:86740a56073b 664 assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
AnnaBridge 143:86740a56073b 665
AnnaBridge 143:86740a56073b 666 base->SERQ = DMA_SERQ_SERQ(channel);
AnnaBridge 143:86740a56073b 667 }
AnnaBridge 143:86740a56073b 668
AnnaBridge 143:86740a56073b 669 /*!
AnnaBridge 143:86740a56073b 670 * @brief Disables the eDMA hardware channel request.
AnnaBridge 143:86740a56073b 671 *
AnnaBridge 143:86740a56073b 672 * This function disables the hardware channel request.
AnnaBridge 143:86740a56073b 673 *
AnnaBridge 143:86740a56073b 674 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 675 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 676 */
AnnaBridge 143:86740a56073b 677 static inline void EDMA_DisableChannelRequest(DMA_Type *base, uint32_t channel)
AnnaBridge 143:86740a56073b 678 {
AnnaBridge 143:86740a56073b 679 assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
AnnaBridge 143:86740a56073b 680
AnnaBridge 143:86740a56073b 681 base->CERQ = DMA_CERQ_CERQ(channel);
AnnaBridge 143:86740a56073b 682 }
AnnaBridge 143:86740a56073b 683
AnnaBridge 143:86740a56073b 684 /*!
AnnaBridge 143:86740a56073b 685 * @brief Starts the eDMA transfer by using the software trigger.
AnnaBridge 143:86740a56073b 686 *
AnnaBridge 143:86740a56073b 687 * This function starts a minor loop transfer.
AnnaBridge 143:86740a56073b 688 *
AnnaBridge 143:86740a56073b 689 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 690 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 691 */
AnnaBridge 143:86740a56073b 692 static inline void EDMA_TriggerChannelStart(DMA_Type *base, uint32_t channel)
AnnaBridge 143:86740a56073b 693 {
AnnaBridge 143:86740a56073b 694 assert(channel < FSL_FEATURE_DMAMUX_MODULE_CHANNEL);
AnnaBridge 143:86740a56073b 695
AnnaBridge 143:86740a56073b 696 base->SSRT = DMA_SSRT_SSRT(channel);
AnnaBridge 143:86740a56073b 697 }
AnnaBridge 143:86740a56073b 698
AnnaBridge 143:86740a56073b 699 /*! @} */
AnnaBridge 143:86740a56073b 700 /*!
AnnaBridge 143:86740a56073b 701 * @name eDMA Channel Status Operation
AnnaBridge 143:86740a56073b 702 * @{
AnnaBridge 143:86740a56073b 703 */
AnnaBridge 143:86740a56073b 704
AnnaBridge 143:86740a56073b 705 /*!
AnnaBridge 143:86740a56073b 706 * @brief Gets the remaining major loop count from the eDMA current channel TCD.
AnnaBridge 143:86740a56073b 707 *
AnnaBridge 143:86740a56073b 708 * This function checks the TCD (Task Control Descriptor) status for a specified
AnnaBridge 143:86740a56073b 709 * eDMA channel and returns the the number of major loop count that has not finished.
AnnaBridge 143:86740a56073b 710 *
AnnaBridge 143:86740a56073b 711 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 712 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 713 * @return Major loop count which has not been transferred yet for the current TCD.
AnnaBridge 143:86740a56073b 714 * @note 1. This function can only be used to get unfinished major loop count of transfer without
AnnaBridge 143:86740a56073b 715 * the next TCD, or it might be inaccuracy.
AnnaBridge 143:86740a56073b 716 * 2. The unfinished/remaining transfer bytes cannot be obtained directly from registers while
AnnaBridge 143:86740a56073b 717 * the channel is running.
AnnaBridge 143:86740a56073b 718 * Because to calculate the remaining bytes, the initial NBYTES configured in DMA_TCDn_NBYTES_MLNO
AnnaBridge 143:86740a56073b 719 * register is needed while the eDMA IP does not support getting it while a channel is active.
AnnaBridge 143:86740a56073b 720 * In another word, the NBYTES value reading is always the actual (decrementing) NBYTES value the dma_engine
AnnaBridge 143:86740a56073b 721 * is working with while a channel is running.
AnnaBridge 143:86740a56073b 722 * Consequently, to get the remaining transfer bytes, a software-saved initial value of NBYTES (for example
AnnaBridge 143:86740a56073b 723 * copied before enabling the channel) is needed. The formula to calculate it is shown below:
AnnaBridge 143:86740a56073b 724 * RemainingBytes = RemainingMajorLoopCount * NBYTES(initially configured)
AnnaBridge 143:86740a56073b 725 */
AnnaBridge 143:86740a56073b 726 uint32_t EDMA_GetRemainingMajorLoopCount(DMA_Type *base, uint32_t channel);
AnnaBridge 143:86740a56073b 727
AnnaBridge 143:86740a56073b 728 /*!
AnnaBridge 143:86740a56073b 729 * @brief Gets the eDMA channel error status flags.
AnnaBridge 143:86740a56073b 730 *
AnnaBridge 143:86740a56073b 731 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 732 * @return The mask of error status flags. Users need to use the
AnnaBridge 143:86740a56073b 733 * _edma_error_status_flags type to decode the return variables.
AnnaBridge 143:86740a56073b 734 */
AnnaBridge 143:86740a56073b 735 static inline uint32_t EDMA_GetErrorStatusFlags(DMA_Type *base)
AnnaBridge 143:86740a56073b 736 {
AnnaBridge 143:86740a56073b 737 return base->ES;
AnnaBridge 143:86740a56073b 738 }
AnnaBridge 143:86740a56073b 739
AnnaBridge 143:86740a56073b 740 /*!
AnnaBridge 143:86740a56073b 741 * @brief Gets the eDMA channel status flags.
AnnaBridge 143:86740a56073b 742 *
AnnaBridge 143:86740a56073b 743 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 744 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 745 * @return The mask of channel status flags. Users need to use the
AnnaBridge 143:86740a56073b 746 * _edma_channel_status_flags type to decode the return variables.
AnnaBridge 143:86740a56073b 747 */
AnnaBridge 143:86740a56073b 748 uint32_t EDMA_GetChannelStatusFlags(DMA_Type *base, uint32_t channel);
AnnaBridge 143:86740a56073b 749
AnnaBridge 143:86740a56073b 750 /*!
AnnaBridge 143:86740a56073b 751 * @brief Clears the eDMA channel status flags.
AnnaBridge 143:86740a56073b 752 *
AnnaBridge 143:86740a56073b 753 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 754 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 755 * @param mask The mask of channel status to be cleared. Users need to use
AnnaBridge 143:86740a56073b 756 * the defined _edma_channel_status_flags type.
AnnaBridge 143:86740a56073b 757 */
AnnaBridge 143:86740a56073b 758 void EDMA_ClearChannelStatusFlags(DMA_Type *base, uint32_t channel, uint32_t mask);
AnnaBridge 143:86740a56073b 759
AnnaBridge 143:86740a56073b 760 /*! @} */
AnnaBridge 143:86740a56073b 761 /*!
AnnaBridge 143:86740a56073b 762 * @name eDMA Transactional Operation
AnnaBridge 143:86740a56073b 763 */
AnnaBridge 143:86740a56073b 764
AnnaBridge 143:86740a56073b 765 /*!
AnnaBridge 143:86740a56073b 766 * @brief Creates the eDMA handle.
AnnaBridge 143:86740a56073b 767 *
AnnaBridge 143:86740a56073b 768 * This function is called if using the transactional API for eDMA. This function
AnnaBridge 143:86740a56073b 769 * initializes the internal state of the eDMA handle.
AnnaBridge 143:86740a56073b 770 *
AnnaBridge 143:86740a56073b 771 * @param handle eDMA handle pointer. The eDMA handle stores callback function and
AnnaBridge 143:86740a56073b 772 * parameters.
AnnaBridge 143:86740a56073b 773 * @param base eDMA peripheral base address.
AnnaBridge 143:86740a56073b 774 * @param channel eDMA channel number.
AnnaBridge 143:86740a56073b 775 */
AnnaBridge 143:86740a56073b 776 void EDMA_CreateHandle(edma_handle_t *handle, DMA_Type *base, uint32_t channel);
AnnaBridge 143:86740a56073b 777
AnnaBridge 143:86740a56073b 778 /*!
AnnaBridge 143:86740a56073b 779 * @brief Installs the TCDs memory pool into the eDMA handle.
AnnaBridge 143:86740a56073b 780 *
AnnaBridge 143:86740a56073b 781 * This function is called after the EDMA_CreateHandle to use scatter/gather feature.
AnnaBridge 143:86740a56073b 782 *
AnnaBridge 143:86740a56073b 783 * @param handle eDMA handle pointer.
AnnaBridge 143:86740a56073b 784 * @param tcdPool A memory pool to store TCDs. It must be 32 bytes aligned.
AnnaBridge 143:86740a56073b 785 * @param tcdSize The number of TCD slots.
AnnaBridge 143:86740a56073b 786 */
AnnaBridge 143:86740a56073b 787 void EDMA_InstallTCDMemory(edma_handle_t *handle, edma_tcd_t *tcdPool, uint32_t tcdSize);
AnnaBridge 143:86740a56073b 788
AnnaBridge 143:86740a56073b 789 /*!
AnnaBridge 143:86740a56073b 790 * @brief Installs a callback function for the eDMA transfer.
AnnaBridge 143:86740a56073b 791 *
AnnaBridge 143:86740a56073b 792 * This callback is called in the eDMA IRQ handler. Use the callback to do something after
AnnaBridge 143:86740a56073b 793 * the current major loop transfer completes.
AnnaBridge 143:86740a56073b 794 *
AnnaBridge 143:86740a56073b 795 * @param handle eDMA handle pointer.
AnnaBridge 143:86740a56073b 796 * @param callback eDMA callback function pointer.
AnnaBridge 143:86740a56073b 797 * @param userData A parameter for the callback function.
AnnaBridge 143:86740a56073b 798 */
AnnaBridge 143:86740a56073b 799 void EDMA_SetCallback(edma_handle_t *handle, edma_callback callback, void *userData);
AnnaBridge 143:86740a56073b 800
AnnaBridge 143:86740a56073b 801 /*!
AnnaBridge 143:86740a56073b 802 * @brief Prepares the eDMA transfer structure.
AnnaBridge 143:86740a56073b 803 *
AnnaBridge 143:86740a56073b 804 * This function prepares the transfer configuration structure according to the user input.
AnnaBridge 143:86740a56073b 805 *
AnnaBridge 143:86740a56073b 806 * @param config The user configuration structure of type edma_transfer_t.
AnnaBridge 143:86740a56073b 807 * @param srcAddr eDMA transfer source address.
AnnaBridge 143:86740a56073b 808 * @param srcWidth eDMA transfer source address width(bytes).
AnnaBridge 143:86740a56073b 809 * @param destAddr eDMA transfer destination address.
AnnaBridge 143:86740a56073b 810 * @param destWidth eDMA transfer destination address width(bytes).
AnnaBridge 143:86740a56073b 811 * @param bytesEachRequest eDMA transfer bytes per channel request.
AnnaBridge 143:86740a56073b 812 * @param transferBytes eDMA transfer bytes to be transferred.
AnnaBridge 143:86740a56073b 813 * @param type eDMA transfer type.
AnnaBridge 143:86740a56073b 814 * @note The data address and the data width must be consistent. For example, if the SRC
AnnaBridge 143:86740a56073b 815 * is 4 bytes, the source address must be 4 bytes aligned, or it results in
AnnaBridge 143:86740a56073b 816 * source address error (SAE).
AnnaBridge 143:86740a56073b 817 */
AnnaBridge 143:86740a56073b 818 void EDMA_PrepareTransfer(edma_transfer_config_t *config,
AnnaBridge 143:86740a56073b 819 void *srcAddr,
AnnaBridge 143:86740a56073b 820 uint32_t srcWidth,
AnnaBridge 143:86740a56073b 821 void *destAddr,
AnnaBridge 143:86740a56073b 822 uint32_t destWidth,
AnnaBridge 143:86740a56073b 823 uint32_t bytesEachRequest,
AnnaBridge 143:86740a56073b 824 uint32_t transferBytes,
AnnaBridge 143:86740a56073b 825 edma_transfer_type_t type);
AnnaBridge 143:86740a56073b 826
AnnaBridge 143:86740a56073b 827 /*!
AnnaBridge 143:86740a56073b 828 * @brief Submits the eDMA transfer request.
AnnaBridge 143:86740a56073b 829 *
AnnaBridge 143:86740a56073b 830 * This function submits the eDMA transfer request according to the transfer configuration structure.
AnnaBridge 143:86740a56073b 831 * If submitting the transfer request repeatedly, this function packs an unprocessed request as
AnnaBridge 143:86740a56073b 832 * a TCD and enables scatter/gather feature to process it in the next time.
AnnaBridge 143:86740a56073b 833 *
AnnaBridge 143:86740a56073b 834 * @param handle eDMA handle pointer.
AnnaBridge 143:86740a56073b 835 * @param config Pointer to eDMA transfer configuration structure.
AnnaBridge 143:86740a56073b 836 * @retval kStatus_EDMA_Success It means submit transfer request succeed.
AnnaBridge 143:86740a56073b 837 * @retval kStatus_EDMA_QueueFull It means TCD queue is full. Submit transfer request is not allowed.
AnnaBridge 143:86740a56073b 838 * @retval kStatus_EDMA_Busy It means the given channel is busy, need to submit request later.
AnnaBridge 143:86740a56073b 839 */
AnnaBridge 143:86740a56073b 840 status_t EDMA_SubmitTransfer(edma_handle_t *handle, const edma_transfer_config_t *config);
AnnaBridge 143:86740a56073b 841
AnnaBridge 143:86740a56073b 842 /*!
AnnaBridge 143:86740a56073b 843 * @brief eDMA starts transfer.
AnnaBridge 143:86740a56073b 844 *
AnnaBridge 143:86740a56073b 845 * This function enables the channel request. Users can call this function after submitting the transfer request
AnnaBridge 143:86740a56073b 846 * or before submitting the transfer request.
AnnaBridge 143:86740a56073b 847 *
AnnaBridge 143:86740a56073b 848 * @param handle eDMA handle pointer.
AnnaBridge 143:86740a56073b 849 */
AnnaBridge 143:86740a56073b 850 void EDMA_StartTransfer(edma_handle_t *handle);
AnnaBridge 143:86740a56073b 851
AnnaBridge 143:86740a56073b 852 /*!
AnnaBridge 143:86740a56073b 853 * @brief eDMA stops transfer.
AnnaBridge 143:86740a56073b 854 *
AnnaBridge 143:86740a56073b 855 * This function disables the channel request to pause the transfer. Users can call EDMA_StartTransfer()
AnnaBridge 143:86740a56073b 856 * again to resume the transfer.
AnnaBridge 143:86740a56073b 857 *
AnnaBridge 143:86740a56073b 858 * @param handle eDMA handle pointer.
AnnaBridge 143:86740a56073b 859 */
AnnaBridge 143:86740a56073b 860 void EDMA_StopTransfer(edma_handle_t *handle);
AnnaBridge 143:86740a56073b 861
AnnaBridge 143:86740a56073b 862 /*!
AnnaBridge 143:86740a56073b 863 * @brief eDMA aborts transfer.
AnnaBridge 143:86740a56073b 864 *
AnnaBridge 143:86740a56073b 865 * This function disables the channel request and clear transfer status bits.
AnnaBridge 143:86740a56073b 866 * Users can submit another transfer after calling this API.
AnnaBridge 143:86740a56073b 867 *
AnnaBridge 143:86740a56073b 868 * @param handle DMA handle pointer.
AnnaBridge 143:86740a56073b 869 */
AnnaBridge 143:86740a56073b 870 void EDMA_AbortTransfer(edma_handle_t *handle);
AnnaBridge 143:86740a56073b 871
AnnaBridge 143:86740a56073b 872 /*!
AnnaBridge 143:86740a56073b 873 * @brief eDMA IRQ handler for the current major loop transfer completion.
AnnaBridge 143:86740a56073b 874 *
AnnaBridge 143:86740a56073b 875 * This function clears the channel major interrupt flag and calls
AnnaBridge 143:86740a56073b 876 * the callback function if it is not NULL.
AnnaBridge 143:86740a56073b 877 *
AnnaBridge 143:86740a56073b 878 * Note:
AnnaBridge 143:86740a56073b 879 * For the case using TCD queue, when the major iteration count is exhausted, additional operations are performed.
AnnaBridge 143:86740a56073b 880 * These include the final address adjustments and reloading of the BITER field into the CITER.
AnnaBridge 143:86740a56073b 881 * Assertion of an optional interrupt request also occurs at this time, as does a possible fetch of a new TCD from
AnnaBridge 143:86740a56073b 882 * memory using the scatter/gather address pointer included in the descriptor (if scatter/gather is enabled).
AnnaBridge 143:86740a56073b 883 *
AnnaBridge 143:86740a56073b 884 * For instance, when the time interrupt of TCD[0] happens, the TCD[1] has already been loaded into the eDMA engine.
AnnaBridge 143:86740a56073b 885 * As sga and sga_index are calculated based on the DLAST_SGA bitfield lies in the TCD_CSR register, the sga_index
AnnaBridge 143:86740a56073b 886 * in this case should be 2 (DLAST_SGA of TCD[1] stores the address of TCD[2]). Thus, the "tcdUsed" updated should be
AnnaBridge 143:86740a56073b 887 * (tcdUsed - 2U) which indicates the number of TCDs can be loaded in the memory pool (because TCD[0] and TCD[1] have
AnnaBridge 143:86740a56073b 888 * been loaded into the eDMA engine at this point already.).
AnnaBridge 143:86740a56073b 889 *
AnnaBridge 143:86740a56073b 890 * For the last two continuous ISRs in a scatter/gather process, they both load the last TCD (The last ISR does not
AnnaBridge 143:86740a56073b 891 * load a new TCD) from the memory pool to the eDMA engine when major loop completes.
AnnaBridge 143:86740a56073b 892 * Therefore, ensure that the header and tcdUsed updated are identical for them.
AnnaBridge 143:86740a56073b 893 * tcdUsed are both 0 in this case as no TCD to be loaded.
AnnaBridge 143:86740a56073b 894 *
AnnaBridge 143:86740a56073b 895 * See the "eDMA basic data flow" in the eDMA Functional description section of the Reference Manual for
AnnaBridge 143:86740a56073b 896 * further details.
AnnaBridge 143:86740a56073b 897 *
AnnaBridge 143:86740a56073b 898 * @param handle eDMA handle pointer.
AnnaBridge 143:86740a56073b 899 */
AnnaBridge 143:86740a56073b 900 void EDMA_HandleIRQ(edma_handle_t *handle);
AnnaBridge 143:86740a56073b 901
AnnaBridge 143:86740a56073b 902 /* @} */
AnnaBridge 143:86740a56073b 903
AnnaBridge 143:86740a56073b 904 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 905 }
AnnaBridge 143:86740a56073b 906 #endif /* __cplusplus */
AnnaBridge 143:86740a56073b 907
AnnaBridge 143:86740a56073b 908 /* @} */
AnnaBridge 143:86740a56073b 909
AnnaBridge 143:86740a56073b 910 #endif /*_FSL_EDMA_H_*/