altos: Timers clock base depends on perhipheral bus prescalers too
authorKeith Packard <keithp@keithp.com>
Sat, 2 Jun 2012 02:35:33 +0000 (19:35 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 2 Jun 2012 02:35:33 +0000 (19:35 -0700)
For some weird reason, a non-unity perhipheral bus clock scaler
affects the base of the various timers; this left the 100Hz tick
running at 200Hz.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/stm/ao_timer.c

index 099a0ece8a6bbdd92d594ab51984238ca06cc900..0c44f352fb56009bb35b7f1e34e2f22a15faa40b 100644 (file)
@@ -69,7 +69,19 @@ ao_timer_set_adc_interval(uint8_t interval) __critical
 }
 #endif
 
-#define TIMER_10kHz    (AO_PCLK1 / 10000)
+/*
+ * According to the STM clock-configuration, timers run
+ * twice as fast as the APB1 clock *if* the APB1 prescaler
+ * is greater than 1.
+ */
+
+#if AO_APB1_PRESCALER > 1
+#define TIMER_23467_SCALER 2
+#else
+#define TIMER_23467_SCALER 1
+#endif
+
+#define TIMER_10kHz    ((AO_PCLK1 * TIMER_23467_SCALER) / 10000)
 
 void
 ao_timer_init(void)