summaryrefslogtreecommitdiff
path: root/src/stmf0/ao_adc_fast.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2015-03-20 15:09:20 -0700
committerKeith Packard <keithp@keithp.com>2015-03-20 15:09:20 -0700
commitb1b69c8b73cbffb56c688f6a968d144b642cdff2 (patch)
treee54eb4ccbed98014a6ccce31d6144b5a3e2866f1 /src/stmf0/ao_adc_fast.c
parent43b4044dc71d44cb25be6397b4d66fd792580eed (diff)
altos/stmf0: Have fast ADC ring buffer code use wrap-around
Instead of requiring that the whole set of returned values fit precisely in the ring, allow for wrap-around so that we can fetch an odd number of ADC values. The previous version required that the fetch amount always be a factor of the ADC buffer size. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/stmf0/ao_adc_fast.c')
-rw-r--r--src/stmf0/ao_adc_fast.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/stmf0/ao_adc_fast.c b/src/stmf0/ao_adc_fast.c
index 7d2a4fd7..26e6691c 100644
--- a/src/stmf0/ao_adc_fast.c
+++ b/src/stmf0/ao_adc_fast.c
@@ -23,7 +23,7 @@ uint16_t ao_adc_ring[AO_ADC_RING_SIZE] __attribute__((aligned(4)));
/* Maximum number of samples fetched per _ao_adc_start call */
#define AO_ADC_RING_CHUNK (AO_ADC_RING_SIZE >> 1)
-uint16_t ao_adc_ring_head, ao_adc_ring_tail;
+uint16_t ao_adc_ring_head, ao_adc_ring_remain;
uint16_t ao_adc_running;
/*
@@ -36,6 +36,7 @@ static void ao_adc_dma_done(int index)
{
(void) index;
ao_adc_ring_head += ao_adc_running;
+ ao_adc_ring_remain += ao_adc_running;
if (ao_adc_ring_head == AO_ADC_RING_SIZE)
ao_adc_ring_head = 0;
ao_adc_running = 0;