msp430_init_dco on 2xx devices now knows defaults for MSP430F2618 chips with missing...
[goodfet] / firmware / lib / msp430x2618.c
index 0158082..b25225d 100644 (file)
@@ -127,12 +127,29 @@ void msp430_init_uart(){
 
 }
 
+//! Initialize the MSP430 clock.
 void msp430_init_dco() {
-  //This REQUIRES that info flash be unmolested.
-  //TODO check for that.
+  //LED lights when init_dco begins,
+  //then dims when successful.
+  PLEDOUT|=PLEDPIN;
   
-  BCSCTL1 = CALBC1_16MHZ;
-  DCOCTL = CALDCO_16MHZ;  
+  if(CALBC1_16MHZ!=0xFF && CALDCO_16MHZ!=0xFF){
+    //Info is intact, use it.
+    BCSCTL1 = CALBC1_16MHZ;
+    DCOCTL = CALDCO_16MHZ;
+  }else{
+    //Info is missing, guess at a good value.
+    switch(*((int*)0xff0)){
+    default:
+    case 0x6ff2:        //f26f, the MSP430F2618
+      BCSCTL1 = 0x8f;   //CALBC1_16MHZ at 0x10f9
+      DCOCTL = 0x7f;    //CALDCO_16MHZ at 0x10f8
+      break;
+    }
+  }
+  
+  //Hopefully by here the clock is meaningful.
+  PLEDOUT&=~PLEDPIN;
   return;
 }