altos-avr: Add SPI-slave companion support
[fw/altos] / src-avr / ao_timer.c
index 01bf8e0c5fd6bbbfbfc7a838eb803628e1b04938..aec404750f308b3d95af12f81b5da667f9666385 100644 (file)
@@ -41,6 +41,9 @@ volatile __data uint8_t       ao_adc_interval = 1;
 volatile __data uint8_t        ao_adc_count;
 #endif
 
+void
+ao_debug_out(char c);
+
 #ifdef AVR
 ISR(TIMER1_COMPA_vect)
 #else
@@ -137,7 +140,13 @@ ao_clock_init(void)
        /* Disable the clock prescaler */
        cli();
        CLKPR = (1 << CLKPCE);
+
+       /* Always run the system clock at 8MHz */
+#if AVR_CLOCK > 12000000UL
+       CLKPR = 1;
+#else
        CLKPR = 0;
+#endif
        sei();
 
        /* Set up the PLL to use the crystal */
@@ -149,7 +158,7 @@ ao_clock_init(void)
                  (0x4 << PDIV0));      /* 48MHz PLL clock */
 
        /* Set the frequency of the crystal */
-#if TEENSY
+#if AVR_CLOCK > 12000000UL
        PLLCSR |= (1 << PINDIV);        /* For 16MHz crystal on Teensy board */
 #else
        PLLCSR &= ~(1 << PINDIV);       /* For 8MHz crystal on TeleScience board */
@@ -159,6 +168,9 @@ ao_clock_init(void)
        PLLCSR |= (1 << PLLE);
        while (!(PLLCSR & (1 << PLOCK)))
                ;
+
+       set_sleep_mode(SLEEP_MODE_IDLE);
+       sleep_enable();
 #else
        /* Switch system clock to crystal oscilator */
        CLKCON = (CLKCON & ~CLKCON_OSC_MASK) | (CLKCON_OSC_XTAL);