* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
+
/**
- * @author R. Steve McKown <smckown@gmail.com>
+ * @author R. Steve McKown <rsmckown@gmail.com>
*/
-
+
+#include "Msp430Timer.h"
+
module MoteClockP {
provides interface Init;
uses interface Init as SubInit;
-
}
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 timers A and B */
+ TACTL |= MC_2;
+ 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();
}
}