2 * Copyright © 2015 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 #ifndef _AO_ADC_FAST_H_
19 #define _AO_ADC_FAST_H_
22 ao_adc_read(uint16_t *dest, int len);
27 /* Total ring size in samples */
28 #define AO_ADC_RING_SIZE 256
30 extern uint16_t ao_adc_ring[AO_ADC_RING_SIZE];
32 #define ao_adc_ring_step(pos,inc) (((pos) + (inc)) & (AO_ADC_RING_SIZE - 1))
34 extern uint16_t ao_adc_ring_head, ao_adc_ring_tail;
35 extern uint16_t ao_adc_running;
40 static inline uint16_t
43 if (ao_adc_ring_tail > ao_adc_ring_head)
44 return AO_ADC_RING_SIZE - ao_adc_ring_tail;
45 return ao_adc_ring_head - ao_adc_ring_tail;
48 static inline uint16_t
51 if (ao_adc_ring_head >= ao_adc_ring_tail)
52 return AO_ADC_RING_SIZE - ao_adc_ring_head;
53 return ao_adc_ring_tail - ao_adc_ring_head;
56 static inline uint16_t *
57 ao_adc_get(uint16_t n)
59 if (ao_adc_ring_tail + n > AO_ADC_RING_SIZE)
60 ao_panic(AO_PANIC_ADC);
61 ao_arch_block_interrupts();
62 while (_ao_adc_remain() < n) {
65 ao_sleep(&ao_adc_ring_head);
67 ao_arch_release_interrupts();
68 return &ao_adc_ring[ao_adc_ring_tail];
72 ao_adc_ack(uint16_t n)
74 if (ao_adc_ring_tail + n > AO_ADC_RING_SIZE)
75 ao_panic(AO_PANIC_ADC);
76 ao_arch_block_interrupts();
77 ao_adc_ring_tail += n;
78 if (ao_adc_ring_tail == AO_ADC_RING_SIZE)
82 ao_arch_release_interrupts();
85 #endif /* _AO_ADC_FAST_H_ */