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)
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/>.
25 #include "drivers/dma_impl.h"
29 dmaIdentifier_e
dmaAllocate(dmaIdentifier_e identifier
, resourceOwner_e owner
, uint8_t resourceIndex
)
31 if (dmaGetOwner(identifier
)->owner
!= OWNER_FREE
) {
35 const int index
= DMA_IDENTIFIER_TO_INDEX(identifier
);
36 dmaDescriptors
[index
].owner
.owner
= owner
;
37 dmaDescriptors
[index
].owner
.resourceIndex
= resourceIndex
;
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
) {
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;