summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2012-04-06 22:39:45 -0700
committerKeith Packard <keithp@keithp.com>2012-04-06 22:39:45 -0700
commit0bcc23c3be1a20a362fea268901c600f9f0d287a (patch)
treef6fc4cc475779daddfeeda22c8e3f29eb834a8e4 /src
parent20926b62a87154a846cb950dc542c737cd54826d (diff)
altos: Disable DMA unit when idle
Should save a bit of power Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
-rw-r--r--src/stm/ao_dma_stm.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/stm/ao_dma_stm.c b/src/stm/ao_dma_stm.c
index 70b9e48a..f996e7cd 100644
--- a/src/stm/ao_dma_stm.c
+++ b/src/stm/ao_dma_stm.c
@@ -27,6 +27,7 @@ uint8_t ao_dma_done[NUM_DMA];
static struct ao_dma_config ao_dma_config[NUM_DMA];
static uint8_t ao_dma_mutex[NUM_DMA];
+static uint8_t ao_dma_active;
static void
ao_dma_isr(uint8_t index) {
@@ -58,10 +59,12 @@ ao_dma_set_transfer(uint8_t index,
uint32_t ccr)
{
ao_mutex_get(&ao_dma_mutex[index]);
+ if (ao_dma_active++ == 0)
+ stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_DMA1EN);
stm_dma.channel[index].ccr = ccr | (1 << STM_DMA_CCR_TCIE);
stm_dma.channel[index].cndtr = count;
- stm_dma.channel[index].cpar = (uint32_t) peripheral;
- stm_dma.channel[index].cmar = (uint32_t) memory;
+ stm_dma.channel[index].cpar = peripheral;
+ stm_dma.channel[index].cmar = memory;
}
void
@@ -75,6 +78,8 @@ void
ao_dma_done_transfer(uint8_t index)
{
stm_dma.channel[index].ccr &= ~(1 << STM_DMA_CCR_EN);
+ if (--ao_dma_active == 0)
+ stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_DMA1EN);
ao_mutex_put(&ao_dma_mutex[index]);
}
@@ -89,8 +94,6 @@ ao_dma_init(void)
{
int index;
- stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_DMA1EN);
-
for (index = 0; index < STM_NUM_DMA; index++) {
stm_nvic_set_enable(STM_ISR_DMA1_CHANNEL1_POS + index);
stm_nvic_set_priority(STM_ISR_DMA1_CHANNEL1_POS + index, 4);