Use the cached value of useDshotTelemetry to ensure consistent runtime use if dshot_b...
[betaflight.git] / src / main / drivers / dma_common.c
blob47338bc77c3c0bc5c2cc6e5b8ae33b4e1bc25ef8
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include "platform.h"
23 #ifdef USE_DMA
25 #include "drivers/dma_impl.h"
27 #include "dma.h"
29 dmaIdentifier_e dmaAllocate(dmaIdentifier_e identifier, resourceOwner_e owner, uint8_t resourceIndex)
31 if (dmaGetOwner(identifier)->owner != OWNER_FREE) {
32 return DMA_NONE;
35 const int index = DMA_IDENTIFIER_TO_INDEX(identifier);
36 dmaDescriptors[index].owner.owner = owner;
37 dmaDescriptors[index].owner.resourceIndex = resourceIndex;
39 return identifier;
42 const resourceOwner_t *dmaGetOwner(dmaIdentifier_e identifier)
44 return &dmaDescriptors[DMA_IDENTIFIER_TO_INDEX(identifier)].owner;
47 dmaIdentifier_e dmaGetIdentifier(const dmaResource_t* channel)
49 for (int i = 0; i < DMA_LAST_HANDLER; i++) {
50 if (dmaDescriptors[i].ref == channel) {
51 return i + 1;
55 return 0;
58 dmaChannelDescriptor_t* dmaGetDescriptorByIdentifier(const dmaIdentifier_e identifier)
60 return &dmaDescriptors[DMA_IDENTIFIER_TO_INDEX(identifier)];
63 uint32_t dmaGetChannel(const uint8_t channel)
65 return ((uint32_t)channel*2)<<24;
67 #endif