Fix clock initialization to not try to use 32kHz xtal on P2_3/P2_4
authorKeith Packard <keithp@keithp.com>
Wed, 17 Jun 2009 20:55:23 +0000 (13:55 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 17 Jun 2009 20:55:23 +0000 (13:55 -0700)
None of our boards have a 32kHz xtal oscillator, instead we use those pins
(on Telemetrum) for the deployment firing circuits. The old clock
initialization code was switching from the 32kHz RC oscillator to the 32kHz
crystal and overriding our use of those pins.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao.h
src/ao_main.c
src/ao_teledongle.c
src/ao_telemetrum.c
src/ao_teleterra.c
src/ao_test.c
src/ao_tidongle.c
src/ao_timer.c
src/cc1111.h

index 02e10ec0fdad31b1f4ec3a02c799718af72af7f0..6836e0103a7a155a9011387522a0a05e9c7b96d2 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -121,6 +121,10 @@ ao_timer_isr(void) interrupt 9;
 void
 ao_timer_init(void);
 
+/* Initialize the hardware clock. Must be called first */
+void
+ao_clock_init(void);
+
 /*
  * ao_adc.c
  */
index 1f7a829fc929480ed1b12e6f37d5cfbf061ae11a..25acccfc7d9c369a7140b217be8af5c1a4ad02d2 100644 (file)
@@ -20,9 +20,7 @@
 void
 main(void)
 {
-       CLKCON = 0;
-       while (!(SLEEP & SLEEP_XOSC_STB))
-               ;
+       ao_clock_init();
 
        /* Turn on the red LED until the system is stable */
        ao_led_init();
index 567751c6097f3f9f17bdf8dc2165e6041dbc97e2..4ebc53a54161d5f1772426dd3257a80c04c9c163 100644 (file)
@@ -22,9 +22,7 @@
 void
 main(void)
 {
-       CLKCON = 0;
-       while (!(SLEEP & SLEEP_XOSC_STB))
-               ;
+       ao_clock_init();
 
        /* Turn on the LED until the system is stable */
        ao_led_init(AO_LED_RED|AO_LED_GREEN);
index a680ce19675180b0377887b33e0609d82169f5d8..5e951b493f098c1a42b787dde12a0635e22f2439 100644 (file)
@@ -20,9 +20,7 @@
 void
 main(void)
 {
-       CLKCON = 0;
-       while (!(SLEEP & SLEEP_XOSC_STB))
-               ;
+       ao_clock_init();
 
        /* Turn on the red LED until the system is stable */
        ao_led_init(AO_LED_RED|AO_LED_GREEN);
index ad3e2d9bd96355347079fe4831d3b746fd36c874..6464ccc07f01ddcca3737a15412dc5037450ff89 100644 (file)
@@ -21,9 +21,7 @@
 void
 main(void)
 {
-       CLKCON = 0;
-       while (!(SLEEP & SLEEP_XOSC_STB))
-               ;
+       ao_clock_init();
 
        /* Turn on the red LED until the system is stable */
        ao_led_init(AO_LED_RED|AO_LED_GREEN);
index c9bb02ae05ba445b7d1685fbd6a1256a155bae3a..b9f7d33840dfe53ee724674df05485f457cda1c6 100644 (file)
@@ -100,9 +100,7 @@ echo(void)
 void
 main(void)
 {
-       CLKCON = 0;
-       while (!(SLEEP & SLEEP_XOSC_STB))
-               ;
+       ao_clock_init();
 
 //     ao_add_task(&blink_0_task, blink_0);
 //     ao_add_task(&blink_1_task, blink_1);
index 6dfa9ae9477103f6b5d9ae11c51f8af61e0b9b07..3b7c2733b7feaf51427f648a9d64f5541a6fb95e 100644 (file)
@@ -22,9 +22,7 @@
 void
 main(void)
 {
-       CLKCON = 0;
-       while (!(SLEEP & SLEEP_XOSC_STB))
-               ;
+       ao_clock_init();
 
        /* Turn on the LED until the system is stable */
        ao_led_init(AO_LED_RED);
index 81c3b376214ffddac88e19113d2e433cafc89d74..78c6e063f0991eb5c71e628b652cca08e928c02b 100644 (file)
@@ -83,3 +83,24 @@ ao_timer_init(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))
+               ;
+}
index f55e802f9b8b22feea66f196c76086d5ef3e7fd4..87b144855c832a9b3585086937a95fed0475f6fa 100644 (file)
@@ -81,6 +81,35 @@ sfr at 0x9A IEN2;            /* Interrupt Enable 2 Register */
 #define IEN2_USBIE             (1 << 1)        /* USB interrupt enable */
 #define IEN2_RFIE              (1 << 0)        /* RF general interrupt enable */
 
+/* CLKCON 0xC6 */
+sfr at 0xC6 CLKCON;            /* Clock Control */
+
+#define CLKCON_OSC32K_RC       (1 << 7)
+#define CLKCON_OSC32K_XTAL     (0 << 7)
+#define CLKCON_OSC32K_MASK     (1 << 7)
+#define CLKCON_OSC_RC          (1 << 6)
+#define CLKCON_OSC_XTAL                (0 << 6)
+#define CLKCON_OSC_MASK                (1 << 6)
+#define CLKCON_TICKSPD_MASK    (7 << 3)
+# define CLKCON_TICKSPD_1      (0 << 3)
+# define CLKCON_TICKSPD_1_2    (1 << 3)
+# define CLKCON_TICKSPD_1_4    (2 << 3)
+# define CLKCON_TICKSPD_1_8    (3 << 3)
+# define CLKCON_TICKSPD_1_16   (4 << 3)
+# define CLKCON_TICKSPD_1_32   (5 << 3)
+# define CLKCON_TICKSPD_1_64   (6 << 3)
+# define CLKCON_TICKSPD_1_128  (7 << 3)
+
+#define CLKCON_CLKSPD_MASK     (7 << 0)
+# define CLKCON_CLKSPD_1       (0 << 0)
+# define CLKCON_CLKSPD_1_2     (1 << 0)
+# define CLKCON_CLKSPD_1_4     (2 << 0)
+# define CLKCON_CLKSPD_1_8     (3 << 0)
+# define CLKCON_CLKSPD_1_16    (4 << 0)
+# define CLKCON_CLKSPD_1_32    (5 << 0)
+# define CLKCON_CLKSPD_1_64    (6 << 0)
+# define CLKCON_CLKSPD_1_128   (7 << 0)
+
 /* SLEEP 0xBE */
 #define SLEEP_USB_EN           (1 << 7)
 #define SLEEP_XOSC_STB         (1 << 6)
@@ -641,9 +670,6 @@ sbit at 0xa1 P2_1;
 sbit at 0xa2 P2_2;
 sbit at 0xa3 P2_3;
 sbit at 0xa4 P2_4;
-sbit at 0xa5 P2_5;
-sbit at 0xa6 P2_6;
-sbit at 0xa7 P2_7;
 
 /* DMA controller */
 struct cc_dma_channel {