mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

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

Committer:
mbed_official
Date:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Child:
592:a274ee790e56
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

Full URL: https://github.com/mbedmicro/mbed/commit/d5b4d2ab9c47edb4dc5776e7177b0c2263459081/

Initial version of drivers for SAMR21

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 579:53297373a894 1 /**
mbed_official 579:53297373a894 2 * \file
mbed_official 579:53297373a894 3 *
mbed_official 579:53297373a894 4 * \brief SAM Direct Memory Access Controller Driver
mbed_official 579:53297373a894 5 *
mbed_official 579:53297373a894 6 * Copyright (C) 2014 Atmel Corporation. All rights reserved.
mbed_official 579:53297373a894 7 *
mbed_official 579:53297373a894 8 * \asf_license_start
mbed_official 579:53297373a894 9 *
mbed_official 579:53297373a894 10 * \page License
mbed_official 579:53297373a894 11 *
mbed_official 579:53297373a894 12 * Redistribution and use in source and binary forms, with or without
mbed_official 579:53297373a894 13 * modification, are permitted provided that the following conditions are met:
mbed_official 579:53297373a894 14 *
mbed_official 579:53297373a894 15 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 579:53297373a894 16 * this list of conditions and the following disclaimer.
mbed_official 579:53297373a894 17 *
mbed_official 579:53297373a894 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 579:53297373a894 19 * this list of conditions and the following disclaimer in the documentation
mbed_official 579:53297373a894 20 * and/or other materials provided with the distribution.
mbed_official 579:53297373a894 21 *
mbed_official 579:53297373a894 22 * 3. The name of Atmel may not be used to endorse or promote products derived
mbed_official 579:53297373a894 23 * from this software without specific prior written permission.
mbed_official 579:53297373a894 24 *
mbed_official 579:53297373a894 25 * 4. This software may only be redistributed and used in connection with an
mbed_official 579:53297373a894 26 * Atmel microcontroller product.
mbed_official 579:53297373a894 27 *
mbed_official 579:53297373a894 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
mbed_official 579:53297373a894 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 579:53297373a894 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
mbed_official 579:53297373a894 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
mbed_official 579:53297373a894 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 579:53297373a894 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
mbed_official 579:53297373a894 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mbed_official 579:53297373a894 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
mbed_official 579:53297373a894 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 579:53297373a894 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 579:53297373a894 38 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 579:53297373a894 39 *
mbed_official 579:53297373a894 40 * \asf_license_stop
mbed_official 579:53297373a894 41 *
mbed_official 579:53297373a894 42 */
mbed_official 579:53297373a894 43 /**
mbed_official 579:53297373a894 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
mbed_official 579:53297373a894 45 */
mbed_official 579:53297373a894 46 #ifndef DMA_H_INCLUDED
mbed_official 579:53297373a894 47 #define DMA_H_INCLUDED
mbed_official 579:53297373a894 48
mbed_official 579:53297373a894 49 #ifdef __cplusplus
mbed_official 579:53297373a894 50 extern "C" {
mbed_official 579:53297373a894 51 #endif
mbed_official 579:53297373a894 52
mbed_official 579:53297373a894 53 /**
mbed_official 579:53297373a894 54 * \defgroup asfdoc_sam0_dma_group SAM Direct Memory Access Controller Driver (DMAC)
mbed_official 579:53297373a894 55 *
mbed_official 579:53297373a894 56 * This driver for Atmel庐 | SMART SAM devices provides an interface for the configuration
mbed_official 579:53297373a894 57 * and management of the Direct Memory Access Controller(DMAC) module within
mbed_official 579:53297373a894 58 * the device. The DMAC can transfer data between memories and peripherals, and
mbed_official 579:53297373a894 59 * thus off-load these tasks from the CPU. The module supports peripheral to
mbed_official 579:53297373a894 60 * peripheral, peripheral to memory, memory to peripheral, and memory to memory
mbed_official 579:53297373a894 61 * transfers.
mbed_official 579:53297373a894 62 *
mbed_official 579:53297373a894 63 * The following peripherals are used by the DMAC Driver:
mbed_official 579:53297373a894 64 * - DMAC (Direct Memory Access Controller)
mbed_official 579:53297373a894 65 *
mbed_official 579:53297373a894 66 * The following devices can use this module:
mbed_official 579:53297373a894 67 * - Atmel | SMART SAM D21
mbed_official 579:53297373a894 68 * - Atmel | SMART SAM R21
mbed_official 579:53297373a894 69 * - Atmel | SMART SAM D10/D11
mbed_official 579:53297373a894 70 * - Atmel | SMART SAM L21
mbed_official 579:53297373a894 71 *
mbed_official 579:53297373a894 72 * The outline of this documentation is as follows:
mbed_official 579:53297373a894 73 * - \ref asfdoc_sam0_dma_prerequisites
mbed_official 579:53297373a894 74 * - \ref asfdoc_sam0_dma_module_overview
mbed_official 579:53297373a894 75 * - \ref asfdoc_sam0_dma_special_considerations
mbed_official 579:53297373a894 76 * - \ref asfdoc_sam0_dma_extra_info
mbed_official 579:53297373a894 77 * - \ref asfdoc_sam0_dma_examples
mbed_official 579:53297373a894 78 * - \ref asfdoc_sam0_dma_api_overview
mbed_official 579:53297373a894 79 *
mbed_official 579:53297373a894 80 *
mbed_official 579:53297373a894 81 * \section asfdoc_sam0_dma_prerequisites Prerequisites
mbed_official 579:53297373a894 82 *
mbed_official 579:53297373a894 83 * There are no prerequisites for this module.
mbed_official 579:53297373a894 84 *
mbed_official 579:53297373a894 85 *
mbed_official 579:53297373a894 86 * \section asfdoc_sam0_dma_module_overview Module Overview
mbed_official 579:53297373a894 87 *
mbed_official 579:53297373a894 88 * SAM devices with DMAC enables high data transfer rates with minimum
mbed_official 579:53297373a894 89 * CPU intervention and frees up CPU time. With access to all peripherals,
mbed_official 579:53297373a894 90 * the DMAC can handle automatic transfer of data to/from modules.
mbed_official 579:53297373a894 91 * It supports static and incremental addressing for both source and
mbed_official 579:53297373a894 92 * destination.
mbed_official 579:53297373a894 93 *
mbed_official 579:53297373a894 94 * The DMAC when used with Event System or peripheral triggers, provides a
mbed_official 579:53297373a894 95 * considerable advantage by reducing the power consumption and performing
mbed_official 579:53297373a894 96 * data transfer in the background.
mbed_official 579:53297373a894 97 * For example if the ADC is configured to generate an event, it can trigger
mbed_official 579:53297373a894 98 * the DMAC to transfer the data into another peripheral or into SRAM.
mbed_official 579:53297373a894 99 * The CPU can remain in sleep during this time to reduce power consumption.
mbed_official 579:53297373a894 100 *
mbed_official 579:53297373a894 101 * The DMAC module has 12 channels. The DMA channel
mbed_official 579:53297373a894 102 * operation can be suspended at any time by software, by events
mbed_official 579:53297373a894 103 * from event system, or after selectable descriptor execution. The operation
mbed_official 579:53297373a894 104 * can be resumed by software or by events from event system.
mbed_official 579:53297373a894 105 * The DMAC driver for SAM supports four types of transfers such as
mbed_official 579:53297373a894 106 * peripheral to peripheral, peripheral to memory, memory to peripheral, and
mbed_official 579:53297373a894 107 * memory to memory.
mbed_official 579:53297373a894 108 *
mbed_official 579:53297373a894 109 * The basic transfer unit is a beat which is defined as a single bus access.
mbed_official 579:53297373a894 110 * There can be multiple beats in a single block transfer and multiple block
mbed_official 579:53297373a894 111 * transfers in a DMA transaction.
mbed_official 579:53297373a894 112 * DMA transfer is based on descriptors, which holds transfer properties
mbed_official 579:53297373a894 113 * such as the source and destination addresses, transfer counter, and other
mbed_official 579:53297373a894 114 * additional transfer control information.
mbed_official 579:53297373a894 115 * The descriptors can be static or linked. When static, a single block transfer
mbed_official 579:53297373a894 116 * is performed. When linked, a number of transfer descriptors can be used to
mbed_official 579:53297373a894 117 * enable multiple block transfers within a single DMA transaction.
mbed_official 579:53297373a894 118 *
mbed_official 579:53297373a894 119 * The implementation of the DMA driver is based on the idea that DMA channel
mbed_official 579:53297373a894 120 * is a finite resource of entities with the same abilities. A DMA channel resource
mbed_official 579:53297373a894 121 * is able to move a defined set of data from a source address to destination
mbed_official 579:53297373a894 122 * address triggered by a transfer trigger. On the SAM devices there are 12
mbed_official 579:53297373a894 123 * DMA resources available for allocation. Each of these DMA resources can trigger
mbed_official 579:53297373a894 124 * interrupt callback routines and peripheral events.
mbed_official 579:53297373a894 125 * The other main features are
mbed_official 579:53297373a894 126 *
mbed_official 579:53297373a894 127 * - Selectable transfer trigger source
mbed_official 579:53297373a894 128 * - Software
mbed_official 579:53297373a894 129 * - Event System
mbed_official 579:53297373a894 130 * - Peripheral
mbed_official 579:53297373a894 131 * - Event input and output is supported for the four lower channels
mbed_official 579:53297373a894 132 * - Four level channel priority
mbed_official 579:53297373a894 133 * - Optional interrupt generation on transfer complete, channel error or channel suspend
mbed_official 579:53297373a894 134 * - Supports multi-buffer or circular buffer mode by linking multiple descriptors
mbed_official 579:53297373a894 135 * - Beat size configurable as 8-bit, 16-bit, or 32-bit
mbed_official 579:53297373a894 136 *
mbed_official 579:53297373a894 137 * A simplified block diagram of the DMA Resource can be seen in
mbed_official 579:53297373a894 138 * \ref asfdoc_sam0_dma_module_block_diagram "the figure below".
mbed_official 579:53297373a894 139 *
mbed_official 579:53297373a894 140 * \anchor asfdoc_sam0_dma_module_block_diagram
mbed_official 579:53297373a894 141 * \dot
mbed_official 579:53297373a894 142 * digraph overview {
mbed_official 579:53297373a894 143 * splines = false;
mbed_official 579:53297373a894 144 * rankdir=LR;
mbed_official 579:53297373a894 145 *
mbed_official 579:53297373a894 146 * mux1 [label="Transfer Trigger", shape=box];
mbed_official 579:53297373a894 147 *
mbed_official 579:53297373a894 148 * dma [label="DMA Channel", shape=polygon, sides=6, orientation=60, style=filled, fillcolor=darkolivegreen1, height=1, width=1];
mbed_official 579:53297373a894 149 * descriptor [label="Transfer Descriptor", shape=box, style=filled, fillcolor=lightblue];
mbed_official 579:53297373a894 150 *
mbed_official 579:53297373a894 151 * mux1 -> dma;
mbed_official 579:53297373a894 152 * descriptor -> dma;
mbed_official 579:53297373a894 153 *
mbed_official 579:53297373a894 154 * interrupt [label="Interrupt", shape=box];
mbed_official 579:53297373a894 155 * events [label="Events", shape=box];
mbed_official 579:53297373a894 156 *
mbed_official 579:53297373a894 157 * dma:e -> interrupt:w;
mbed_official 579:53297373a894 158 * dma:e -> events:w;
mbed_official 579:53297373a894 159 *
mbed_official 579:53297373a894 160 * {rank=same; descriptor dma}
mbed_official 579:53297373a894 161 *
mbed_official 579:53297373a894 162 * }
mbed_official 579:53297373a894 163 * \enddot
mbed_official 579:53297373a894 164 *
mbed_official 579:53297373a894 165 * \subsection asfdoc_sam0_dma_features Driver Feature Macro Definition
mbed_official 579:53297373a894 166 * <table>
mbed_official 579:53297373a894 167 * <tr>
mbed_official 579:53297373a894 168 * <th>Driver Feature Macro</th>
mbed_official 579:53297373a894 169 * <th>Supported devices</th>
mbed_official 579:53297373a894 170 * </tr>
mbed_official 579:53297373a894 171 * <tr>
mbed_official 579:53297373a894 172 * <td>FEATURE_DMA_CHANNEL_STANDBY</td>
mbed_official 579:53297373a894 173 * <td>SAML21</td>
mbed_official 579:53297373a894 174 * </tr>
mbed_official 579:53297373a894 175 * </table>
mbed_official 579:53297373a894 176 * \note The specific features are only available in the driver when the
mbed_official 579:53297373a894 177 * selected device supports those features.
mbed_official 579:53297373a894 178 *
mbed_official 579:53297373a894 179 * \subsection asfdoc_sam0_dma_module_overview_dma_transf_term Terminology Used in DMAC Transfers
mbed_official 579:53297373a894 180 *
mbed_official 579:53297373a894 181 * <table border="0" cellborder="1" cellspacing="0" >
mbed_official 579:53297373a894 182 * <tr>
mbed_official 579:53297373a894 183 * <th> Name </th> <th> Description </th>
mbed_official 579:53297373a894 184 * </tr>
mbed_official 579:53297373a894 185 * <tr>
mbed_official 579:53297373a894 186 * <td > Beat </td>
mbed_official 579:53297373a894 187 * <td > It is a single bus access by the DMAC.
mbed_official 579:53297373a894 188 * Configurable as 8-bit, 16-bit, or 32-bit
mbed_official 579:53297373a894 189 * </td>
mbed_official 579:53297373a894 190 * </tr>
mbed_official 579:53297373a894 191 * <tr>
mbed_official 579:53297373a894 192 * <td > Burst </td>
mbed_official 579:53297373a894 193 * <td> It is a transfer of n-beats (n=1,4,8,16).
mbed_official 579:53297373a894 194 * For the DMAC module in SAM, the burst size is one beat.
mbed_official 579:53297373a894 195 * Arbitration takes place each time a burst transfer is completed
mbed_official 579:53297373a894 196 * </td>
mbed_official 579:53297373a894 197 * </tr>
mbed_official 579:53297373a894 198 * <tr>
mbed_official 579:53297373a894 199 * <td > Block transfer </td>
mbed_official 579:53297373a894 200 * <td> A single block transfer is a configurable number of (1 to 64k)
mbed_official 579:53297373a894 201 * beat transfers
mbed_official 579:53297373a894 202 * </td>
mbed_official 579:53297373a894 203 * </tr>
mbed_official 579:53297373a894 204 * </table>
mbed_official 579:53297373a894 205 *
mbed_official 579:53297373a894 206 * \subsection asfdoc_sam0_dma_module_overview_dma_channels DMA Channels
mbed_official 579:53297373a894 207 * The DMAC in each device consists of several DMA channels, which
mbed_official 579:53297373a894 208 * along with the transfer descriptors defines the data transfer properties.
mbed_official 579:53297373a894 209 * - The transfer control descriptor defines the source and destination
mbed_official 579:53297373a894 210 * addresses, source and destination address increment settings, the
mbed_official 579:53297373a894 211 * block transfer count and event output condition selection
mbed_official 579:53297373a894 212 * - Dedicated channel registers control the peripheral trigger source,
mbed_official 579:53297373a894 213 * trigger mode settings, event input actions, and channel priority level
mbed_official 579:53297373a894 214 * settings
mbed_official 579:53297373a894 215 *
mbed_official 579:53297373a894 216 * With a successful DMA resource allocation, a dedicated
mbed_official 579:53297373a894 217 * DMA channel will be assigned. The channel will be occupied until the
mbed_official 579:53297373a894 218 * DMA resource is freed. A DMA resource handle is used to identify the specific
mbed_official 579:53297373a894 219 * DMA resource.
mbed_official 579:53297373a894 220 * When there are multiple channels with active requests, the arbiter prioritizes
mbed_official 579:53297373a894 221 * the channels requesting access to the bus.
mbed_official 579:53297373a894 222 *
mbed_official 579:53297373a894 223 * \subsection asfdoc_sam0_dma_module_overview_dma_trigger DMA Triggers
mbed_official 579:53297373a894 224 * DMA transfer can be started only when a DMA transfer request is acknowledged/granted by the arbiter. A
mbed_official 579:53297373a894 225 * transfer request can be triggered from software, peripheral, or an event. There
mbed_official 579:53297373a894 226 * are dedicated source trigger selections for each DMA channel usage.
mbed_official 579:53297373a894 227
mbed_official 579:53297373a894 228 *
mbed_official 579:53297373a894 229 * \subsection asfdoc_sam0_dma_module_overview_dma_transfer_descriptor DMA Transfer Descriptor
mbed_official 579:53297373a894 230 * The transfer descriptor resides in the SRAM and
mbed_official 579:53297373a894 231 * defines these channel properties.
mbed_official 579:53297373a894 232 * <table border="0" cellborder="1" cellspacing="0" >
mbed_official 579:53297373a894 233 * <tr>
mbed_official 579:53297373a894 234 * <th> Field name </th> <th> Field width </th>
mbed_official 579:53297373a894 235 * </tr>
mbed_official 579:53297373a894 236 * <tr>
mbed_official 579:53297373a894 237 * <td > Descriptor Next Address </td> <td > 32 bits </td>
mbed_official 579:53297373a894 238 * </tr>
mbed_official 579:53297373a894 239 * <tr>
mbed_official 579:53297373a894 240 * <td > Destination Address </td> <td> 32 bits </td>
mbed_official 579:53297373a894 241 * </tr>
mbed_official 579:53297373a894 242 * <tr>
mbed_official 579:53297373a894 243 * <td > Source Address </td> <td> 32 bits </td>
mbed_official 579:53297373a894 244 * </tr>
mbed_official 579:53297373a894 245 * <tr>
mbed_official 579:53297373a894 246 * <td > Block Transfer Counter </td> <td> 16 bits </td>
mbed_official 579:53297373a894 247 * </tr>
mbed_official 579:53297373a894 248 * <tr>
mbed_official 579:53297373a894 249 * <td > Block Transfer Control </td> <td> 16 bits </td>
mbed_official 579:53297373a894 250 * </tr>
mbed_official 579:53297373a894 251 * </table>
mbed_official 579:53297373a894 252 *
mbed_official 579:53297373a894 253 * Before starting a transfer, at least one descriptor should be configured.
mbed_official 579:53297373a894 254 * After a successful allocation of a DMA channel, the transfer descriptor can
mbed_official 579:53297373a894 255 * be added with a call to \ref dma_add_descriptor(). If there is a transfer
mbed_official 579:53297373a894 256 * descriptor already allocated to the DMA resource, the descriptor will
mbed_official 579:53297373a894 257 * be linked to the next descriptor address.
mbed_official 579:53297373a894 258 *
mbed_official 579:53297373a894 259 * \subsection asfdoc_sam0_dma_module_overview_dma_output DMA Interrupts/Events
mbed_official 579:53297373a894 260 * Both an interrupt callback and an peripheral event can be triggered by the
mbed_official 579:53297373a894 261 * DMA transfer. Three types of callbacks are supported by the DMA driver:
mbed_official 579:53297373a894 262 * transfer complete, channel suspend, and transfer error. Each of these callback
mbed_official 579:53297373a894 263 * types can be registered and enabled for each channel independently through
mbed_official 579:53297373a894 264 * the DMA driver API.
mbed_official 579:53297373a894 265 *
mbed_official 579:53297373a894 266 * The DMAC module can also generate events on transfer complete. Event
mbed_official 579:53297373a894 267 * generation is enabled through the DMA channel, event channel configuration,
mbed_official 579:53297373a894 268 * and event user multiplexing is done through the events driver.
mbed_official 579:53297373a894 269 *
mbed_official 579:53297373a894 270 * The DMAC can generate events in the below cases:
mbed_official 579:53297373a894 271 *
mbed_official 579:53297373a894 272 * - When a block transfer is complete
mbed_official 579:53297373a894 273 *
mbed_official 579:53297373a894 274 * - When each beat transfer within a block transfer is complete
mbed_official 579:53297373a894 275 *
mbed_official 579:53297373a894 276 * \section asfdoc_sam0_dma_special_considerations Special Considerations
mbed_official 579:53297373a894 277 *
mbed_official 579:53297373a894 278 * There are no special considerations for this module.
mbed_official 579:53297373a894 279 *
mbed_official 579:53297373a894 280 *
mbed_official 579:53297373a894 281 * \section asfdoc_sam0_dma_extra_info Extra Information
mbed_official 579:53297373a894 282 *
mbed_official 579:53297373a894 283 * For extra information, see \ref asfdoc_sam0_dma_extra. This includes:
mbed_official 579:53297373a894 284 * - \ref asfdoc_sam0_dma_extra_acronyms
mbed_official 579:53297373a894 285 * - \ref asfdoc_sam0_dma_extra_dependencies
mbed_official 579:53297373a894 286 * - \ref asfdoc_sam0_dma_extra_errata
mbed_official 579:53297373a894 287 * - \ref asfdoc_sam0_dma_extra_history
mbed_official 579:53297373a894 288 *
mbed_official 579:53297373a894 289 *
mbed_official 579:53297373a894 290 * \section asfdoc_sam0_dma_examples Examples
mbed_official 579:53297373a894 291 *
mbed_official 579:53297373a894 292 * For a list of examples related to this driver, see
mbed_official 579:53297373a894 293 * \ref asfdoc_sam0_dma_exqsg.
mbed_official 579:53297373a894 294 *
mbed_official 579:53297373a894 295 *
mbed_official 579:53297373a894 296 * \section asfdoc_sam0_dma_api_overview API Overview
mbed_official 579:53297373a894 297 * @{
mbed_official 579:53297373a894 298 */
mbed_official 579:53297373a894 299
mbed_official 579:53297373a894 300 #include <compiler.h>
mbed_official 579:53297373a894 301 #include "conf_dma.h"
mbed_official 579:53297373a894 302
mbed_official 579:53297373a894 303 #if (SAML21)
mbed_official 579:53297373a894 304 #define FEATURE_DMA_CHANNEL_STANDBY
mbed_official 579:53297373a894 305 #endif
mbed_official 579:53297373a894 306
mbed_official 579:53297373a894 307 /** DMA invalid channel number. */
mbed_official 579:53297373a894 308 #define DMA_INVALID_CHANNEL 0xff
mbed_official 579:53297373a894 309
mbed_official 579:53297373a894 310 /** ExInitial description section. */
mbed_official 579:53297373a894 311 extern DmacDescriptor descriptor_section[CONF_MAX_USED_CHANNEL_NUM];
mbed_official 579:53297373a894 312
mbed_official 579:53297373a894 313 /** DMA priority level. */
mbed_official 579:53297373a894 314 enum dma_priority_level {
mbed_official 579:53297373a894 315 /** Priority level 0. */
mbed_official 579:53297373a894 316 DMA_PRIORITY_LEVEL_0,
mbed_official 579:53297373a894 317 /** Priority level 1. */
mbed_official 579:53297373a894 318 DMA_PRIORITY_LEVEL_1,
mbed_official 579:53297373a894 319 /** Priority level 2. */
mbed_official 579:53297373a894 320 DMA_PRIORITY_LEVEL_2,
mbed_official 579:53297373a894 321 /** Priority level 3. */
mbed_official 579:53297373a894 322 DMA_PRIORITY_LEVEL_3,
mbed_official 579:53297373a894 323 };
mbed_official 579:53297373a894 324
mbed_official 579:53297373a894 325 /** DMA input actions. */
mbed_official 579:53297373a894 326 enum dma_event_input_action {
mbed_official 579:53297373a894 327 /** No action. */
mbed_official 579:53297373a894 328 DMA_EVENT_INPUT_NOACT,
mbed_official 579:53297373a894 329 /** Normal transfer and periodic transfer trigger. */
mbed_official 579:53297373a894 330 DMA_EVENT_INPUT_TRIG,
mbed_official 579:53297373a894 331 /** Conditional transfer trigger. */
mbed_official 579:53297373a894 332 DMA_EVENT_INPUT_CTRIG,
mbed_official 579:53297373a894 333 /** Conditional block transfer. */
mbed_official 579:53297373a894 334 DMA_EVENT_INPUT_CBLOCK,
mbed_official 579:53297373a894 335 /** Channel suspend operation. */
mbed_official 579:53297373a894 336 DMA_EVENT_INPUT_SUSPEND,
mbed_official 579:53297373a894 337 /** Channel resume operation. */
mbed_official 579:53297373a894 338 DMA_EVENT_INPUT_RESUME,
mbed_official 579:53297373a894 339 /** Skip next block suspend action. */
mbed_official 579:53297373a894 340 DMA_EVENT_INPUT_SSKIP,
mbed_official 579:53297373a894 341 };
mbed_official 579:53297373a894 342
mbed_official 579:53297373a894 343 /**
mbed_official 579:53297373a894 344 * Address increment step size. These bits select the address increment step
mbed_official 579:53297373a894 345 * size. The setting apply to source or destination address, depending on
mbed_official 579:53297373a894 346 * STEPSEL setting.
mbed_official 579:53297373a894 347 */
mbed_official 579:53297373a894 348 enum dma_address_increment_stepsize {
mbed_official 579:53297373a894 349 /** The address is incremented by (beat size * 1). */
mbed_official 579:53297373a894 350 DMA_ADDRESS_INCREMENT_STEP_SIZE_1 = 0,
mbed_official 579:53297373a894 351 /** The address is incremented by (beat size * 2). */
mbed_official 579:53297373a894 352 DMA_ADDRESS_INCREMENT_STEP_SIZE_2,
mbed_official 579:53297373a894 353 /** The address is incremented by (beat size * 4). */
mbed_official 579:53297373a894 354 DMA_ADDRESS_INCREMENT_STEP_SIZE_4,
mbed_official 579:53297373a894 355 /** The address is incremented by (beat size * 8). */
mbed_official 579:53297373a894 356 DMA_ADDRESS_INCREMENT_STEP_SIZE_8,
mbed_official 579:53297373a894 357 /** The address is incremented by (beat size * 16). */
mbed_official 579:53297373a894 358 DMA_ADDRESS_INCREMENT_STEP_SIZE_16,
mbed_official 579:53297373a894 359 /** The address is incremented by (beat size * 32). */
mbed_official 579:53297373a894 360 DMA_ADDRESS_INCREMENT_STEP_SIZE_32,
mbed_official 579:53297373a894 361 /** The address is incremented by (beat size * 64). */
mbed_official 579:53297373a894 362 DMA_ADDRESS_INCREMENT_STEP_SIZE_64,
mbed_official 579:53297373a894 363 /** The address is incremented by (beat size * 128). */
mbed_official 579:53297373a894 364 DMA_ADDRESS_INCREMENT_STEP_SIZE_128,
mbed_official 579:53297373a894 365 };
mbed_official 579:53297373a894 366
mbed_official 579:53297373a894 367 /**
mbed_official 579:53297373a894 368 * DMA step selection. This bit determines whether the step size setting
mbed_official 579:53297373a894 369 * is applied to source or destination address.
mbed_official 579:53297373a894 370 */
mbed_official 579:53297373a894 371 enum dma_step_selection {
mbed_official 579:53297373a894 372 /** Step size settings apply to the destination address. */
mbed_official 579:53297373a894 373 DMA_STEPSEL_DST = 0,
mbed_official 579:53297373a894 374 /** Step size settings apply to the source address. */
mbed_official 579:53297373a894 375 DMA_STEPSEL_SRC,
mbed_official 579:53297373a894 376 };
mbed_official 579:53297373a894 377
mbed_official 579:53297373a894 378 /** The basic transfer unit in DMAC is a beat, which is defined as a
mbed_official 579:53297373a894 379 * single bus access. Its size is configurable and applies to both read
mbed_official 579:53297373a894 380 * and write. */
mbed_official 579:53297373a894 381 enum dma_beat_size {
mbed_official 579:53297373a894 382 /** 8-bit access. */
mbed_official 579:53297373a894 383 DMA_BEAT_SIZE_BYTE = 0,
mbed_official 579:53297373a894 384 /** 16-bit access. */
mbed_official 579:53297373a894 385 DMA_BEAT_SIZE_HWORD,
mbed_official 579:53297373a894 386 /** 32-bit access. */
mbed_official 579:53297373a894 387 DMA_BEAT_SIZE_WORD,
mbed_official 579:53297373a894 388 };
mbed_official 579:53297373a894 389
mbed_official 579:53297373a894 390 /**
mbed_official 579:53297373a894 391 * Block action definitions.
mbed_official 579:53297373a894 392 */
mbed_official 579:53297373a894 393 enum dma_block_action {
mbed_official 579:53297373a894 394 /** No action. */
mbed_official 579:53297373a894 395 DMA_BLOCK_ACTION_NOACT = 0,
mbed_official 579:53297373a894 396 /** Channel in normal operation and sets transfer complete interrupt flag
mbed_official 579:53297373a894 397 * after block transfer. */
mbed_official 579:53297373a894 398 DMA_BLOCK_ACTION_INT,
mbed_official 579:53297373a894 399 /** Trigger channel suspend after block transfer and sets channel
mbed_official 579:53297373a894 400 * suspend interrupt flag once the channel is suspended. */
mbed_official 579:53297373a894 401 DMA_BLOCK_ACTION_SUSPEND,
mbed_official 579:53297373a894 402 /** Sets transfer complete interrupt flag after a block transfer and
mbed_official 579:53297373a894 403 * trigger channel suspend. The channel suspend interrupt flag will be set
mbed_official 579:53297373a894 404 * once the channel is suspended. */
mbed_official 579:53297373a894 405 DMA_BLOCK_ACTION_BOTH,
mbed_official 579:53297373a894 406 };
mbed_official 579:53297373a894 407
mbed_official 579:53297373a894 408 /** Event output selection. */
mbed_official 579:53297373a894 409 enum dma_event_output_selection {
mbed_official 579:53297373a894 410 /** Event generation disable. */
mbed_official 579:53297373a894 411 DMA_EVENT_OUTPUT_DISABLE = 0,
mbed_official 579:53297373a894 412 /** Event strobe when block transfer complete. */
mbed_official 579:53297373a894 413 DMA_EVENT_OUTPUT_BLOCK,
mbed_official 579:53297373a894 414 /** Event output reserved. */
mbed_official 579:53297373a894 415 DMA_EVENT_OUTPUT_RESERVED,
mbed_official 579:53297373a894 416 /** Event strobe when beat transfer complete. */
mbed_official 579:53297373a894 417 DMA_EVENT_OUTPUT_BEAT,
mbed_official 579:53297373a894 418 };
mbed_official 579:53297373a894 419
mbed_official 579:53297373a894 420 /** DMA trigger action type. */
mbed_official 579:53297373a894 421 enum dma_transfer_trigger_action {
mbed_official 579:53297373a894 422 /** Perform a block transfer when triggered. */
mbed_official 579:53297373a894 423 DMA_TRIGGER_ACTON_BLOCK = DMAC_CHCTRLB_TRIGACT_BLOCK_Val,
mbed_official 579:53297373a894 424 /** Perform a beat transfer when triggered. */
mbed_official 579:53297373a894 425 DMA_TRIGGER_ACTON_BEAT = DMAC_CHCTRLB_TRIGACT_BEAT_Val,
mbed_official 579:53297373a894 426 /** Perform a transaction when triggered. */
mbed_official 579:53297373a894 427 DMA_TRIGGER_ACTON_TRANSACTION = DMAC_CHCTRLB_TRIGACT_TRANSACTION_Val,
mbed_official 579:53297373a894 428 };
mbed_official 579:53297373a894 429
mbed_official 579:53297373a894 430 /**
mbed_official 579:53297373a894 431 * Callback types for DMA callback driver.
mbed_official 579:53297373a894 432 */
mbed_official 579:53297373a894 433 enum dma_callback_type {
mbed_official 579:53297373a894 434 /** Callback for transfer complete. */
mbed_official 579:53297373a894 435 DMA_CALLBACK_TRANSFER_DONE,
mbed_official 579:53297373a894 436 /** Callback for any of transfer errors. A transfer error is flagged
mbed_official 579:53297373a894 437 * if a bus error is detected during an AHB access or when the DMAC
mbed_official 579:53297373a894 438 * fetches an invalid descriptor. */
mbed_official 579:53297373a894 439 DMA_CALLBACK_TRANSFER_ERROR,
mbed_official 579:53297373a894 440 /** Callback for channel suspend. */
mbed_official 579:53297373a894 441 DMA_CALLBACK_CHANNEL_SUSPEND,
mbed_official 579:53297373a894 442 /** Number of available callbacks. */
mbed_official 579:53297373a894 443 DMA_CALLBACK_N,
mbed_official 579:53297373a894 444 };
mbed_official 579:53297373a894 445
mbed_official 579:53297373a894 446 /**
mbed_official 579:53297373a894 447 * DMA transfer descriptor configuration. When the source or destination address
mbed_official 579:53297373a894 448 * increment is enabled, the addresses stored into the configuration structure
mbed_official 579:53297373a894 449 * must correspond to the end of the transfer.
mbed_official 579:53297373a894 450 *
mbed_official 579:53297373a894 451 */
mbed_official 579:53297373a894 452 struct dma_descriptor_config {
mbed_official 579:53297373a894 453 /** Descriptor valid flag used to identify whether a descriptor is
mbed_official 579:53297373a894 454 valid or not. */
mbed_official 579:53297373a894 455 bool descriptor_valid;
mbed_official 579:53297373a894 456 /** This is used to generate an event on specific transfer action in
mbed_official 579:53297373a894 457 a channel. Supported only in four lower channels. */
mbed_official 579:53297373a894 458 enum dma_event_output_selection event_output_selection;
mbed_official 579:53297373a894 459 /** Action taken when a block transfer is completed. */
mbed_official 579:53297373a894 460 enum dma_block_action block_action;
mbed_official 579:53297373a894 461 /** Beat size is configurable as 8-bit, 16-bit, or 32-bit. */
mbed_official 579:53297373a894 462 enum dma_beat_size beat_size;
mbed_official 579:53297373a894 463 /** Used for enabling the source address increment. */
mbed_official 579:53297373a894 464 bool src_increment_enable;
mbed_official 579:53297373a894 465 /** Used for enabling the destination address increment. */
mbed_official 579:53297373a894 466 bool dst_increment_enable;
mbed_official 579:53297373a894 467 /** This bit selects whether the source or destination address is
mbed_official 579:53297373a894 468 using the step size settings. */
mbed_official 579:53297373a894 469 enum dma_step_selection step_selection;
mbed_official 579:53297373a894 470 /** The step size for source/destination address increment.
mbed_official 579:53297373a894 471 The next address is calculated
mbed_official 579:53297373a894 472 as next_addr = addr + (2^step_size * beat size). */
mbed_official 579:53297373a894 473 enum dma_address_increment_stepsize step_size;
mbed_official 579:53297373a894 474 /** It is the number of beats in a block. This count value is
mbed_official 579:53297373a894 475 * decremented by one after each beat data transfer. */
mbed_official 579:53297373a894 476 uint16_t block_transfer_count;
mbed_official 579:53297373a894 477 /** Transfer source address. */
mbed_official 579:53297373a894 478 uint32_t source_address;
mbed_official 579:53297373a894 479 /** Transfer destination address. */
mbed_official 579:53297373a894 480 uint32_t destination_address;
mbed_official 579:53297373a894 481 /** Set to zero for static descriptors. This must have a valid memory
mbed_official 579:53297373a894 482 address for linked descriptors. */
mbed_official 579:53297373a894 483 uint32_t next_descriptor_address;
mbed_official 579:53297373a894 484 };
mbed_official 579:53297373a894 485
mbed_official 579:53297373a894 486 /** Configurations for DMA events. */
mbed_official 579:53297373a894 487 struct dma_events_config {
mbed_official 579:53297373a894 488 /** Event input actions. */
mbed_official 579:53297373a894 489 enum dma_event_input_action input_action;
mbed_official 579:53297373a894 490 /** Enable DMA event output. */
mbed_official 579:53297373a894 491 bool event_output_enable;
mbed_official 579:53297373a894 492 };
mbed_official 579:53297373a894 493
mbed_official 579:53297373a894 494 /** DMA configurations for transfer. */
mbed_official 579:53297373a894 495 struct dma_resource_config {
mbed_official 579:53297373a894 496 /** DMA transfer priority. */
mbed_official 579:53297373a894 497 enum dma_priority_level priority;
mbed_official 579:53297373a894 498 /**DMA peripheral trigger index. */
mbed_official 579:53297373a894 499 uint8_t peripheral_trigger;
mbed_official 579:53297373a894 500 /** DMA trigger action. */
mbed_official 579:53297373a894 501 enum dma_transfer_trigger_action trigger_action;
mbed_official 579:53297373a894 502 #ifdef FEATURE_DMA_CHANNEL_STANDBY
mbed_official 579:53297373a894 503 /** Keep DMA channel enabled in standby sleep mode if true. */
mbed_official 579:53297373a894 504 bool run_in_standby;
mbed_official 579:53297373a894 505 #endif
mbed_official 579:53297373a894 506 /** DMA events configurations. */
mbed_official 579:53297373a894 507 struct dma_events_config event_config;
mbed_official 579:53297373a894 508 };
mbed_official 579:53297373a894 509
mbed_official 579:53297373a894 510 /** Forward definition of the DMA resource. */
mbed_official 579:53297373a894 511 struct dma_resource;
mbed_official 579:53297373a894 512 /** Type definition for a DMA resource callback function. */
mbed_official 579:53297373a894 513 typedef void (*dma_callback_t)(const struct dma_resource *const resource);
mbed_official 579:53297373a894 514
mbed_official 579:53297373a894 515 /** Structure for DMA transfer resource. */
mbed_official 579:53297373a894 516 struct dma_resource {
mbed_official 579:53297373a894 517 /** Allocated DMA channel ID. */
mbed_official 579:53297373a894 518 uint8_t channel_id;
mbed_official 579:53297373a894 519 /** Array of callback functions for DMA transfer job. */
mbed_official 579:53297373a894 520 dma_callback_t callback[DMA_CALLBACK_N];
mbed_official 579:53297373a894 521 /** Bit mask for enabled callbacks. */
mbed_official 579:53297373a894 522 uint8_t callback_enable;
mbed_official 579:53297373a894 523 /** Status of the last job. */
mbed_official 579:53297373a894 524 volatile enum status_code job_status;
mbed_official 579:53297373a894 525 /** Transferred data size. */
mbed_official 579:53297373a894 526 uint32_t transfered_size;
mbed_official 579:53297373a894 527 /** DMA transfer descriptor. */
mbed_official 579:53297373a894 528 DmacDescriptor* descriptor;
mbed_official 579:53297373a894 529 };
mbed_official 579:53297373a894 530
mbed_official 579:53297373a894 531 /**
mbed_official 579:53297373a894 532 * \brief Get DMA resource status.
mbed_official 579:53297373a894 533 *
mbed_official 579:53297373a894 534 * \param[in] resource Pointer to the DMA resource
mbed_official 579:53297373a894 535 *
mbed_official 579:53297373a894 536 * \return Status of the DMA resource.
mbed_official 579:53297373a894 537 */
mbed_official 579:53297373a894 538 static inline enum status_code dma_get_job_status(struct dma_resource *resource)
mbed_official 579:53297373a894 539 {
mbed_official 579:53297373a894 540 Assert(resource);
mbed_official 579:53297373a894 541
mbed_official 579:53297373a894 542 return resource->job_status;
mbed_official 579:53297373a894 543 }
mbed_official 579:53297373a894 544
mbed_official 579:53297373a894 545 /**
mbed_official 579:53297373a894 546 * \brief Check if the given DMA resource is busy.
mbed_official 579:53297373a894 547 *
mbed_official 579:53297373a894 548 * \param[in] resource Pointer to the DMA resource
mbed_official 579:53297373a894 549 *
mbed_official 579:53297373a894 550 * \return Status which indicates whether the DMA resource is busy.
mbed_official 579:53297373a894 551 *
mbed_official 579:53297373a894 552 * \retval true The DMA resource has an on-going transfer
mbed_official 579:53297373a894 553 * \retval false The DMA resource is not busy
mbed_official 579:53297373a894 554 */
mbed_official 579:53297373a894 555 static inline bool dma_is_busy(struct dma_resource *resource)
mbed_official 579:53297373a894 556 {
mbed_official 579:53297373a894 557 Assert(resource);
mbed_official 579:53297373a894 558
mbed_official 579:53297373a894 559 return (resource->job_status == STATUS_BUSY);
mbed_official 579:53297373a894 560 }
mbed_official 579:53297373a894 561
mbed_official 579:53297373a894 562 /**
mbed_official 579:53297373a894 563 * \brief Enable a callback function for a dedicated DMA resource.
mbed_official 579:53297373a894 564 *
mbed_official 579:53297373a894 565 * \param[in] resource Pointer to the DMA resource
mbed_official 579:53297373a894 566 * \param[in] type Callback function type
mbed_official 579:53297373a894 567 *
mbed_official 579:53297373a894 568 */
mbed_official 579:53297373a894 569 static inline void dma_enable_callback(struct dma_resource *resource,
mbed_official 579:53297373a894 570 enum dma_callback_type type)
mbed_official 579:53297373a894 571 {
mbed_official 579:53297373a894 572 Assert(resource);
mbed_official 579:53297373a894 573
mbed_official 579:53297373a894 574 resource->callback_enable |= 1 << type;
mbed_official 579:53297373a894 575 }
mbed_official 579:53297373a894 576
mbed_official 579:53297373a894 577 /**
mbed_official 579:53297373a894 578 * \brief Disable a callback function for a dedicated DMA resource.
mbed_official 579:53297373a894 579 *
mbed_official 579:53297373a894 580 * \param[in] resource Pointer to the DMA resource
mbed_official 579:53297373a894 581 * \param[in] type Callback function type
mbed_official 579:53297373a894 582 *
mbed_official 579:53297373a894 583 */
mbed_official 579:53297373a894 584 static inline void dma_disable_callback(struct dma_resource *resource,
mbed_official 579:53297373a894 585 enum dma_callback_type type)
mbed_official 579:53297373a894 586 {
mbed_official 579:53297373a894 587 Assert(resource);
mbed_official 579:53297373a894 588
mbed_official 579:53297373a894 589 resource->callback_enable &= ~(1 << type);
mbed_official 579:53297373a894 590 }
mbed_official 579:53297373a894 591
mbed_official 579:53297373a894 592 /**
mbed_official 579:53297373a894 593 * \brief Register a callback function for a dedicated DMA resource.
mbed_official 579:53297373a894 594 *
mbed_official 579:53297373a894 595 * There are three types of callback functions, which can be registered:
mbed_official 579:53297373a894 596 * - Callback for transfer complete
mbed_official 579:53297373a894 597 * - Callback for transfer error
mbed_official 579:53297373a894 598 * - Callback for channel suspend
mbed_official 579:53297373a894 599 *
mbed_official 579:53297373a894 600 * \param[in] resource Pointer to the DMA resource
mbed_official 579:53297373a894 601 * \param[in] callback Pointer to the callback function
mbed_official 579:53297373a894 602 * \param[in] type Callback function type
mbed_official 579:53297373a894 603 *
mbed_official 579:53297373a894 604 */
mbed_official 579:53297373a894 605 static inline void dma_register_callback(struct dma_resource *resource,
mbed_official 579:53297373a894 606 dma_callback_t callback, enum dma_callback_type type)
mbed_official 579:53297373a894 607 {
mbed_official 579:53297373a894 608 Assert(resource);
mbed_official 579:53297373a894 609
mbed_official 579:53297373a894 610 resource->callback[type] = callback;
mbed_official 579:53297373a894 611 }
mbed_official 579:53297373a894 612
mbed_official 579:53297373a894 613 /**
mbed_official 579:53297373a894 614 * \brief Unregister a callback function for a dedicated DMA resource.
mbed_official 579:53297373a894 615 *
mbed_official 579:53297373a894 616 * There are three types of callback functions:
mbed_official 579:53297373a894 617 * - Callback for transfer complete
mbed_official 579:53297373a894 618 * - Callback for transfer error
mbed_official 579:53297373a894 619 * - Callback for channel suspend
mbed_official 579:53297373a894 620 *
mbed_official 579:53297373a894 621 * The application can unregister any of the callback functions which
mbed_official 579:53297373a894 622 * are already registered and are no longer needed.
mbed_official 579:53297373a894 623 *
mbed_official 579:53297373a894 624 * \param[in] resource Pointer to the DMA resource
mbed_official 579:53297373a894 625 * \param[in] type Callback function type
mbed_official 579:53297373a894 626 *
mbed_official 579:53297373a894 627 */
mbed_official 579:53297373a894 628 static inline void dma_unregister_callback(struct dma_resource *resource,
mbed_official 579:53297373a894 629 enum dma_callback_type type)
mbed_official 579:53297373a894 630 {
mbed_official 579:53297373a894 631 Assert(resource);
mbed_official 579:53297373a894 632
mbed_official 579:53297373a894 633 resource->callback[type] = NULL;
mbed_official 579:53297373a894 634 }
mbed_official 579:53297373a894 635
mbed_official 579:53297373a894 636 /**
mbed_official 579:53297373a894 637 * \brief Will set a software trigger for resource.
mbed_official 579:53297373a894 638 *
mbed_official 579:53297373a894 639 * This function is used to set a software trigger on the DMA channel
mbed_official 579:53297373a894 640 * associated with resource. If a trigger is already pending no new trigger
mbed_official 579:53297373a894 641 * will be generated for the channel.
mbed_official 579:53297373a894 642 *
mbed_official 579:53297373a894 643 * \param[in] resource Pointer to the DMA resource
mbed_official 579:53297373a894 644 */
mbed_official 579:53297373a894 645 static inline void dma_trigger_transfer(struct dma_resource *resource)
mbed_official 579:53297373a894 646 {
mbed_official 579:53297373a894 647 Assert(resource);
mbed_official 579:53297373a894 648
mbed_official 579:53297373a894 649 DMAC->SWTRIGCTRL.reg |= (1 << resource->channel_id);
mbed_official 579:53297373a894 650 }
mbed_official 579:53297373a894 651
mbed_official 579:53297373a894 652 /**
mbed_official 579:53297373a894 653 * \brief Initializes DMA transfer configuration with predefined default values.
mbed_official 579:53297373a894 654 *
mbed_official 579:53297373a894 655 * This function will initialize a given DMA descriptor configuration structure to
mbed_official 579:53297373a894 656 * a set of known default values. This function should be called on
mbed_official 579:53297373a894 657 * any new instance of the configuration structure before being
mbed_official 579:53297373a894 658 * modified by the user application.
mbed_official 579:53297373a894 659 *
mbed_official 579:53297373a894 660 * The default configuration is as follows:
mbed_official 579:53297373a894 661 * \li Set the descriptor as valid
mbed_official 579:53297373a894 662 * \li Disable event output
mbed_official 579:53297373a894 663 * \li No block action
mbed_official 579:53297373a894 664 * \li Set beat size as byte
mbed_official 579:53297373a894 665 * \li Enable source increment
mbed_official 579:53297373a894 666 * \li Enable destination increment
mbed_official 579:53297373a894 667 * \li Step size is applied to the destination address
mbed_official 579:53297373a894 668 * \li Address increment is beat size multiplied by 1
mbed_official 579:53297373a894 669 * \li Default transfer size is set to 0
mbed_official 579:53297373a894 670 * \li Default source address is set to NULL
mbed_official 579:53297373a894 671 * \li Default destination address is set to NULL
mbed_official 579:53297373a894 672 * \li Default next descriptor not available
mbed_official 579:53297373a894 673 * \param[out] config Pointer to the configuration
mbed_official 579:53297373a894 674 *
mbed_official 579:53297373a894 675 */
mbed_official 579:53297373a894 676 static inline void dma_descriptor_get_config_defaults(struct dma_descriptor_config *config)
mbed_official 579:53297373a894 677 {
mbed_official 579:53297373a894 678 Assert(config);
mbed_official 579:53297373a894 679
mbed_official 579:53297373a894 680 /* Set descriptor as valid */
mbed_official 579:53297373a894 681 config->descriptor_valid = true;
mbed_official 579:53297373a894 682 /* Disable event output */
mbed_official 579:53297373a894 683 config->event_output_selection = DMA_EVENT_OUTPUT_DISABLE;
mbed_official 579:53297373a894 684 /* No block action */
mbed_official 579:53297373a894 685 config->block_action = DMA_BLOCK_ACTION_NOACT;
mbed_official 579:53297373a894 686 /* Set beat size to one byte */
mbed_official 579:53297373a894 687 config->beat_size = DMA_BEAT_SIZE_BYTE;
mbed_official 579:53297373a894 688 /* Enable source increment */
mbed_official 579:53297373a894 689 config->src_increment_enable = true;
mbed_official 579:53297373a894 690 /* Enable destination increment */
mbed_official 579:53297373a894 691 config->dst_increment_enable = true;
mbed_official 579:53297373a894 692 /* Step size is applied to the destination address */
mbed_official 579:53297373a894 693 config->step_selection = DMA_STEPSEL_DST;
mbed_official 579:53297373a894 694 /* Address increment is beat size multiplied by 1*/
mbed_official 579:53297373a894 695 config->step_size = DMA_ADDRESS_INCREMENT_STEP_SIZE_1;
mbed_official 579:53297373a894 696 /* Default transfer size is set to 0 */
mbed_official 579:53297373a894 697 config->block_transfer_count = 0;
mbed_official 579:53297373a894 698 /* Default source address is set to NULL */
mbed_official 579:53297373a894 699 config->source_address = (uint32_t)NULL;
mbed_official 579:53297373a894 700 /* Default destination address is set to NULL */
mbed_official 579:53297373a894 701 config->destination_address = (uint32_t)NULL;
mbed_official 579:53297373a894 702 /** Next descriptor address set to 0 */
mbed_official 579:53297373a894 703 config->next_descriptor_address = 0;
mbed_official 579:53297373a894 704 }
mbed_official 579:53297373a894 705
mbed_official 579:53297373a894 706 /**
mbed_official 579:53297373a894 707 * \brief Update DMA descriptor.
mbed_official 579:53297373a894 708 *
mbed_official 579:53297373a894 709 * This function can update the descriptor of an allocated DMA resource.
mbed_official 579:53297373a894 710 *
mbed_official 579:53297373a894 711 */
mbed_official 579:53297373a894 712 static inline void dma_update_descriptor(struct dma_resource *resource,
mbed_official 579:53297373a894 713 DmacDescriptor* descriptor)
mbed_official 579:53297373a894 714 {
mbed_official 579:53297373a894 715 Assert(resource);
mbed_official 579:53297373a894 716
mbed_official 579:53297373a894 717 resource->descriptor = descriptor;
mbed_official 579:53297373a894 718 }
mbed_official 579:53297373a894 719
mbed_official 579:53297373a894 720 /**
mbed_official 579:53297373a894 721 * \brief Reset DMA descriptor.
mbed_official 579:53297373a894 722 *
mbed_official 579:53297373a894 723 * This function will clear the DESCADDR register of an allocated DMA resource.
mbed_official 579:53297373a894 724 *
mbed_official 579:53297373a894 725 */
mbed_official 579:53297373a894 726 static inline void dma_reset_descriptor(struct dma_resource *resource)
mbed_official 579:53297373a894 727 {
mbed_official 579:53297373a894 728 Assert(resource);
mbed_official 579:53297373a894 729
mbed_official 579:53297373a894 730 resource->descriptor = NULL;
mbed_official 579:53297373a894 731 }
mbed_official 579:53297373a894 732
mbed_official 579:53297373a894 733 void dma_get_config_defaults(struct dma_resource_config *config);
mbed_official 579:53297373a894 734 enum status_code dma_allocate(struct dma_resource *resource,
mbed_official 579:53297373a894 735 struct dma_resource_config *config);
mbed_official 579:53297373a894 736 enum status_code dma_free(struct dma_resource *resource);
mbed_official 579:53297373a894 737 enum status_code dma_start_transfer_job(struct dma_resource *resource);
mbed_official 579:53297373a894 738 void dma_abort_job(struct dma_resource *resource);
mbed_official 579:53297373a894 739 void dma_suspend_job(struct dma_resource *resource);
mbed_official 579:53297373a894 740 void dma_resume_job(struct dma_resource *resource);
mbed_official 579:53297373a894 741 void dma_descriptor_create(DmacDescriptor* descriptor,
mbed_official 579:53297373a894 742 struct dma_descriptor_config *config);
mbed_official 579:53297373a894 743 enum status_code dma_add_descriptor(struct dma_resource *resource,
mbed_official 579:53297373a894 744 DmacDescriptor* descriptor);
mbed_official 579:53297373a894 745
mbed_official 579:53297373a894 746 /** @} */
mbed_official 579:53297373a894 747
mbed_official 579:53297373a894 748 /**
mbed_official 579:53297373a894 749 * \page asfdoc_sam0_dma_extra Extra Information for DMAC Driver
mbed_official 579:53297373a894 750 *
mbed_official 579:53297373a894 751 * \section asfdoc_sam0_dma_extra_acronyms Acronyms
mbed_official 579:53297373a894 752 * Below is a table listing the acronyms used in this module, along with their
mbed_official 579:53297373a894 753 * intended meanings.
mbed_official 579:53297373a894 754 *
mbed_official 579:53297373a894 755 * <table>
mbed_official 579:53297373a894 756 * <tr>
mbed_official 579:53297373a894 757 * <th>Acronym</th>
mbed_official 579:53297373a894 758 * <th>Description</th>
mbed_official 579:53297373a894 759 * </tr>
mbed_official 579:53297373a894 760 * <tr>
mbed_official 579:53297373a894 761 * <td>DMA</td>
mbed_official 579:53297373a894 762 * <td>Direct Memory Access</td>
mbed_official 579:53297373a894 763 * </tr>
mbed_official 579:53297373a894 764 * <tr>
mbed_official 579:53297373a894 765 * <td>DMAC</td>
mbed_official 579:53297373a894 766 * <td>Direct Memory Access Controller </td>
mbed_official 579:53297373a894 767 * </tr>
mbed_official 579:53297373a894 768 * <tr>
mbed_official 579:53297373a894 769 * <td>CPU</td>
mbed_official 579:53297373a894 770 * <td>Central Processing Unit</td>
mbed_official 579:53297373a894 771 * </tr>
mbed_official 579:53297373a894 772 * </table>
mbed_official 579:53297373a894 773 *
mbed_official 579:53297373a894 774 *
mbed_official 579:53297373a894 775 * \section asfdoc_sam0_dma_extra_dependencies Dependencies
mbed_official 579:53297373a894 776 * This driver has the following dependencies:
mbed_official 579:53297373a894 777 *
mbed_official 579:53297373a894 778 * - \ref asfdoc_sam0_system_clock_group "System Clock Driver"
mbed_official 579:53297373a894 779 *
mbed_official 579:53297373a894 780 *
mbed_official 579:53297373a894 781 * \section asfdoc_sam0_dma_extra_errata Errata
mbed_official 579:53297373a894 782 * There are no errata related to this driver.
mbed_official 579:53297373a894 783 *
mbed_official 579:53297373a894 784 *
mbed_official 579:53297373a894 785 * \section asfdoc_sam0_dma_extra_history Module History
mbed_official 579:53297373a894 786 * An overview of the module history is presented in the table below, with
mbed_official 579:53297373a894 787 * details on the enhancements and fixes made to the module since its first
mbed_official 579:53297373a894 788 * release. The current version of this corresponds to the newest version in
mbed_official 579:53297373a894 789 * the table.
mbed_official 579:53297373a894 790 *
mbed_official 579:53297373a894 791 * <table>
mbed_official 579:53297373a894 792 * <tr>
mbed_official 579:53297373a894 793 * <th>Changelog</th>
mbed_official 579:53297373a894 794 * </tr>
mbed_official 579:53297373a894 795 * <tr>
mbed_official 579:53297373a894 796 * <td>Add SAM L21 support</td>
mbed_official 579:53297373a894 797 * </tr>
mbed_official 579:53297373a894 798 * <tr>
mbed_official 579:53297373a894 799 * <td>Initial Release</td>
mbed_official 579:53297373a894 800 * </tr>
mbed_official 579:53297373a894 801 * </table>
mbed_official 579:53297373a894 802 */
mbed_official 579:53297373a894 803
mbed_official 579:53297373a894 804 /**
mbed_official 579:53297373a894 805 * \page asfdoc_sam0_dma_exqsg Examples for DMAC Driver
mbed_official 579:53297373a894 806 *
mbed_official 579:53297373a894 807 * This is a list of the available Quick Start Guides (QSGs) and example
mbed_official 579:53297373a894 808 * applications for \ref asfdoc_sam0_dma_group. QSGs are simple examples with
mbed_official 579:53297373a894 809 * step-by-step instructions to configure and use this driver in a selection of
mbed_official 579:53297373a894 810 * use cases. Note that QSGs can be compiled as a standalone application or be
mbed_official 579:53297373a894 811 * added to the user application.
mbed_official 579:53297373a894 812 *
mbed_official 579:53297373a894 813 * - \subpage asfdoc_sam0_dma_basic_use_case
mbed_official 579:53297373a894 814 *
mbed_official 579:53297373a894 815 * \note More DMA usage examples are available in peripheral QSGs.
mbed_official 579:53297373a894 816 * A quick start guide for TC/TCC
mbed_official 579:53297373a894 817 * shows the usage of DMA event trigger; SERCOM SPI/USART/I<SUP>2</SUP>C has example for
mbed_official 579:53297373a894 818 * DMA transfer from peripheral to memory or from memory to peripheral;
mbed_official 579:53297373a894 819 * ADC/DAC shows peripheral to peripheral transfer.
mbed_official 579:53297373a894 820 *
mbed_official 579:53297373a894 821 * \page asfdoc_sam0_dma_document_revision_history Document Revision History
mbed_official 579:53297373a894 822 *
mbed_official 579:53297373a894 823 * <table>
mbed_official 579:53297373a894 824 * <tr>
mbed_official 579:53297373a894 825 * <th>Doc. Rev.</td>
mbed_official 579:53297373a894 826 * <th>Date</td>
mbed_official 579:53297373a894 827 * <th>Comments</td>
mbed_official 579:53297373a894 828 * </tr>
mbed_official 579:53297373a894 829 * <tr>
mbed_official 579:53297373a894 830 * <td>C</td>
mbed_official 579:53297373a894 831 * <td>11/2014</td>
mbed_official 579:53297373a894 832 * <td>Added SAML21 support</td>
mbed_official 579:53297373a894 833 * </tr>
mbed_official 579:53297373a894 834 * <tr>
mbed_official 579:53297373a894 835 * <td>B</td>
mbed_official 579:53297373a894 836 * <td>12/2014</td>
mbed_official 579:53297373a894 837 * <td>Added SAMR21 and SAMD10/D11 support</td>
mbed_official 579:53297373a894 838 * </tr>
mbed_official 579:53297373a894 839 * <tr>
mbed_official 579:53297373a894 840 * <td>A</td>
mbed_official 579:53297373a894 841 * <td>02/2014</td>
mbed_official 579:53297373a894 842 * <td>Initial release</td>
mbed_official 579:53297373a894 843 * </tr>
mbed_official 579:53297373a894 844 * </table>
mbed_official 579:53297373a894 845 */
mbed_official 579:53297373a894 846
mbed_official 579:53297373a894 847 #ifdef __cplusplus
mbed_official 579:53297373a894 848 }
mbed_official 579:53297373a894 849 #endif
mbed_official 579:53297373a894 850
mbed_official 579:53297373a894 851 #endif /* DMA_H_INCLUDED */