]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Update the tmicore platform's clock initialization. If DCO constants are in
authorsmckown <smckown@4bc1554a-c7f2-4f65-a403-e0be01f0239c>
Mon, 8 Sep 2008 23:10:45 +0000 (23:10 +0000)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 1 Dec 2009 03:00:50 +0000 (20:00 -0700)
INFOA, it uses them.  If not, is uses the standard mecthod of calibrating the
DCO off of ACLK.  For tmicore, DCOCLK = MCLK = 8MHz.  We add additional code to
set SMCLK = 1MHz.  If the constants are used, the 1MHz = 10^6HZ.  If the
internal cal routines are used, 1MHz = 2^20Hz.

tos/platforms/tmicore/MoteClockC.nc
tos/platforms/tmicore/MoteClockP.nc

index 2c125656af85ad030f26c82e0b84a46065813537..e838b5e5ef108de858cbc5369318b6ff61561b63 100644 (file)
  * @author R. Steve McKown <smckown@gmail.com>
  */
  
-#define MS430DCOSPEC_H
-#define TARGET_DCO_KHZ 8192 // the target DCO clock rate in binary kHz
-//#define TARGET_DCO_KHZ 4096 // the target DCO clock rate in binary kHz
-#define ACLK_KHZ 32 // the ACLK rate in binary kHz
-
 configuration MoteClockC {
   provides interface Init as MoteClockInit;
 }
@@ -49,5 +44,5 @@ implementation {
 
   components Msp430ClockC;
   MoteClockP.SubInit -> Msp430ClockC.Init;
-  //MoteClockP.Msp430ClockInit -> Msp430ClockC;
+  MoteClockP.Msp430ClockInit -> Msp430ClockC;
 }
index 1e141b45cafe3b150024d7a4891297734fcbb1d1..543aab467e4bc3800ffc1d5a500167a5dc61aa59 100644 (file)
  * @author R. Steve McKown <smckown@gmail.com>
  */
  
+//#include "msp430hardware.h"
+#include "Msp430Timer.h"
+
+#define MS430DCOSPEC_H
+#define TARGET_DCO_KHZ 8192 // the target DCO clock rate in binary kHz
+//#define TARGET_DCO_KHZ 4096 // the target DCO clock rate in binary kHz
+#define ACLK_KHZ 32 // the ACLK rate in binary kHz
+
 module MoteClockP {
   provides interface Init;
-  uses interface Init as SubInit;
-
+  uses {
+    interface Init as SubInit;
+    interface Msp430ClockInit;
+  }
 }
 
 implementation {
   command error_t Init.init()
   {
     if (CALBC1_8MHZ != 0xff || CALDCO_8MHZ != 0xff) {
-      /* Initialize timers */
-      TACTL = TASSEL_2 | TACLR | TAIE;
-      TAIV = 0;
-      TBCTL = TBSSEL_1 | TBCLR | TBIE;
-      TBIV = 0;
-
-      /* Initialize DCO from calibrated data */
-      BCSCTL1 = CALBC1_8MHZ;
-      DCOCTL = CALDCO_8MHZ;
+      /* Use built-in constant */
+      atomic {
+       /* Initialize timers */
+       TACTL = TASSEL_2 | TACLR | TAIE;
+       TAIV = 0;
+       TBCTL = TBSSEL_1 | TBCLR | TBIE;
+       TBIV = 0;
 
-      /* Turn on TimerB, aka the 32KHz clock */
-      TBCTL |= MC1;
+       /* Initialize DCO from calibrated data.  DCO = 8MHz.  SMCLK = DCO/8 */
+       BCSCTL1 = CALBC1_8MHZ;
+       BCSCTL2 = SELM_0 | DIVM_0 | DIVS_3;
+       DCOCTL = CALDCO_8MHZ;
 
+       /* Turn on TimerB, aka the 32KHz clock */
+       TBCTL |= MC1;
+      }
       return SUCCESS;
-    } else
+    } else {
+      /* Constant not present; calibrate on the fly */
+      int i;
+
+      for (i = 0; i < 0xfffe; i++); /* ensure LFXT1 is stable */
       return call SubInit.init();
+    }
+  }
+
+  event void Msp430ClockInit.setupDcoCalibrate()
+  {
+    call Msp430ClockInit.defaultSetupDcoCalibrate();
+  }
+
+  event void Msp430ClockInit.initClocks()
+  {
+    /* We run at 8MHz, so SMCLK divider needs to be /8 */
+    call Msp430ClockInit.defaultInitClocks();
+    BCSCTL2 |= DIVS_3;
+  }
+
+  event void Msp430ClockInit.initTimerA()
+  {
+    call Msp430ClockInit.defaultInitTimerA();
+  }
+
+  event void Msp430ClockInit.initTimerB()
+  {
+    call Msp430ClockInit.defaultInitTimerB();
   }
 }