This allows a single user of a DMA channel to reserve it for use
without needing to lock the mutex; this is required for DMA from the
ADC to work on megametrum as it wants to start DMA from an interrupt
handler, which cannot block on a mutex.
Signed-off-by: Keith Packard <keithp@keithp.com>
/* Clear any stale status bits */
stm_adc.sr = 0;
ao_adc_ready = 1;
/* Clear any stale status bits */
stm_adc.sr = 0;
ao_adc_ready = 1;
+
+ ao_dma_alloc(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1));
ao_cmd_register(&ao_adc_cmds[0]);
}
ao_cmd_register(&ao_adc_cmds[0]);
}
void
ao_dma_abort(uint8_t index);
void
ao_dma_abort(uint8_t index);
+void
+ao_dma_alloc(uint8_t index);
+
uint8_t ao_dma_done[NUM_DMA];
static struct ao_dma_config ao_dma_config[NUM_DMA];
uint8_t ao_dma_done[NUM_DMA];
static struct ao_dma_config ao_dma_config[NUM_DMA];
+static uint8_t ao_dma_allocated[NUM_DMA];
static uint8_t ao_dma_mutex[NUM_DMA];
static uint8_t ao_dma_active;
static uint8_t ao_dma_mutex[NUM_DMA];
static uint8_t ao_dma_active;
uint16_t count,
uint32_t ccr)
{
uint16_t count,
uint32_t ccr)
{
- ao_mutex_get(&ao_dma_mutex[index]);
+ if (ao_dma_allocated[index]) {
+ if (ao_dma_mutex[index])
+ ao_panic(AO_PANIC_DMA);
+ ao_dma_mutex[index] = 1;
+ } else
+ ao_mutex_get(&ao_dma_mutex[index]);
ao_arch_critical(
if (ao_dma_active++ == 0)
stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_DMA1EN);
ao_arch_critical(
if (ao_dma_active++ == 0)
stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_DMA1EN);
if (--ao_dma_active == 0)
stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_DMA1EN);
);
if (--ao_dma_active == 0)
stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_DMA1EN);
);
- ao_mutex_put(&ao_dma_mutex[index]);
+ if (ao_dma_allocated[index])
+ ao_dma_mutex[index] = 0;
+ else
+ ao_mutex_put(&ao_dma_mutex[index]);
stm_dma.channel[index].ccr &= ~(1 << STM_DMA_CCR_EN);
}
stm_dma.channel[index].ccr &= ~(1 << STM_DMA_CCR_EN);
}
+void
+ao_dma_alloc(uint8_t index)
+{
+ if (ao_dma_allocated[index])
+ ao_panic(AO_PANIC_DMA);
+ ao_dma_allocated[index] = 1;
+}
+
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);
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);
+ ao_dma_allocated[index] = 0;
+ ao_dma_mutex[index] = 0;