]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/platforms/tmicore/MoteClockP.nc
Proper support for the new basic_clock+ peripheral. Default UART baud rate is
[tinyos-2.x.git] / tos / platforms / tmicore / MoteClockP.nc
index 1e141b45cafe3b150024d7a4891297734fcbb1d1..3502a0a4f9c58b7fa996463933697626489ecec8 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;
+    uint16_t i;
 
-      /* Initialize DCO from calibrated data */
-      BCSCTL1 = CALBC1_8MHZ;
-      DCOCTL = CALDCO_8MHZ;
+#if defined (CALDCO_8MHZ_) && !defined(__DisableCalData)
+    if (CALBC1_8MHZ != 0xff || CALDCO_8MHZ != 0xff) {
+      /* 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, driven by ACLK */
+       TBCTL |= MC_2;
+      }
       return SUCCESS;
-    } else
-      return call SubInit.init();
+    }
+#endif
+
+    /* Calibrate DCOCLK to ACLK when calibration data are disabled or erased */
+    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()
+  {
+    call Msp430ClockInit.defaultInitClocks();
+  }
+
+  event void Msp430ClockInit.initTimerA()
+  {
+    call Msp430ClockInit.defaultInitTimerA();
+  }
+
+  event void Msp430ClockInit.initTimerB()
+  {
+    call Msp430ClockInit.defaultInitTimerB();
   }
 }