]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/timer/Msp430ClockP.nc
Let's let the compiler type system work for us. Instead of having a single
[tinyos-2.x.git] / tos / chips / msp430 / timer / Msp430ClockP.nc
index 094cda714f7652a649361b9bbc1e42a5e72c6e9d..55aaba33203581bdff602e1b62d393355f5fe05b 100644 (file)
 
 /**
  * @author Cory Sharp <cssharp@eecs.berkeley.edu>
+ * @author Vlado Handziski <handzisk@tkn.tu-berlind.de>
  */
 
 #include <Msp430DcoSpec.h>
 
 #include "Msp430Timer.h"
 
-module Msp430ClockP
+module Msp430ClockP @safe()
 {
   provides interface Init;
   provides interface Msp430ClockInit;
@@ -44,10 +45,22 @@ implementation
   enum
   {
     ACLK_CALIB_PERIOD = 8,
-    ACLK_HZ = 32768U,
-    TARGET_DCO_DELTA = (TARGET_DCO_HZ / ACLK_HZ) * ACLK_CALIB_PERIOD,
+    TARGET_DCO_DELTA = (TARGET_DCO_KHZ / ACLK_KHZ) * ACLK_CALIB_PERIOD,
   };
 
+
+  command void Msp430ClockInit.defaultSetupDcoCalibrate()
+  {
+  
+    // --- setup ---
+
+    TACTL = TASSEL1 | MC1; // source SMCLK, continuous mode, everything else 0
+    TBCTL = TBSSEL0 | MC1;
+    BCSCTL1 = XT2OFF | RSEL2;
+    BCSCTL2 = 0;
+    TBCCTL0 = CM0;
+   }
+    
   command void Msp430ClockInit.defaultInitClocks()
   {
     // BCSCTL1
@@ -99,6 +112,11 @@ implementation
     TBCTL = TBSSEL0 | TBIE;
   }
 
+  default event void Msp430ClockInit.setupDcoCalibrate()
+  {
+    call Msp430ClockInit.defaultSetupDcoCalibrate();
+  }
+  
   default event void Msp430ClockInit.initClocks()
   {
     call Msp430ClockInit.defaultInitClocks();
@@ -174,14 +192,6 @@ implementation
     int calib;
     int step;
 
-    // --- setup ---
-
-    TACTL = TASSEL1 | MC1; // source SMCLK, continuous mode, everything else 0
-    TBCTL = TBSSEL0 | MC1;
-    BCSCTL1 = XT2OFF | RSEL2;
-    BCSCTL2 = 0;
-    TBCCTL0 = CM0;
-
     // --- calibrate ---
 
     // Binary search for RSEL,DCO,DCOMOD.
@@ -211,6 +221,7 @@ implementation
 
     atomic
     {
+      signal Msp430ClockInit.setupDcoCalibrate();
       busyCalibrateDco();
       signal Msp430ClockInit.initClocks();
       signal Msp430ClockInit.initTimerA();