Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-src by
targets/hal/TARGET_Silicon_Labs/TARGET_EFM32/dma_api.c@548:1abac31e188e, 2015-05-22 (annotated)
- Committer:
- mbed_official
- Date:
- Fri May 22 10:45:46 2015 +0100
- Revision:
- 548:1abac31e188e
- Parent:
- 525:c320967f86b9
- Child:
- 627:4fa1328d9c60
Synchronized with git revision 88d158e43b54f97c5e94da305ea9a096889cc81b
Full URL: https://github.com/mbedmicro/mbed/commit/88d158e43b54f97c5e94da305ea9a096889cc81b/
Silicon Labs - Cosmetic: apply mbed coding style to HAL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 525:c320967f86b9 | 1 | /* mbed Microcontroller Library |
mbed_official | 525:c320967f86b9 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 525:c320967f86b9 | 3 | * |
mbed_official | 525:c320967f86b9 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 525:c320967f86b9 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 525:c320967f86b9 | 6 | * You may obtain a copy of the License at |
mbed_official | 525:c320967f86b9 | 7 | * |
mbed_official | 525:c320967f86b9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 525:c320967f86b9 | 9 | * |
mbed_official | 525:c320967f86b9 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 525:c320967f86b9 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 525:c320967f86b9 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 525:c320967f86b9 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 525:c320967f86b9 | 14 | * limitations under the License. |
mbed_official | 525:c320967f86b9 | 15 | */ |
mbed_official | 525:c320967f86b9 | 16 | |
mbed_official | 525:c320967f86b9 | 17 | #include <stdint.h> |
mbed_official | 525:c320967f86b9 | 18 | #include "dma_api_HAL.h" |
mbed_official | 525:c320967f86b9 | 19 | #include "em_dma.h" |
mbed_official | 525:c320967f86b9 | 20 | #include "em_cmu.h" |
mbed_official | 525:c320967f86b9 | 21 | |
mbed_official | 525:c320967f86b9 | 22 | /** DMA control block array, requires proper alignment. */ |
mbed_official | 525:c320967f86b9 | 23 | #if defined (__ICCARM__) |
mbed_official | 525:c320967f86b9 | 24 | #pragma data_alignment=DMACTRL_ALIGNMENT |
mbed_official | 525:c320967f86b9 | 25 | DMA_DESCRIPTOR_TypeDef dmaControlBlock[DMACTRL_CH_CNT * 2]; |
mbed_official | 525:c320967f86b9 | 26 | |
mbed_official | 525:c320967f86b9 | 27 | #elif defined (__CC_ARM) |
mbed_official | 525:c320967f86b9 | 28 | DMA_DESCRIPTOR_TypeDef dmaControlBlock[DMACTRL_CH_CNT * 2] __attribute__ ((aligned(DMACTRL_ALIGNMENT))); |
mbed_official | 525:c320967f86b9 | 29 | |
mbed_official | 525:c320967f86b9 | 30 | #elif defined (__GNUC__) |
mbed_official | 525:c320967f86b9 | 31 | DMA_DESCRIPTOR_TypeDef dmaControlBlock[DMACTRL_CH_CNT * 2] __attribute__ ((aligned(DMACTRL_ALIGNMENT), section("dma"))); |
mbed_official | 525:c320967f86b9 | 32 | |
mbed_official | 525:c320967f86b9 | 33 | #else |
mbed_official | 525:c320967f86b9 | 34 | #error Undefined toolkit, need to define alignment |
mbed_official | 525:c320967f86b9 | 35 | #endif |
mbed_official | 525:c320967f86b9 | 36 | |
mbed_official | 525:c320967f86b9 | 37 | uint32_t channels = 0; // Bit vector of taken channels |
mbed_official | 525:c320967f86b9 | 38 | bool enabled = false; |
mbed_official | 525:c320967f86b9 | 39 | |
mbed_official | 525:c320967f86b9 | 40 | void dma_init(void) |
mbed_official | 525:c320967f86b9 | 41 | { |
mbed_official | 548:1abac31e188e | 42 | if (enabled) return; |
mbed_official | 548:1abac31e188e | 43 | DMA_Init_TypeDef dmaInit; |
mbed_official | 525:c320967f86b9 | 44 | |
mbed_official | 548:1abac31e188e | 45 | CMU_ClockEnable(cmuClock_DMA, true); |
mbed_official | 548:1abac31e188e | 46 | CMU_ClockEnable(cmuClock_HFPER, true); |
mbed_official | 525:c320967f86b9 | 47 | |
mbed_official | 548:1abac31e188e | 48 | /* Configure general DMA issues */ |
mbed_official | 548:1abac31e188e | 49 | dmaInit.hprot = 0; |
mbed_official | 548:1abac31e188e | 50 | dmaInit.controlBlock = dmaControlBlock; |
mbed_official | 548:1abac31e188e | 51 | DMA_Init(&dmaInit); |
mbed_official | 548:1abac31e188e | 52 | enabled = true; |
mbed_official | 525:c320967f86b9 | 53 | } |
mbed_official | 525:c320967f86b9 | 54 | |
mbed_official | 525:c320967f86b9 | 55 | int dma_channel_allocate(uint32_t capabilities) |
mbed_official | 525:c320967f86b9 | 56 | { |
mbed_official | 548:1abac31e188e | 57 | int i; |
mbed_official | 548:1abac31e188e | 58 | // Check if 2d copy is required |
mbed_official | 548:1abac31e188e | 59 | if (DMA_CAP_2DCOPY & capabilities) { |
mbed_official | 548:1abac31e188e | 60 | if (channels & 1) { |
mbed_official | 548:1abac31e188e | 61 | // Channel already in use |
mbed_official | 548:1abac31e188e | 62 | return DMA_ERROR_OUT_OF_CHANNELS; |
mbed_official | 548:1abac31e188e | 63 | } else { |
mbed_official | 548:1abac31e188e | 64 | channels |= 1 << 0; |
mbed_official | 548:1abac31e188e | 65 | return 0; |
mbed_official | 548:1abac31e188e | 66 | } |
mbed_official | 525:c320967f86b9 | 67 | } |
mbed_official | 548:1abac31e188e | 68 | for (i = 1; i < DMA_CHAN_COUNT; i++) { |
mbed_official | 548:1abac31e188e | 69 | if ((channels & (1 << i)) == 0) { |
mbed_official | 548:1abac31e188e | 70 | // Channel available |
mbed_official | 548:1abac31e188e | 71 | channels |= 1 << i; |
mbed_official | 548:1abac31e188e | 72 | return i; |
mbed_official | 548:1abac31e188e | 73 | } |
mbed_official | 525:c320967f86b9 | 74 | } |
mbed_official | 548:1abac31e188e | 75 | // Check if channel 0 is available |
mbed_official | 548:1abac31e188e | 76 | if ((channels & 1 ) == 0) { |
mbed_official | 548:1abac31e188e | 77 | channels |= 1 << 0; |
mbed_official | 548:1abac31e188e | 78 | return 0; |
mbed_official | 548:1abac31e188e | 79 | } |
mbed_official | 548:1abac31e188e | 80 | // Couldn't find a channel. |
mbed_official | 548:1abac31e188e | 81 | return DMA_ERROR_OUT_OF_CHANNELS; |
mbed_official | 525:c320967f86b9 | 82 | } |
mbed_official | 525:c320967f86b9 | 83 | |
mbed_official | 548:1abac31e188e | 84 | int dma_channel_free(int channelid) |
mbed_official | 525:c320967f86b9 | 85 | { |
mbed_official | 548:1abac31e188e | 86 | channels &= ~(1 << channelid); |
mbed_official | 548:1abac31e188e | 87 | return 0; |
mbed_official | 525:c320967f86b9 | 88 | } |
mbed_official | 525:c320967f86b9 | 89 |