1 /* 2 * Copyright (c) 2016 Erik Gilling 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 #pragma once 9 10 #include <stdint.h> 11 12 typedef enum { 13 DMA_CHANNEL_1 = 1, 14 DMA_CHANNEL_2 = 2, 15 DMA_CHANNEL_3 = 3, 16 DMA_CHANNEL_4 = 4, 17 DMA_CHANNEL_5 = 5, 18 DMA_CHANNEL_6 = 6, 19 DMA_CHANNEL_7 = 7, 20 } dma_channel_t; 21 22 #define DMA_CHANNELS 7 23 24 #define DMA_FLAG_FROM_PERIPH (0 << 4) 25 #define DMA_FLAG_FROM_MEM (1 << 4) 26 #define DMA_FLAG_PERIPH_INCREMENT (1 << 6) 27 #define DMA_FLAG_MEM_INCREMENT (1 << 7) 28 #define DMA_FLAG_PERIPH_8_BIT (0 << 8) 29 #define DMA_FLAG_PERIPH_16_BIT (1 << 8) 30 #define DMA_FLAG_PERIPH_32_BIT (2 << 8) 31 #define DMA_FLAG_MEM_8_BIT (0 << 10) 32 #define DMA_FLAG_MEM_16_BIT (1 << 10) 33 #define DMA_FLAG_MEM_32_BIT (2 << 10) 34 #define DMA_FLAG_PRIORITY(x) (((x) & 0x3) << 12) 35 36 /** 37 * dmi_init 38 * 39 * Initialize the DMA peripheral. 40 */ 41 void dma_init(void); 42 43 /** 44 * dma_transfer_start 45 * 46 * Initiate a DMA transfer. 47 * 48 * @param[in] chan DMA channel. 49 * @param[in] periph_addr Address of the peripheral register for the transfer. 50 * @param[in] mem_addr Address of the memory of the transfer. 51 * @param[in] count Number of cycles to transfer. 52 * @param[in] flags Flags to control the transfer (see DMA_FLAG_*.) 53 */ 54 55 void dma_transfer_start(dma_channel_t chan, 56 uint32_t periph_addr, 57 uint32_t mem_addr, 58 uint16_t count, 59 uint32_t flags); 60 61 /** 62 * dma_wait 63 * 64 * Wait for a DMA transaction to complete. 65 * TODO(konkers): Add timeout support. 66 * TODO(konkers): Add error reporting. 67 * 68 * @param[in] chan DMA channel. 69 */ 70 void dma_wait(dma_channel_t chan); 71 72