- Add new command/event in Msp430ClockInit to enable overriding of the startup values for the DCO calibrate routine
- Modify PlatformC/PlatformP in platform/telosa to use intermediate configuration MoteClockC that can be used to override the default clock initialization via MoteClockP
- Add MoteClockC and MoteClockP in platform/telosb to allow for usage of the DCOR flag / ROSC on tmote sky. The overriding configuration is currently disabled pending closer review of the calibration routine behavior for the new setup and other potential gotchas
/**
* @author Cory Sharp <cssharp@eecs.berkeley.edu>
+ * @author Vlado Handziski <handzisk@tkn.tu-berlin.de>
*/
interface Msp430ClockInit
{
+ event void setupDcoCalibrate();
event void initClocks();
event void initTimerA();
event void initTimerB();
+ command void defaultSetupDcoCalibrate();
command void defaultInitClocks();
command void defaultInitTimerA();
command void defaultInitTimerB();
/**
* @author Cory Sharp <cssharp@eecs.berkeley.edu>
+ * @author Vlado Handziski <handzisk@tkn.tu-berlind.de>
*/
#include <Msp430DcoSpec.h>
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
TBCTL = TBSSEL0 | TBIE;
}
+ default event void Msp430ClockInit.setupDcoCalibrate()
+ {
+ call Msp430ClockInit.defaultSetupDcoCalibrate();
+ }
+
default event void Msp430ClockInit.initClocks()
{
call Msp430ClockInit.defaultInitClocks();
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.
atomic
{
+ signal Msp430ClockInit.setupDcoCalibrate();
busyCalibrateDco();
signal Msp430ClockInit.initClocks();
signal Msp430ClockInit.initTimerA();
/**
* Specify the target cpu clock speed of your platform by overriding this file.
*
- * Be aware that tinyos relies on binary 4Mhz, that is 4096000 Hz. Some
+ * Be aware that tinyos relies on binary 4MHz, that is 4096 binary kHz. Some
* platforms have an external high frequency oscilator to generate the SMCLK
* (e.g. eyesIFX, and possibly future ZigBee compliant nodes). These
* oscillators provide metric frequencies, but may not run in power down
#ifndef MS430DCOSPEC_H
#define MS430DCOSPEC_H
-#define TARGET_DCO_HZ 4096000 // the cpu clock rate in Hz
-
+#define TARGET_DCO_KHZ 4096 // the target DCO clock rate in binary kHz
+#define ACLK_KHZ 32 // the ACLK rate in binary kHz
#endif
#ifndef MS430DCOSPEC_H
#define MS430DCOSPEC_H
-#define TARGET_DCO_HZ 4000000 // the cpu clock rate in Hz
-
+#define TARGET_DCO_KHZ 3904 // the target MCLK clock rate in binary kHz (4 000 000 Hz)
+#define ACLK_KHZ 32 // the ACLK rate in binary kHz
#endif
--- /dev/null
+/*
+ * Copyright (c) 2007, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universität Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id$
+ *
+ */
+
+ /**
+ * @author Vlado Handziski <handzisk@tkn.tu-berlind.de>
+ */
+
+configuration MoteClockC
+{
+ provides interface Init as MoteClockInit;
+}
+implementation
+
+{
+ components Msp430ClockC;
+
+ MoteClockInit = Msp430ClockC.Init;
+}
}
implementation
{
- components PlatformP, MotePlatformC, Msp430ClockC;
+ components PlatformP, MotePlatformC, MoteClockC;
Init = PlatformP;
- PlatformP.Msp430ClockInit -> Msp430ClockC.Init;
+ PlatformP.MoteClockInit -> MoteClockC;
PlatformP.MoteInit -> MotePlatformC;
}
module PlatformP{
provides interface Init;
- uses interface Init as Msp430ClockInit;
+ uses interface Init as MoteClockInit;
uses interface Init as MoteInit;
uses interface Init as LedsInit;
}
implementation {
command error_t Init.init() {
- call Msp430ClockInit.init();
+ call MoteClockInit.init();
call MoteInit.init();
call LedsInit.init();
return SUCCESS;
--- /dev/null
+/*
+ * Copyright (c) 2007, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universität Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id$
+ *
+ */
+
+ /**
+ * @author Vlado Handziski <handzisk@tkn.tu-berlind.de>
+ */
+
+configuration MoteClockC
+{
+ provides interface Init as MoteClockInit;
+}
+implementation
+
+{
+ components Msp430ClockC, MoteClockP;
+
+ MoteClockInit = Msp430ClockC.Init;
+ //MoteClockP.Msp430ClockInit -> Msp430ClockC;
+}
--- /dev/null
+/*
+ * Copyright (c) 2007, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universität Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id$
+ *
+ */
+
+ /**
+ * @author Vlado Handziski <handzisk@tkn.tu-berlind.de>
+ * @author Cory Sharp <cssharp@eecs.berkeley.edu>
+ */
+
+module MoteClockP {
+ uses interface Msp430ClockInit;
+}
+
+implementation {
+
+ event void Msp430ClockInit.setupDcoCalibrate()
+ {
+
+ // --- setup ---
+
+ TACTL = TASSEL1 | MC1; // source SMCLK, continuous mode, everything else 0
+ TBCTL = TBSSEL0 | MC1;
+ BCSCTL1 = XT2OFF | RSEL2;
+ BCSCTL2 = DCOR; // enable DCOR
+ TBCCTL0 = CM0;
+ }
+
+ event void Msp430ClockInit.initClocks()
+ {
+ // BCSCTL1
+ // .XT2OFF = 1; disable the external oscillator for SCLK and MCLK
+ // .XTS = 0; set low frequency mode for LXFT1
+ // .DIVA = 0; set the divisor on ACLK to 1
+ // .RSEL, do not modify
+ BCSCTL1 = XT2OFF | (BCSCTL1 & (RSEL2|RSEL1|RSEL0));
+
+ // BCSCTL2
+ // .SELM = 0; select DCOCLK as source for MCLK
+ // .DIVM = 0; set the divisor of MCLK to 1
+ // .SELS = 0; select DCOCLK as source for SCLK
+ // .DIVS = 2; set the divisor of SCLK to 4
+ // .DCOR = 1; select internal resistor for DCO
+ BCSCTL2 = DIVS1 | DCOR;
+
+ // IE1.OFIE = 0; no interrupt for oscillator fault
+ CLR_FLAG( IE1, OFIE );
+ }
+
+ event void Msp430ClockInit.initTimerA()
+ {
+ TAR = 0;
+
+ // TACTL
+ // .TACLGRP = 0; each TACL group latched independently
+ // .CNTL = 0; 16-bit counter
+ // .TASSEL = 2; source SMCLK = DCO/4
+ // .ID = 0; input divisor of 1
+ // .MC = 0; initially disabled
+ // .TACLR = 0; reset timer A
+ // .TAIE = 1; enable timer A interrupts
+ TACTL = TASSEL1 | TAIE;
+ }
+
+ event void Msp430ClockInit.initTimerB()
+ {
+ TBR = 0;
+
+ // TBCTL
+ // .TBCLGRP = 0; each TBCL group latched independently
+ // .CNTL = 0; 16-bit counter
+ // .TBSSEL = 1; source ACLK
+ // .ID = 0; input divisor of 1
+ // .MC = 0; initially disabled
+ // .TBCLR = 0; reset timer B
+ // .TBIE = 1; enable timer B interrupts
+ TBCTL = TBSSEL0 | TBIE;
+ }
+
+}