diff options
| -rw-r--r-- | src/ao.h | 4 | ||||
| -rw-r--r-- | src/ao_main.c | 4 | ||||
| -rw-r--r-- | src/ao_teledongle.c | 4 | ||||
| -rw-r--r-- | src/ao_telemetrum.c | 4 | ||||
| -rw-r--r-- | src/ao_teleterra.c | 4 | ||||
| -rw-r--r-- | src/ao_test.c | 4 | ||||
| -rw-r--r-- | src/ao_tidongle.c | 4 | ||||
| -rw-r--r-- | src/ao_timer.c | 21 | ||||
| -rw-r--r-- | src/cc1111.h | 32 | 
9 files changed, 60 insertions, 21 deletions
@@ -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   */ diff --git a/src/ao_main.c b/src/ao_main.c index 1f7a829f..25acccfc 100644 --- a/src/ao_main.c +++ b/src/ao_main.c @@ -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(); diff --git a/src/ao_teledongle.c b/src/ao_teledongle.c index 567751c6..4ebc53a5 100644 --- a/src/ao_teledongle.c +++ b/src/ao_teledongle.c @@ -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); diff --git a/src/ao_telemetrum.c b/src/ao_telemetrum.c index a680ce19..5e951b49 100644 --- a/src/ao_telemetrum.c +++ b/src/ao_telemetrum.c @@ -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); diff --git a/src/ao_teleterra.c b/src/ao_teleterra.c index ad3e2d9b..6464ccc0 100644 --- a/src/ao_teleterra.c +++ b/src/ao_teleterra.c @@ -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); diff --git a/src/ao_test.c b/src/ao_test.c index c9bb02ae..b9f7d338 100644 --- a/src/ao_test.c +++ b/src/ao_test.c @@ -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); diff --git a/src/ao_tidongle.c b/src/ao_tidongle.c index 6dfa9ae9..3b7c2733 100644 --- a/src/ao_tidongle.c +++ b/src/ao_tidongle.c @@ -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); diff --git a/src/ao_timer.c b/src/ao_timer.c index 81c3b376..78c6e063 100644 --- a/src/ao_timer.c +++ b/src/ao_timer.c @@ -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)) +		; +} diff --git a/src/cc1111.h b/src/cc1111.h index f55e802f..87b14485 100644 --- a/src/cc1111.h +++ b/src/cc1111.h @@ -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 {  | 
