2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
22 struct dmaChannelDescriptor_s
;
23 typedef void (*dmaCallbackHandlerFuncPtr
)(struct dmaChannelDescriptor_s
*channelDescriptor
);
25 typedef struct dmaChannelDescriptor_s
{
27 #if defined(STM32F4) || defined(STM32F7)
28 DMA_Stream_TypeDef
* ref
;
30 DMA_Channel_TypeDef
* ref
;
32 dmaCallbackHandlerFuncPtr irqHandlerCallback
;
37 resourceOwner_e owner
;
38 uint8_t resourceIndex
;
39 } dmaChannelDescriptor_t
;
42 //#define HAL_CLEANINVALIDATECACHE(addr, size) (SCB_CleanInvalidateDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)(addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
43 //#define HAL_CLEANCACHE(addr, size) (SCB_CleanDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)(addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
46 #if defined(STM32F4) || defined(STM32F7)
47 uint32_t dmaFlag_IT_TCIF(const DMA_Stream_TypeDef
*stream
);
69 #define DMA_MOD_VALUE 8
70 #define DMA_MOD_OFFSET 0
71 #define DMA_OUTPUT_INDEX 0
72 #define DMA_OUTPUT_STRING "DMA%d Stream %d:"
74 #define DEFINE_DMA_CHANNEL(d, s, f, i, r) {.dma = d, .ref = s, .irqHandlerCallback = NULL, .flagsShift = f, .irqN = i, .rcc = r, .userParam = 0, .owner = 0, .resourceIndex = 0 }
75 #define DEFINE_DMA_IRQ_HANDLER(d, s, i) void DMA ## d ## _Stream ## s ## _IRQHandler(void) {\
76 if (dmaDescriptors[i].irqHandlerCallback)\
77 dmaDescriptors[i].irqHandlerCallback(&dmaDescriptors[i]);\
80 #define DMA_CLEAR_FLAG(d, flag) if(d->flagsShift > 31) d->dma->HIFCR = (flag << (d->flagsShift - 32)); else d->dma->LIFCR = (flag << d->flagsShift)
81 #define DMA_GET_FLAG_STATUS(d, flag) (d->flagsShift > 31 ? d->dma->HISR & (flag << (d->flagsShift - 32)): d->dma->LISR & (flag << d->flagsShift))
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 dmaIdentifier_e
dmaGetIdentifier(const DMA_Stream_TypeDef
* stream
);
91 dmaChannelDescriptor_t
* getDmaDescriptor(const DMA_Stream_TypeDef
* stream
);
103 #if defined(STM32F3) || defined(STM32F10X_CL)
113 #define DMA_MOD_VALUE 7
114 #define DMA_MOD_OFFSET 1
115 #define DMA_OUTPUT_INDEX 0
116 #define DMA_OUTPUT_STRING "DMA%d Channel %d:"
118 #define DEFINE_DMA_CHANNEL(d, c, f, i, r) {.dma = d, .ref = c, .irqHandlerCallback = NULL, .flagsShift = f, .irqN = i, .rcc = r, .userParam = 0, .owner = 0, .resourceIndex = 0 }
119 #define DEFINE_DMA_IRQ_HANDLER(d, c, i) void DMA ## d ## _Channel ## c ## _IRQHandler(void) {\
120 if (dmaDescriptors[i].irqHandlerCallback)\
121 dmaDescriptors[i].irqHandlerCallback(&dmaDescriptors[i]);\
124 #define DMA_CLEAR_FLAG(d, flag) d->dma->IFCR = (flag << d->flagsShift)
125 #define DMA_GET_FLAG_STATUS(d, flag) (d->dma->ISR & (flag << d->flagsShift))
127 #define DMA_IT_TCIF ((uint32_t)0x00000002)
128 #define DMA_IT_HTIF ((uint32_t)0x00000004)
129 #define DMA_IT_TEIF ((uint32_t)0x00000008)
131 dmaIdentifier_e
dmaGetIdentifier(const DMA_Channel_TypeDef
* channel
);
135 void dmaInit(dmaIdentifier_e identifier
, resourceOwner_e owner
, uint8_t resourceIndex
);
136 void dmaSetHandler(dmaIdentifier_e identifier
, dmaCallbackHandlerFuncPtr callback
, uint32_t priority
, uint32_t userParam
);
138 resourceOwner_e
dmaGetOwner(dmaIdentifier_e identifier
);
139 uint8_t dmaGetResourceIndex(dmaIdentifier_e identifier
);