2 * This file is part of Betaflight.
4 * Betaflight is free software. You can redistribute this software
5 * and/or modify this software under the terms of the GNU General
6 * Public License as published by the Free Software Foundation,
7 * either version 3 of the License, or (at your option) any later
10 * Betaflight is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this software.
19 * If not, see <http://www.gnu.org/licenses/>.
25 #include "drivers/resource.h"
45 DMA_LAST_HANDLER
= DMA2_ST7_HANDLER
48 #define DMA_DEVICE_NO(x) ((((x)-1) / 8) + 1)
49 #define DMA_DEVICE_INDEX(x) ((((x)-1) % 8))
50 #define DMA_OUTPUT_INDEX 0
51 #define DMA_OUTPUT_STRING "DMA%d Stream %d:"
52 #define DMA_INPUT_STRING "DMA%d_ST%d"
54 #define DEFINE_DMA_CHANNEL(d, s, f) { \
56 .ref = (dmaResource_t *)d ## _Stream ## s, \
58 .irqHandlerCallback = NULL, \
60 .irqN = d ## _Stream ## s ## _IRQn, \
63 .owner.resourceIndex = 0 \
66 #define DEFINE_DMA_IRQ_HANDLER(d, s, i) FAST_IRQ_HANDLER void DMA ## d ## _STR ## s ## _IRQHandler(void) {\
67 const uint8_t index = DMA_IDENTIFIER_TO_INDEX(i); \
68 dmaCallbackHandlerFuncPtr handler = dmaDescriptors[index].irqHandlerCallback; \
70 handler(&dmaDescriptors[index]); \
73 #define DMA_CLEAR_FLAG(d, flag) if (d->flagsShift > 31) d->dma->HIFCLR = (flag << (d->flagsShift - 32)); else d->dma->LIFCLR = (flag << d->flagsShift)
74 #define DMA_GET_FLAG_STATUS(d, flag) (d->flagsShift > 31 ? d->dma->HINTSTS & (flag << (d->flagsShift - 32)): d->dma->LINTSTS & (flag << d->flagsShift))
76 #define xDDL_EX_DMA_DeInit(dmaResource) DDL_EX_DMA_DeInit((DMA_ARCH_TYPE *)(dmaResource))
77 #define xDDL_EX_DMA_Init(dmaResource, initstruct) DDL_EX_DMA_Init((DMA_ARCH_TYPE *)(dmaResource), initstruct)
78 #define xDDL_EX_DMA_DisableResource(dmaResource) DDL_EX_DMA_DisableResource((DMA_ARCH_TYPE *)(dmaResource))
79 #define xDDL_EX_DMA_EnableResource(dmaResource) DDL_EX_DMA_EnableResource((DMA_ARCH_TYPE *)(dmaResource))
80 #define xDDL_EX_DMA_GetDataLength(dmaResource) DDL_EX_DMA_GetDataLength((DMA_ARCH_TYPE *)(dmaResource))
81 #define xDDL_EX_DMA_SetDataLength(dmaResource, length) DDL_EX_DMA_SetDataLength((DMA_ARCH_TYPE *)(dmaResource), length)
82 #define xDDL_EX_DMA_EnableIT_TC(dmaResource) DDL_EX_DMA_EnableIT_TC((DMA_ARCH_TYPE *)(dmaResource))
84 #define DMA_IT_TCIF ((uint32_t)0x00000020)
85 #define DMA_IT_HTIF ((uint32_t)0x00000010)
86 #define DMA_IT_TEIF ((uint32_t)0x00000008)
87 #define DMA_IT_DMEIF ((uint32_t)0x00000004)
88 #define DMA_IT_FEIF ((uint32_t)0x00000001)
90 void dmaMuxEnable(dmaIdentifier_e identifier
, uint32_t dmaMuxId
);