X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fstmf0%2Fao_adc_fast.c;h=be9b5986778d51ff95310a1e72f2f9884bd33eb0;hp=5885ae4fba748379d22bb2f120f803a4952812d6;hb=8ca1f234586225caea1040bc229b63491dadc1cb;hpb=3749426af1e900a1b3354922fdd7e8b3bfa38084 diff --git a/src/stmf0/ao_adc_fast.c b/src/stmf0/ao_adc_fast.c index 5885ae4f..be9b5986 100644 --- a/src/stmf0/ao_adc_fast.c +++ b/src/stmf0/ao_adc_fast.c @@ -18,7 +18,10 @@ #include #include -static uint8_t ao_adc_done; +uint16_t ao_adc_ring[AO_ADC_RING_SIZE]; + +uint16_t ao_adc_ring_head, ao_adc_ring_tail; +uint8_t ao_adc_running; /* * Callback from DMA ISR @@ -28,22 +31,30 @@ static uint8_t ao_adc_done; static void ao_adc_dma_done(int index) { (void) index; - ao_adc_done = 1; - ao_wakeup(&ao_adc_done); + ao_adc_ring_head += AO_ADC_RING_CHUNK; + if (ao_adc_ring_head == AO_ADC_RING_SIZE) + ao_adc_ring_head = 0; + ao_adc_running = 0; + ao_wakeup(&ao_adc_ring_head); + ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC_1)); } -/* - * Start the ADC sequence using the DMA engine - */ void -ao_adc_read(uint16_t *dest, int len) +_ao_adc_start(void) { - ao_adc_done = 0; + uint16_t *buf; + + if (ao_adc_running) + return; + if (_ao_adc_space() < AO_ADC_RING_CHUNK) + return; + ao_adc_running = 1; + buf = ao_adc_ring + ao_adc_ring_head; stm_adc.isr = 0; ao_dma_set_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC_1), &stm_adc.dr, - dest, - len, + buf, + AO_ADC_RING_CHUNK, (0 << STM_DMA_CCR_MEM2MEM) | (STM_DMA_CCR_PL_HIGH << STM_DMA_CCR_PL) | (STM_DMA_CCR_MSIZE_16 << STM_DMA_CCR_MSIZE) | @@ -56,16 +67,6 @@ ao_adc_read(uint16_t *dest, int len) ao_dma_start(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC_1)); stm_adc.cr |= (1 << STM_ADC_CR_ADSTART); - ao_arch_block_interrupts(); - while (!ao_adc_done) - ao_sleep(&ao_adc_done); - ao_arch_release_interrupts(); - - ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC_1)); - - stm_adc.cr |= (1 << STM_ADC_CR_ADSTP); - while ((stm_adc.cr & (1 << STM_ADC_CR_ADSTP)) != 0) - ; } void @@ -185,4 +186,5 @@ ao_adc_init(void) stm_syscfg.cfgr1 &= ~(1 << STM_SYSCFG_CFGR1_ADC_DMA_RMP); ao_dma_alloc(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC_1)); + ao_dma_set_isr(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC_1), ao_adc_dma_done); }