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:
Kojto
Date:
Tue Feb 14 11:24:20 2017 +0000
Revision:
136:ef9c61f8c49f
Parent:
128:9bcdf88f62b0
Child:
139:856d2700e60b
Release 136 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

3432: Target STM USBHOST support https://github.com/ARMmbed/mbed-os/pull/3432
3181: NUCLEO_F207ZG extending PeripheralPins.c: all available alternate functions can be used now https://github.com/ARMmbed/mbed-os/pull/3181
3626: NUCLEO_F412ZG : Add USB Device +Host https://github.com/ARMmbed/mbed-os/pull/3626
3628: Fix warnings https://github.com/ARMmbed/mbed-os/pull/3628
3629: STM32: L0 LL layer https://github.com/ARMmbed/mbed-os/pull/3629
3632: IDE Export support for platform VK_RZ_A1H https://github.com/ARMmbed/mbed-os/pull/3632
3642: Missing IRQ pin fix for platform VK_RZ_A1H https://github.com/ARMmbed/mbed-os/pull/3642
3664: Fix ncs36510 sleep definitions https://github.com/ARMmbed/mbed-os/pull/3664
3655: [STM32F4] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3655
3657: [STM32L4] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3657
3658: [STM32F3] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3658
3685: STM32: I2C: reset state machine https://github.com/ARMmbed/mbed-os/pull/3685
3692: uVisor: Standardize available legacy heap and stack https://github.com/ARMmbed/mbed-os/pull/3692
3621: Fix for #2884, LPC824: export to LPCXpresso, target running with wron https://github.com/ARMmbed/mbed-os/pull/3621
3649: [STM32F7] Modify folder structure https://github.com/ARMmbed/mbed-os/pull/3649
3695: Enforce device_name is valid in targets.json https://github.com/ARMmbed/mbed-os/pull/3695
3723: NCS36510: spi_format function bug fix https://github.com/ARMmbed/mbed-os/pull/3723

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 98:8ab26030e058 1 /***************************************************************************//**
Kojto 98:8ab26030e058 2 * @file em_dma.h
Kojto 98:8ab26030e058 3 * @brief Direct memory access (DMA) API
<> 128:9bcdf88f62b0 4 * @version 5.0.0
Kojto 98:8ab26030e058 5 *******************************************************************************
Kojto 98:8ab26030e058 6 * @section License
<> 128:9bcdf88f62b0 7 * <b>Copyright 2016 Silicon Laboratories, Inc. http://www.silabs.com</b>
Kojto 98:8ab26030e058 8 *******************************************************************************
Kojto 98:8ab26030e058 9 *
Kojto 98:8ab26030e058 10 * Permission is granted to anyone to use this software for any purpose,
Kojto 98:8ab26030e058 11 * including commercial applications, and to alter it and redistribute it
Kojto 98:8ab26030e058 12 * freely, subject to the following restrictions:
Kojto 98:8ab26030e058 13 *
Kojto 98:8ab26030e058 14 * 1. The origin of this software must not be misrepresented; you must not
Kojto 98:8ab26030e058 15 * claim that you wrote the original software.
Kojto 98:8ab26030e058 16 * 2. Altered source versions must be plainly marked as such, and must not be
Kojto 98:8ab26030e058 17 * misrepresented as being the original software.
Kojto 98:8ab26030e058 18 * 3. This notice may not be removed or altered from any source distribution.
Kojto 98:8ab26030e058 19 *
Kojto 98:8ab26030e058 20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
Kojto 98:8ab26030e058 21 * obligation to support this Software. Silicon Labs is providing the
Kojto 98:8ab26030e058 22 * Software "AS IS", with no express or implied warranties of any kind,
Kojto 98:8ab26030e058 23 * including, but not limited to, any implied warranties of merchantability
Kojto 98:8ab26030e058 24 * or fitness for any particular purpose or warranties against infringement
Kojto 98:8ab26030e058 25 * of any proprietary rights of a third party.
Kojto 98:8ab26030e058 26 *
Kojto 98:8ab26030e058 27 * Silicon Labs will not be liable for any consequential, incidental, or
Kojto 98:8ab26030e058 28 * special damages, or any other relief, or for any claim by any third party,
Kojto 98:8ab26030e058 29 * arising from your use of this Software.
Kojto 98:8ab26030e058 30 *
Kojto 98:8ab26030e058 31 ******************************************************************************/
Kojto 98:8ab26030e058 32
<> 128:9bcdf88f62b0 33 #ifndef EM_DMA_H
<> 128:9bcdf88f62b0 34 #define EM_DMA_H
Kojto 98:8ab26030e058 35
Kojto 98:8ab26030e058 36 #include "em_device.h"
Kojto 98:8ab26030e058 37 #if defined( DMA_PRESENT )
Kojto 98:8ab26030e058 38
Kojto 98:8ab26030e058 39 #include <stdio.h>
Kojto 98:8ab26030e058 40 #include <stdbool.h>
Kojto 98:8ab26030e058 41
Kojto 98:8ab26030e058 42 #ifdef __cplusplus
Kojto 98:8ab26030e058 43 extern "C" {
Kojto 98:8ab26030e058 44 #endif
Kojto 98:8ab26030e058 45
Kojto 98:8ab26030e058 46 /***************************************************************************//**
<> 128:9bcdf88f62b0 47 * @addtogroup emlib
Kojto 98:8ab26030e058 48 * @{
Kojto 98:8ab26030e058 49 ******************************************************************************/
Kojto 98:8ab26030e058 50
Kojto 98:8ab26030e058 51 /***************************************************************************//**
Kojto 98:8ab26030e058 52 * @addtogroup DMA
Kojto 98:8ab26030e058 53 * @{
Kojto 98:8ab26030e058 54 ******************************************************************************/
Kojto 98:8ab26030e058 55
Kojto 98:8ab26030e058 56 /*******************************************************************************
Kojto 98:8ab26030e058 57 ******************************** ENUMS ************************************
Kojto 98:8ab26030e058 58 ******************************************************************************/
Kojto 98:8ab26030e058 59
Kojto 98:8ab26030e058 60 /**
Kojto 98:8ab26030e058 61 * Amount source/destination address should be incremented for each data
Kojto 98:8ab26030e058 62 * transfer.
Kojto 98:8ab26030e058 63 */
Kojto 98:8ab26030e058 64 typedef enum
Kojto 98:8ab26030e058 65 {
Kojto 98:8ab26030e058 66 dmaDataInc1 = _DMA_CTRL_SRC_INC_BYTE, /**< Increment address 1 byte. */
Kojto 98:8ab26030e058 67 dmaDataInc2 = _DMA_CTRL_SRC_INC_HALFWORD, /**< Increment address 2 bytes. */
Kojto 98:8ab26030e058 68 dmaDataInc4 = _DMA_CTRL_SRC_INC_WORD, /**< Increment address 4 bytes. */
Kojto 98:8ab26030e058 69 dmaDataIncNone = _DMA_CTRL_SRC_INC_NONE /**< Do not increment address. */
Kojto 98:8ab26030e058 70 } DMA_DataInc_TypeDef;
Kojto 98:8ab26030e058 71
Kojto 98:8ab26030e058 72
Kojto 98:8ab26030e058 73 /** Data sizes (in number of bytes) to be read/written by DMA transfer. */
Kojto 98:8ab26030e058 74 typedef enum
Kojto 98:8ab26030e058 75 {
Kojto 98:8ab26030e058 76 dmaDataSize1 = _DMA_CTRL_SRC_SIZE_BYTE, /**< 1 byte DMA transfer size. */
Kojto 98:8ab26030e058 77 dmaDataSize2 = _DMA_CTRL_SRC_SIZE_HALFWORD, /**< 2 byte DMA transfer size. */
Kojto 98:8ab26030e058 78 dmaDataSize4 = _DMA_CTRL_SRC_SIZE_WORD /**< 4 byte DMA transfer size. */
Kojto 98:8ab26030e058 79 } DMA_DataSize_TypeDef;
Kojto 98:8ab26030e058 80
Kojto 98:8ab26030e058 81
Kojto 98:8ab26030e058 82 /** Type of DMA transfer. */
Kojto 98:8ab26030e058 83 typedef enum
Kojto 98:8ab26030e058 84 {
Kojto 98:8ab26030e058 85 /** Basic DMA cycle. */
Kojto 98:8ab26030e058 86 dmaCycleCtrlBasic = _DMA_CTRL_CYCLE_CTRL_BASIC,
Kojto 98:8ab26030e058 87 /** Auto-request DMA cycle. */
Kojto 98:8ab26030e058 88 dmaCycleCtrlAuto = _DMA_CTRL_CYCLE_CTRL_AUTO,
Kojto 98:8ab26030e058 89 /** Ping-pong DMA cycle. */
Kojto 98:8ab26030e058 90 dmaCycleCtrlPingPong = _DMA_CTRL_CYCLE_CTRL_PINGPONG,
Kojto 98:8ab26030e058 91 /** Memory scatter-gather DMA cycle. */
Kojto 98:8ab26030e058 92 dmaCycleCtrlMemScatterGather = _DMA_CTRL_CYCLE_CTRL_MEM_SCATTER_GATHER,
Kojto 98:8ab26030e058 93 /** Peripheral scatter-gather DMA cycle. */
Kojto 98:8ab26030e058 94 dmaCycleCtrlPerScatterGather = _DMA_CTRL_CYCLE_CTRL_PER_SCATTER_GATHER
Kojto 98:8ab26030e058 95 } DMA_CycleCtrl_TypeDef;
Kojto 98:8ab26030e058 96
Kojto 98:8ab26030e058 97
Kojto 98:8ab26030e058 98 /** Number of transfers before controller does new arbitration. */
Kojto 98:8ab26030e058 99 typedef enum
Kojto 98:8ab26030e058 100 {
Kojto 98:8ab26030e058 101 dmaArbitrate1 = _DMA_CTRL_R_POWER_1, /**< Arbitrate after 1 DMA transfer. */
Kojto 98:8ab26030e058 102 dmaArbitrate2 = _DMA_CTRL_R_POWER_2, /**< Arbitrate after 2 DMA transfers. */
Kojto 98:8ab26030e058 103 dmaArbitrate4 = _DMA_CTRL_R_POWER_4, /**< Arbitrate after 4 DMA transfers. */
Kojto 98:8ab26030e058 104 dmaArbitrate8 = _DMA_CTRL_R_POWER_8, /**< Arbitrate after 8 DMA transfers. */
Kojto 98:8ab26030e058 105 dmaArbitrate16 = _DMA_CTRL_R_POWER_16, /**< Arbitrate after 16 DMA transfers. */
Kojto 98:8ab26030e058 106 dmaArbitrate32 = _DMA_CTRL_R_POWER_32, /**< Arbitrate after 32 DMA transfers. */
Kojto 98:8ab26030e058 107 dmaArbitrate64 = _DMA_CTRL_R_POWER_64, /**< Arbitrate after 64 DMA transfers. */
Kojto 98:8ab26030e058 108 dmaArbitrate128 = _DMA_CTRL_R_POWER_128, /**< Arbitrate after 128 DMA transfers. */
Kojto 98:8ab26030e058 109 dmaArbitrate256 = _DMA_CTRL_R_POWER_256, /**< Arbitrate after 256 DMA transfers. */
Kojto 98:8ab26030e058 110 dmaArbitrate512 = _DMA_CTRL_R_POWER_512, /**< Arbitrate after 512 DMA transfers. */
Kojto 98:8ab26030e058 111 dmaArbitrate1024 = _DMA_CTRL_R_POWER_1024 /**< Arbitrate after 1024 DMA transfers. */
Kojto 98:8ab26030e058 112 } DMA_ArbiterConfig_TypeDef;
Kojto 98:8ab26030e058 113
Kojto 98:8ab26030e058 114
Kojto 98:8ab26030e058 115 /*******************************************************************************
Kojto 98:8ab26030e058 116 ******************************* STRUCTS ***********************************
Kojto 98:8ab26030e058 117 ******************************************************************************/
Kojto 98:8ab26030e058 118
Kojto 98:8ab26030e058 119 /**
Kojto 98:8ab26030e058 120 * @brief
Kojto 98:8ab26030e058 121 * DMA interrupt callback function pointer.
Kojto 98:8ab26030e058 122 * @details
Kojto 98:8ab26030e058 123 * Parameters:
Kojto 98:8ab26030e058 124 * @li channel - The DMA channel the callback function is invoked for.
Kojto 98:8ab26030e058 125 * @li primary - Indicates if callback is invoked for completion of primary
Kojto 98:8ab26030e058 126 * (true) or alternate (false) descriptor. This is mainly useful for
Kojto 98:8ab26030e058 127 * ping-pong DMA cycles, in order to know which descriptor to refresh.
Kojto 98:8ab26030e058 128 * @li user - User definable reference that may be used to pass information
Kojto 98:8ab26030e058 129 * to be used by the callback handler. If used, the referenced data must be
Kojto 98:8ab26030e058 130 * valid at the point when the interrupt handler invokes the callback.
Kojto 98:8ab26030e058 131 * If callback changes any data in the provided user structure, remember
Kojto 98:8ab26030e058 132 * that those changes are done in interrupt context, and proper protection
Kojto 98:8ab26030e058 133 * of data may be required.
Kojto 98:8ab26030e058 134 */
Kojto 98:8ab26030e058 135 typedef void (*DMA_FuncPtr_TypeDef)(unsigned int channel, bool primary, void *user);
Kojto 98:8ab26030e058 136
Kojto 98:8ab26030e058 137
Kojto 98:8ab26030e058 138 /**
Kojto 98:8ab26030e058 139 * @brief
Kojto 98:8ab26030e058 140 * Callback structure that can be used to define DMA complete actions.
Kojto 98:8ab26030e058 141 * @details
Kojto 98:8ab26030e058 142 * A reference to this structure is only stored in the primary descriptor
Kojto 98:8ab26030e058 143 * for a channel (if callback feature is used). If callback is required
Kojto 98:8ab26030e058 144 * for both primary and alternate descriptor completion, this must be
Kojto 98:8ab26030e058 145 * handled by one common callback, using the provided 'primary' parameter
Kojto 98:8ab26030e058 146 * with the callback function.
Kojto 98:8ab26030e058 147 */
Kojto 98:8ab26030e058 148 typedef struct
Kojto 98:8ab26030e058 149 {
Kojto 98:8ab26030e058 150 /**
Kojto 98:8ab26030e058 151 * Pointer to callback function to invoke when DMA transfer cycle done.
Kojto 98:8ab26030e058 152 * Notice that this function is invoked in interrupt context, and therefore
Kojto 98:8ab26030e058 153 * should be short and non-blocking.
Kojto 98:8ab26030e058 154 */
Kojto 98:8ab26030e058 155 DMA_FuncPtr_TypeDef cbFunc;
Kojto 98:8ab26030e058 156
Kojto 98:8ab26030e058 157 /** User defined pointer to provide with callback function. */
Kojto 98:8ab26030e058 158 void *userPtr;
Kojto 98:8ab26030e058 159
Kojto 98:8ab26030e058 160 /**
Kojto 98:8ab26030e058 161 * For internal use only: Indicates if next callback applies to primary
Kojto 98:8ab26030e058 162 * or alternate descriptor completion. Mainly useful for ping-pong DMA
Kojto 98:8ab26030e058 163 * cycles. Set this value to 0 prior to configuring callback handling.
Kojto 98:8ab26030e058 164 */
Kojto 98:8ab26030e058 165 uint8_t primary;
Kojto 98:8ab26030e058 166 } DMA_CB_TypeDef;
Kojto 98:8ab26030e058 167
Kojto 98:8ab26030e058 168
Kojto 98:8ab26030e058 169 /** Configuration structure for a channel. */
Kojto 98:8ab26030e058 170 typedef struct
Kojto 98:8ab26030e058 171 {
Kojto 98:8ab26030e058 172 /**
Kojto 98:8ab26030e058 173 * Select if channel priority is in the high or default priority group
Kojto 98:8ab26030e058 174 * with respect to arbitration. Within a priority group, lower numbered
Kojto 98:8ab26030e058 175 * channels have higher priority than higher numbered channels.
Kojto 98:8ab26030e058 176 */
Kojto 98:8ab26030e058 177 bool highPri;
Kojto 98:8ab26030e058 178
Kojto 98:8ab26030e058 179 /**
Kojto 98:8ab26030e058 180 * Select if interrupt shall be enabled for channel (triggering interrupt
Kojto 98:8ab26030e058 181 * handler when dma_done signal is asserted). It should normally be
Kojto 98:8ab26030e058 182 * enabled if using the callback feature for a channel, and disabled if
Kojto 98:8ab26030e058 183 * not using the callback feature.
Kojto 98:8ab26030e058 184 */
Kojto 98:8ab26030e058 185 bool enableInt;
Kojto 98:8ab26030e058 186
Kojto 98:8ab26030e058 187 /**
Kojto 98:8ab26030e058 188 * Channel control specifying the source of DMA signals. If accessing
Kojto 98:8ab26030e058 189 * peripherals, use one of the DMAREQ_nnn defines available for the
Kojto 98:8ab26030e058 190 * peripheral. Set it to 0 for memory-to-memory DMA cycles.
Kojto 98:8ab26030e058 191 */
Kojto 98:8ab26030e058 192 uint32_t select;
Kojto 98:8ab26030e058 193
Kojto 98:8ab26030e058 194 /**
Kojto 98:8ab26030e058 195 * @brief
Kojto 98:8ab26030e058 196 * User definable callback handling configuration.
Kojto 98:8ab26030e058 197 * @details
Kojto 98:8ab26030e058 198 * Please refer to structure definition for details. The callback
Kojto 98:8ab26030e058 199 * is invoked when the specified DMA cycle is complete (when dma_done
Kojto 98:8ab26030e058 200 * signal asserted). The callback is invoked in interrupt context,
Kojto 98:8ab26030e058 201 * and should be efficient and non-blocking. Set to NULL to not
Kojto 98:8ab26030e058 202 * use the callback feature.
Kojto 98:8ab26030e058 203 * @note
Kojto 98:8ab26030e058 204 * The referenced structure is used by the interrupt handler, and must
Kojto 98:8ab26030e058 205 * be available until no longer used. Thus, in most cases it should
Kojto 98:8ab26030e058 206 * not be located on the stack.
Kojto 98:8ab26030e058 207 */
Kojto 98:8ab26030e058 208 DMA_CB_TypeDef *cb;
Kojto 98:8ab26030e058 209 } DMA_CfgChannel_TypeDef;
Kojto 98:8ab26030e058 210
Kojto 98:8ab26030e058 211
Kojto 98:8ab26030e058 212 /**
Kojto 98:8ab26030e058 213 * Configuration structure for primary or alternate descriptor
Kojto 98:8ab26030e058 214 * (not used for scatter-gather DMA cycles).
Kojto 98:8ab26030e058 215 */
Kojto 98:8ab26030e058 216 typedef struct
Kojto 98:8ab26030e058 217 {
Kojto 98:8ab26030e058 218 /** Destination increment size for each DMA transfer */
Kojto 98:8ab26030e058 219 DMA_DataInc_TypeDef dstInc;
Kojto 98:8ab26030e058 220
Kojto 98:8ab26030e058 221 /** Source increment size for each DMA transfer */
Kojto 98:8ab26030e058 222 DMA_DataInc_TypeDef srcInc;
Kojto 98:8ab26030e058 223
Kojto 98:8ab26030e058 224 /** DMA transfer unit size. */
Kojto 98:8ab26030e058 225 DMA_DataSize_TypeDef size;
Kojto 98:8ab26030e058 226
Kojto 98:8ab26030e058 227 /**
Kojto 98:8ab26030e058 228 * Arbitration rate, ie number of DMA transfers done before rearbitration
Kojto 98:8ab26030e058 229 * takes place.
Kojto 98:8ab26030e058 230 */
Kojto 98:8ab26030e058 231 DMA_ArbiterConfig_TypeDef arbRate;
Kojto 98:8ab26030e058 232
Kojto 98:8ab26030e058 233 /**
Kojto 98:8ab26030e058 234 * HPROT signal state, please refer to reference manual, DMA chapter for
Kojto 98:8ab26030e058 235 * further details. Normally set to 0 if protection is not an issue.
Kojto 98:8ab26030e058 236 * The following bits are available:
Kojto 98:8ab26030e058 237 * @li bit 0 - HPROT[1] control for source read accesses,
Kojto 98:8ab26030e058 238 * privileged/non-privileged access
Kojto 98:8ab26030e058 239 * @li bit 3 - HPROT[1] control for destination write accesses,
Kojto 98:8ab26030e058 240 * privileged/non-privileged access
Kojto 98:8ab26030e058 241 */
Kojto 98:8ab26030e058 242 uint8_t hprot;
Kojto 98:8ab26030e058 243 } DMA_CfgDescr_TypeDef;
Kojto 98:8ab26030e058 244
Kojto 98:8ab26030e058 245
Kojto 98:8ab26030e058 246 #if defined( _DMA_LOOP0_MASK ) && defined( _DMA_LOOP1_MASK )
Kojto 98:8ab26030e058 247 /**
Kojto 98:8ab26030e058 248 * Configuration structure for loop mode
Kojto 98:8ab26030e058 249 */
Kojto 98:8ab26030e058 250 typedef struct
Kojto 98:8ab26030e058 251 {
Kojto 98:8ab26030e058 252 /** Enable repeated loop */
Kojto 98:8ab26030e058 253 bool enable;
Kojto 98:8ab26030e058 254 /** Width of transfer, reload value for nMinus1 */
Kojto 98:8ab26030e058 255 uint16_t nMinus1;
Kojto 98:8ab26030e058 256 } DMA_CfgLoop_TypeDef;
Kojto 98:8ab26030e058 257 #endif
Kojto 98:8ab26030e058 258
Kojto 98:8ab26030e058 259
Kojto 98:8ab26030e058 260 #if defined( _DMA_RECT0_MASK )
Kojto 98:8ab26030e058 261 /**
Kojto 98:8ab26030e058 262 * Configuration structure for rectangular copy
Kojto 98:8ab26030e058 263 */
Kojto 98:8ab26030e058 264 typedef struct
Kojto 98:8ab26030e058 265 {
Kojto 98:8ab26030e058 266 /** DMA channel destination stride (width of destination image, distance between lines) */
Kojto 98:8ab26030e058 267 uint16_t dstStride;
Kojto 98:8ab26030e058 268 /** DMA channel source stride (width of source image, distance between lines) */
Kojto 98:8ab26030e058 269 uint16_t srcStride;
Kojto 98:8ab26030e058 270 /** 2D copy height */
Kojto 98:8ab26030e058 271 uint16_t height;
Kojto 98:8ab26030e058 272 } DMA_CfgRect_TypeDef;
Kojto 98:8ab26030e058 273 #endif
Kojto 98:8ab26030e058 274
Kojto 98:8ab26030e058 275
Kojto 98:8ab26030e058 276 /** Configuration structure for alternate scatter-gather descriptor. */
Kojto 98:8ab26030e058 277 typedef struct
Kojto 98:8ab26030e058 278 {
Kojto 98:8ab26030e058 279 /** Pointer to location to transfer data from. */
Kojto 98:8ab26030e058 280 void *src;
Kojto 98:8ab26030e058 281
Kojto 98:8ab26030e058 282 /** Pointer to location to transfer data to. */
Kojto 98:8ab26030e058 283 void *dst;
Kojto 98:8ab26030e058 284
Kojto 98:8ab26030e058 285 /** Destination increment size for each DMA transfer */
Kojto 98:8ab26030e058 286 DMA_DataInc_TypeDef dstInc;
Kojto 98:8ab26030e058 287
Kojto 98:8ab26030e058 288 /** Source increment size for each DMA transfer */
Kojto 98:8ab26030e058 289 DMA_DataInc_TypeDef srcInc;
Kojto 98:8ab26030e058 290
Kojto 98:8ab26030e058 291 /** DMA transfer unit size. */
Kojto 98:8ab26030e058 292 DMA_DataSize_TypeDef size;
Kojto 98:8ab26030e058 293
Kojto 98:8ab26030e058 294 /**
Kojto 98:8ab26030e058 295 * Arbitration rate, ie number of DMA transfers done before rearbitration
Kojto 98:8ab26030e058 296 * takes place.
Kojto 98:8ab26030e058 297 */
Kojto 98:8ab26030e058 298 DMA_ArbiterConfig_TypeDef arbRate;
Kojto 98:8ab26030e058 299
Kojto 98:8ab26030e058 300 /** Number of DMA transfers minus 1 to do. Must be <= 1023. */
Kojto 98:8ab26030e058 301 uint16_t nMinus1;
Kojto 98:8ab26030e058 302
Kojto 98:8ab26030e058 303 /**
Kojto 98:8ab26030e058 304 * HPROT signal state, please refer to reference manual, DMA chapter for
Kojto 98:8ab26030e058 305 * further details. Normally set to 0 if protection is not an issue.
Kojto 98:8ab26030e058 306 * The following bits are available:
Kojto 98:8ab26030e058 307 * @li bit 0 - HPROT[1] control for source read accesses,
Kojto 98:8ab26030e058 308 * privileged/non-privileged access
Kojto 98:8ab26030e058 309 * @li bit 3 - HPROT[1] control for destination write accesses,
Kojto 98:8ab26030e058 310 * privileged/non-privileged access
Kojto 98:8ab26030e058 311 */
Kojto 98:8ab26030e058 312 uint8_t hprot;
Kojto 98:8ab26030e058 313
Kojto 98:8ab26030e058 314 /** Specify if a memory or peripheral scatter-gather DMA cycle. Notice
Kojto 98:8ab26030e058 315 * that this parameter should be the same for all alternate
Kojto 98:8ab26030e058 316 * descriptors.
Kojto 98:8ab26030e058 317 * @li true - this is a peripheral scatter-gather cycle
Kojto 98:8ab26030e058 318 * @li false - this is a memory scatter-gather cycle
Kojto 98:8ab26030e058 319 */
Kojto 98:8ab26030e058 320 bool peripheral;
Kojto 98:8ab26030e058 321 } DMA_CfgDescrSGAlt_TypeDef;
Kojto 98:8ab26030e058 322
Kojto 98:8ab26030e058 323
Kojto 98:8ab26030e058 324 /** DMA init structure */
Kojto 98:8ab26030e058 325 typedef struct
Kojto 98:8ab26030e058 326 {
Kojto 98:8ab26030e058 327 /**
Kojto 98:8ab26030e058 328 * HPROT signal state when accessing the primary/alternate
Kojto 98:8ab26030e058 329 * descriptors. Normally set to 0 if protection is not an issue.
Kojto 98:8ab26030e058 330 * The following bits are available:
Kojto 98:8ab26030e058 331 * @li bit 0 - HPROT[1] control for descriptor accesses (ie when
Kojto 98:8ab26030e058 332 * the DMA controller accesses the channel control block itself),
Kojto 98:8ab26030e058 333 * privileged/non-privileged access
Kojto 98:8ab26030e058 334 */
Kojto 98:8ab26030e058 335 uint8_t hprot;
Kojto 98:8ab26030e058 336
Kojto 98:8ab26030e058 337 /**
Kojto 98:8ab26030e058 338 * Pointer to the controlblock in memory holding descriptors (channel
Kojto 98:8ab26030e058 339 * control data structures). This memory must be properly aligned
Kojto 98:8ab26030e058 340 * at a 256 bytes. I.e. the 8 least significant bits must be zero.
Kojto 98:8ab26030e058 341 *
Kojto 98:8ab26030e058 342 * Please refer to the reference manual, DMA chapter for more details.
Kojto 98:8ab26030e058 343 *
Kojto 98:8ab26030e058 344 * It is possible to provide a smaller memory block, only covering
Kojto 98:8ab26030e058 345 * those channels actually used, if not all available channels are used.
Kojto 98:8ab26030e058 346 * Ie, if only using 4 channels (0-3), both primary and alternate
Kojto 98:8ab26030e058 347 * structures, then only 16*2*4 = 128 bytes must be provided. This
Kojto 98:8ab26030e058 348 * implementation has however no check if later exceeding such a limit
Kojto 98:8ab26030e058 349 * by configuring for instance channel 4, in which case memory overwrite
Kojto 98:8ab26030e058 350 * of some other data will occur.
Kojto 98:8ab26030e058 351 */
Kojto 98:8ab26030e058 352 DMA_DESCRIPTOR_TypeDef *controlBlock;
Kojto 98:8ab26030e058 353 } DMA_Init_TypeDef;
Kojto 98:8ab26030e058 354
Kojto 98:8ab26030e058 355
Kojto 98:8ab26030e058 356 /*******************************************************************************
Kojto 98:8ab26030e058 357 ***************************** PROTOTYPES **********************************
Kojto 98:8ab26030e058 358 ******************************************************************************/
Kojto 98:8ab26030e058 359
Kojto 98:8ab26030e058 360 void DMA_ActivateAuto(unsigned int channel,
Kojto 98:8ab26030e058 361 bool primary,
Kojto 98:8ab26030e058 362 void *dst,
Kojto 98:8ab26030e058 363 void *src,
Kojto 98:8ab26030e058 364 unsigned int nMinus1);
Kojto 98:8ab26030e058 365 void DMA_ActivateBasic(unsigned int channel,
Kojto 98:8ab26030e058 366 bool primary,
Kojto 98:8ab26030e058 367 bool useBurst,
Kojto 98:8ab26030e058 368 void *dst,
Kojto 98:8ab26030e058 369 void *src,
Kojto 98:8ab26030e058 370 unsigned int nMinus1);
Kojto 98:8ab26030e058 371 void DMA_ActivatePingPong(unsigned int channel,
Kojto 98:8ab26030e058 372 bool useBurst,
Kojto 98:8ab26030e058 373 void *primDst,
Kojto 98:8ab26030e058 374 void *primSrc,
Kojto 98:8ab26030e058 375 unsigned int primNMinus1,
Kojto 98:8ab26030e058 376 void *altDst,
Kojto 98:8ab26030e058 377 void *altSrc,
Kojto 98:8ab26030e058 378 unsigned int altNMinus1);
Kojto 98:8ab26030e058 379 void DMA_ActivateScatterGather(unsigned int channel,
Kojto 98:8ab26030e058 380 bool useBurst,
Kojto 98:8ab26030e058 381 DMA_DESCRIPTOR_TypeDef *altDescr,
Kojto 98:8ab26030e058 382 unsigned int count);
Kojto 98:8ab26030e058 383 void DMA_CfgChannel(unsigned int channel, DMA_CfgChannel_TypeDef *cfg);
Kojto 98:8ab26030e058 384 void DMA_CfgDescr(unsigned int channel,
Kojto 98:8ab26030e058 385 bool primary,
Kojto 98:8ab26030e058 386 DMA_CfgDescr_TypeDef *cfg);
Kojto 98:8ab26030e058 387 #if defined( _DMA_LOOP0_MASK ) && defined( _DMA_LOOP1_MASK )
Kojto 98:8ab26030e058 388 void DMA_CfgLoop(unsigned int channel, DMA_CfgLoop_TypeDef *cfg);
Kojto 98:8ab26030e058 389 #endif
Kojto 98:8ab26030e058 390
Kojto 98:8ab26030e058 391 #if defined( _DMA_RECT0_MASK )
Kojto 98:8ab26030e058 392 void DMA_CfgRect(unsigned int channel, DMA_CfgRect_TypeDef *cfg);
Kojto 98:8ab26030e058 393 #endif
Kojto 98:8ab26030e058 394
Kojto 98:8ab26030e058 395 #if defined( _DMA_LOOP0_MASK ) && defined( _DMA_LOOP1_MASK )
Kojto 98:8ab26030e058 396 /***************************************************************************//**
Kojto 98:8ab26030e058 397 * @brief
Kojto 98:8ab26030e058 398 * Clear Loop configuration for channel
Kojto 98:8ab26030e058 399 *
Kojto 98:8ab26030e058 400 * @param[in] channel
Kojto 98:8ab26030e058 401 * Channel to reset loop configuration for
Kojto 98:8ab26030e058 402 ******************************************************************************/
Kojto 98:8ab26030e058 403 __STATIC_INLINE void DMA_ResetLoop(unsigned int channel)
Kojto 98:8ab26030e058 404 {
Kojto 98:8ab26030e058 405 /* Clean loop copy operation */
Kojto 98:8ab26030e058 406 switch(channel)
Kojto 98:8ab26030e058 407 {
Kojto 113:f141b2784e32 408 case 0:
Kojto 113:f141b2784e32 409 DMA->LOOP0 = _DMA_LOOP0_RESETVALUE;
Kojto 113:f141b2784e32 410 break;
Kojto 113:f141b2784e32 411 case 1:
Kojto 113:f141b2784e32 412 DMA->LOOP1 = _DMA_LOOP1_RESETVALUE;
Kojto 113:f141b2784e32 413 break;
Kojto 113:f141b2784e32 414 default:
Kojto 113:f141b2784e32 415 break;
Kojto 98:8ab26030e058 416 }
Kojto 98:8ab26030e058 417 }
Kojto 98:8ab26030e058 418 #endif
Kojto 98:8ab26030e058 419
Kojto 98:8ab26030e058 420
Kojto 98:8ab26030e058 421 #if defined( _DMA_RECT0_MASK )
Kojto 98:8ab26030e058 422 /***************************************************************************//**
Kojto 98:8ab26030e058 423 * @brief
Kojto 98:8ab26030e058 424 * Clear Rect/2D DMA configuration for channel
Kojto 98:8ab26030e058 425 *
Kojto 98:8ab26030e058 426 * @param[in] channel
Kojto 98:8ab26030e058 427 * Channel to reset loop configuration for
Kojto 98:8ab26030e058 428 ******************************************************************************/
Kojto 98:8ab26030e058 429 __STATIC_INLINE void DMA_ResetRect(unsigned int channel)
Kojto 98:8ab26030e058 430 {
Kojto 98:8ab26030e058 431 (void) channel;
Kojto 98:8ab26030e058 432
Kojto 98:8ab26030e058 433 /* Clear rect copy operation */
Kojto 98:8ab26030e058 434 DMA->RECT0 = _DMA_RECT0_RESETVALUE;
Kojto 98:8ab26030e058 435 }
Kojto 98:8ab26030e058 436 #endif
Kojto 98:8ab26030e058 437 void DMA_CfgDescrScatterGather(DMA_DESCRIPTOR_TypeDef *descr,
Kojto 98:8ab26030e058 438 unsigned int indx,
Kojto 98:8ab26030e058 439 DMA_CfgDescrSGAlt_TypeDef *cfg);
Kojto 98:8ab26030e058 440 void DMA_ChannelEnable(unsigned int channel, bool enable);
Kojto 98:8ab26030e058 441 bool DMA_ChannelEnabled(unsigned int channel);
<> 128:9bcdf88f62b0 442 void DMA_ChannelRequestEnable(unsigned int channel, bool enable);
Kojto 98:8ab26030e058 443 void DMA_Init(DMA_Init_TypeDef *init);
Kojto 98:8ab26030e058 444 void DMA_IRQHandler(void);
Kojto 98:8ab26030e058 445 void DMA_RefreshPingPong(unsigned int channel,
Kojto 98:8ab26030e058 446 bool primary,
Kojto 98:8ab26030e058 447 bool useBurst,
Kojto 98:8ab26030e058 448 void *dst,
Kojto 98:8ab26030e058 449 void *src,
Kojto 98:8ab26030e058 450 unsigned int nMinus1,
Kojto 98:8ab26030e058 451 bool last);
Kojto 98:8ab26030e058 452 void DMA_Reset(void);
Kojto 98:8ab26030e058 453
Kojto 113:f141b2784e32 454 /***************************************************************************//**
Kojto 113:f141b2784e32 455 * @brief
Kojto 113:f141b2784e32 456 * Clear one or more pending DMA interrupts.
Kojto 113:f141b2784e32 457 *
Kojto 113:f141b2784e32 458 * @param[in] flags
Kojto 113:f141b2784e32 459 * Pending DMA interrupt sources to clear. Use one or more valid
Kojto 113:f141b2784e32 460 * interrupt flags for the DMA module (DMA_IFC_nnn).
Kojto 113:f141b2784e32 461 ******************************************************************************/
Kojto 113:f141b2784e32 462 __STATIC_INLINE void DMA_IntClear(uint32_t flags)
Kojto 113:f141b2784e32 463 {
Kojto 113:f141b2784e32 464 DMA->IFC = flags;
Kojto 113:f141b2784e32 465 }
Kojto 113:f141b2784e32 466
Kojto 113:f141b2784e32 467
Kojto 113:f141b2784e32 468 /***************************************************************************//**
Kojto 113:f141b2784e32 469 * @brief
Kojto 113:f141b2784e32 470 * Disable one or more DMA interrupts.
Kojto 113:f141b2784e32 471 *
Kojto 113:f141b2784e32 472 * @param[in] flags
Kojto 113:f141b2784e32 473 * DMA interrupt sources to disable. Use one or more valid
Kojto 113:f141b2784e32 474 * interrupt flags for the DMA module (DMA_IEN_nnn).
Kojto 113:f141b2784e32 475 ******************************************************************************/
Kojto 113:f141b2784e32 476 __STATIC_INLINE void DMA_IntDisable(uint32_t flags)
Kojto 113:f141b2784e32 477 {
Kojto 113:f141b2784e32 478 DMA->IEN &= ~flags;
Kojto 113:f141b2784e32 479 }
Kojto 113:f141b2784e32 480
Kojto 113:f141b2784e32 481
Kojto 113:f141b2784e32 482 /***************************************************************************//**
Kojto 113:f141b2784e32 483 * @brief
Kojto 113:f141b2784e32 484 * Enable one or more DMA interrupts.
Kojto 113:f141b2784e32 485 *
Kojto 113:f141b2784e32 486 * @note
Kojto 113:f141b2784e32 487 * Depending on the use, a pending interrupt may already be set prior to
Kojto 113:f141b2784e32 488 * enabling the interrupt. Consider using DMA_IntClear() prior to enabling
Kojto 113:f141b2784e32 489 * if such a pending interrupt should be ignored.
Kojto 113:f141b2784e32 490 *
Kojto 113:f141b2784e32 491 * @param[in] flags
Kojto 113:f141b2784e32 492 * DMA interrupt sources to enable. Use one or more valid
Kojto 113:f141b2784e32 493 * interrupt flags for the DMA module (DMA_IEN_nnn).
Kojto 113:f141b2784e32 494 ******************************************************************************/
Kojto 113:f141b2784e32 495 __STATIC_INLINE void DMA_IntEnable(uint32_t flags)
Kojto 113:f141b2784e32 496 {
Kojto 113:f141b2784e32 497 DMA->IEN |= flags;
Kojto 113:f141b2784e32 498 }
Kojto 113:f141b2784e32 499
Kojto 113:f141b2784e32 500
Kojto 113:f141b2784e32 501 /***************************************************************************//**
Kojto 113:f141b2784e32 502 * @brief
Kojto 113:f141b2784e32 503 * Get pending DMA interrupt flags.
Kojto 113:f141b2784e32 504 *
Kojto 113:f141b2784e32 505 * @note
Kojto 113:f141b2784e32 506 * The event bits are not cleared by the use of this function.
Kojto 113:f141b2784e32 507 *
Kojto 113:f141b2784e32 508 * @return
Kojto 113:f141b2784e32 509 * DMA interrupt sources pending. Returns one or more valid
Kojto 113:f141b2784e32 510 * interrupt flags for the DMA module (DMA_IF_nnn).
Kojto 113:f141b2784e32 511 ******************************************************************************/
Kojto 113:f141b2784e32 512 __STATIC_INLINE uint32_t DMA_IntGet(void)
Kojto 113:f141b2784e32 513 {
Kojto 113:f141b2784e32 514 return DMA->IF;
Kojto 113:f141b2784e32 515 }
Kojto 113:f141b2784e32 516
Kojto 113:f141b2784e32 517
Kojto 113:f141b2784e32 518 /***************************************************************************//**
Kojto 113:f141b2784e32 519 * @brief
Kojto 113:f141b2784e32 520 * Get enabled and pending DMA interrupt flags.
Kojto 113:f141b2784e32 521 * Useful for handling more interrupt sources in the same interrupt handler.
Kojto 113:f141b2784e32 522 *
Kojto 113:f141b2784e32 523 * @note
Kojto 113:f141b2784e32 524 * Interrupt flags are not cleared by the use of this function.
Kojto 113:f141b2784e32 525 *
Kojto 113:f141b2784e32 526 * @return
Kojto 113:f141b2784e32 527 * Pending and enabled DMA interrupt sources
Kojto 113:f141b2784e32 528 * The return value is the bitwise AND of
Kojto 113:f141b2784e32 529 * - the enabled interrupt sources in DMA_IEN and
Kojto 113:f141b2784e32 530 * - the pending interrupt flags DMA_IF
Kojto 113:f141b2784e32 531 ******************************************************************************/
Kojto 113:f141b2784e32 532 __STATIC_INLINE uint32_t DMA_IntGetEnabled(void)
Kojto 113:f141b2784e32 533 {
Kojto 113:f141b2784e32 534 uint32_t ien;
Kojto 113:f141b2784e32 535
Kojto 113:f141b2784e32 536 ien = DMA->IEN;
Kojto 113:f141b2784e32 537 return DMA->IF & ien;
Kojto 113:f141b2784e32 538 }
Kojto 113:f141b2784e32 539
Kojto 113:f141b2784e32 540
Kojto 113:f141b2784e32 541 /***************************************************************************//**
Kojto 113:f141b2784e32 542 * @brief
Kojto 113:f141b2784e32 543 * Set one or more pending DMA interrupts
Kojto 113:f141b2784e32 544 *
Kojto 113:f141b2784e32 545 * @param[in] flags
Kojto 113:f141b2784e32 546 * DMA interrupt sources to set to pending. Use one or more valid
Kojto 113:f141b2784e32 547 * interrupt flags for the DMA module (DMA_IFS_nnn).
Kojto 113:f141b2784e32 548 ******************************************************************************/
Kojto 113:f141b2784e32 549 __STATIC_INLINE void DMA_IntSet(uint32_t flags)
Kojto 113:f141b2784e32 550 {
Kojto 113:f141b2784e32 551 DMA->IFS = flags;
Kojto 113:f141b2784e32 552 }
Kojto 113:f141b2784e32 553
Kojto 98:8ab26030e058 554 /** @} (end addtogroup DMA) */
<> 128:9bcdf88f62b0 555 /** @} (end addtogroup emlib) */
Kojto 98:8ab26030e058 556
Kojto 98:8ab26030e058 557 #ifdef __cplusplus
Kojto 98:8ab26030e058 558 }
Kojto 98:8ab26030e058 559 #endif
Kojto 98:8ab26030e058 560
Kojto 98:8ab26030e058 561 #endif /* defined( DMA_PRESENT ) */
<> 128:9bcdf88f62b0 562 #endif /* EM_DMA_H */