Reliability patch to Chipcon.
[goodfet] / firmware / lib / msp430x2618.c
index 0158082..6238fe2 100644 (file)
@@ -1,7 +1,6 @@
 //! MSP430F2618 clock and I/O definitions
 
-// Ought to be portable to other 2xx chips.
-// 2274 looks particularly appealing.
+// Included by other 2xx ports, such as the 2274.
 
 #include "platform.h"
 
@@ -127,12 +126,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;
 }