aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2011-03-12 01:10:40 +0000
committerDimitri Sokolyuk <demon@dim13.org>2011-03-12 01:10:40 +0000
commit8d9da58254aabb37d2c76414ba5a1a6e43518f45 (patch)
tree2c9bb960a34dba0c938d2dee58e0d8cfdfce73fb /kernel
parent1026e533722f68fbcaa0167c4c172540afcabeba (diff)
add ADC prescale flag
Diffstat (limited to 'kernel')
-rw-r--r--kernel/Makefile4
-rw-r--r--kernel/adc.c3
-rw-r--r--kernel/kernel.h20
3 files changed, 24 insertions, 3 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index 0807a73..810c3d5 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -10,6 +10,7 @@ STACK = 64
TASKS = 8
SEMAPHORES = 8
BAUD = 9600
+ADCPRESCALE = 8
# You should not have to change anything below here.
@@ -20,7 +21,8 @@ SIZE = avr-size
OBJS = ${SRCS:.c=.o}
CFLAGS = -Wall -Os -mmcu=${MCU_TARGET} \
-DF_CPU=${F_CPU} -DPRESCALE=${PRESCALE} -DBAUD=${BAUD} \
- -DSTACK=${STACK} -DTASKS=${TASKS} -DSEMAPHORES=${SEMAPHORES}
+ -DSTACK=${STACK} -DTASKS=${TASKS} -DSEMAPHORES=${SEMAPHORES} \
+ -DADCPRESCALE=${ADCPRESCALE}
LDFLAGS = -Wl,-Map,${PROG}.map
.SUFFIXES: .elf .lst .hex .bin .srec .ehex .ebin .esrec
diff --git a/kernel/adc.c b/kernel/adc.c
index f48fccd..8f2164d 100644
--- a/kernel/adc.c
+++ b/kernel/adc.c
@@ -38,8 +38,7 @@ adc(void *arg)
a->r = release();
a->d = deadline();
- /* prescale 8 */
- ADCSRA |= (_BV(ADEN) | _BV(ADFR) | _BV(ADPS1) | _BV(ADPS0));
+ ADCSRA |= (_BV(ADEN) | _BV(ADFR) | ADC_FLAGS);
for (;;) {
*a->value = rdadc(a->channel);
diff --git a/kernel/kernel.h b/kernel/kernel.h
index feab5b0..866ed5c 100644
--- a/kernel/kernel.h
+++ b/kernel/kernel.h
@@ -57,6 +57,26 @@
#warning "invalid PRESCALE value"
#endif
+#if (ADCPRESCALE == 1)
+#define ADC_FLAGS 0
+#elif (ADCPRESCALE == 2)
+#define ADC_FLAGS _BV(ADPS0)
+#elif (ADCPRESCALE == 4)
+#define ADC_FLAGS _BV(ADPS1)
+#elif (ADCPRESCALE == 8)
+#define ADC_FLAGS (_BV(ADPS1) | _BV(ADPS0))
+#elif (ADCPRESCALE == 16)
+#define ADC_FLAGS _BV(ADPS2)
+#elif (ADCPRESCALE == 32)
+#define ADC_FLAGS (_BV(ADPS2) | _BV(ADPS0))
+#elif (ADCPRESCALE == 64)
+#define ADC_FLAGS (_BV(ADPS2) | _BV(ADPS1))
+#elif (ADCPRESCALE == 128)
+#define ADC_FLAGS (_BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0))
+#else
+#warning "invalid ADCPRESCALE value"
+#endif
+
#define SEC(T) ((uint32_t)((T) * (F_CPU / PRESCALE)))
#define MSEC(T) ((uint32_t)(T) * ((F_CPU / 1000) / PRESCALE))
#define USEC(T) ((uint32_t)(T) * ((F_CPU / 1000000) / PRESCALE))