return ao_tick_count;
}
+static __xdata uint8_t ao_forever;
+
void
ao_delay(uint16_t ticks)
{
- uint16_t until = ao_time() + ticks;
-
- while ((int16_t) (until - ao_time()) > 0)
- ao_sleep(DATA_TO_XDATA(&ao_tick_count));
+ ao_alarm(ticks);
+ ao_sleep(&ao_forever);
}
#define T1_CLOCK_DIVISOR 8 /* 24e6/8 = 3e6 */
ao_adc_count = 0;
ao_adc_poll();
}
- ao_wakeup(DATA_TO_XDATA(&ao_tick_count));
}
void
/* enable timer 1 in module mode, dividing by 8 */
T1CTL = T1CTL_MODE_MODULO | T1CTL_DIV_8;
}
+
+/*
+ * AltOS always cranks the clock to the max frequency
+ */
+void
+ao_clock_init(void)
+{
+ /* Switch system clock to crystal oscilator */
+ CLKCON = (CLKCON & ~CLKCON_OSC_MASK) | (CLKCON_OSC_XTAL);
+
+ while (!(SLEEP & SLEEP_XOSC_STB))
+ ;
+
+ /* Crank up the timer tick and system clock speed */
+ CLKCON = ((CLKCON & ~(CLKCON_TICKSPD_MASK | CLKCON_CLKSPD_MASK)) |
+ (CLKCON_TICKSPD_1 | CLKCON_CLKSPD_1));
+
+ while ((CLKCON & (CLKCON_TICKSPD_MASK|CLKCON_CLKSPD_MASK)) !=
+ (CLKCON_TICKSPD_1 | CLKCON_CLKSPD_1))
+ ;
+}