From 6a8d8e3abff7159c7f9209ff0b072b801e3e0c23 Mon Sep 17 00:00:00 2001 From: adamdunkels Date: Sun, 25 Mar 2007 21:51:31 +0000 Subject: [PATCH] Added experimental clock_fine() function --- core/sys/clock.h | 6 +++- cpu/msp430/clock.c | 76 +++++++++++++++++++++++++++++----------------- 2 files changed, 53 insertions(+), 29 deletions(-) diff --git a/core/sys/clock.h b/core/sys/clock.h index be0d99cf6..8bcef866d 100644 --- a/core/sys/clock.h +++ b/core/sys/clock.h @@ -53,7 +53,7 @@ * * Author: Adam Dunkels * - * $Id: clock.h,v 1.1 2006/06/17 22:41:20 adamdunkels Exp $ + * $Id: clock.h,v 1.2 2007/03/25 21:51:31 adamdunkels Exp $ */ #ifndef __CLOCK_H__ #define __CLOCK_H__ @@ -91,6 +91,10 @@ void clock_delay(unsigned int); #define CLOCK_SECOND (clock_time_t)32 #endif +int clock_fine_max(void); +unsigned short clock_fine(void); + + #endif /* __CLOCK_H__ */ /** @} */ diff --git a/cpu/msp430/clock.c b/cpu/msp430/clock.c index 88619b9ec..9a23fda50 100644 --- a/cpu/msp430/clock.c +++ b/cpu/msp430/clock.c @@ -1,34 +1,34 @@ /* * Copyright (c) 2005, Swedish Institute of Computer Science - * All rights reserved. + * All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. * * This file is part of the Contiki operating system. * - * @(#)$Id: clock.c,v 1.4 2006/08/25 09:40:21 bg- Exp $ + * @(#)$Id: clock.c,v 1.5 2007/03/25 21:52:00 adamdunkels Exp $ */ @@ -47,10 +47,12 @@ #define MAX_TICKS (~((clock_time_t)0) / 2) static volatile clock_time_t count = 0; +static unsigned short last_tar = 0; /*---------------------------------------------------------------------------*/ interrupt(TIMERA1_VECTOR) timera1 (void) { if(TAIV == 2) { TACCR1 += INTERVAL; + last_tar = TAR; ++count; if(etimer_pending() @@ -69,12 +71,30 @@ clock_time(void) /*---------------------------------------------------------------------------*/ void clock_set(clock_time_t clock, clock_time_t fclock) -{ +{ TAR = fclock; TACCR1 = fclock + INTERVAL; count = clock; } /*---------------------------------------------------------------------------*/ +int +clock_fine_max(void) +{ + return INTERVAL; +} +/*---------------------------------------------------------------------------*/ +unsigned short +clock_fine(void) +{ + unsigned short t; + + dint(); + t = TAR; + eint(); + + return (unsigned short)((unsigned long)t - (unsigned long)last_tar); +} +/*---------------------------------------------------------------------------*/ void clock_init(void) { @@ -89,7 +109,7 @@ clock_init(void) TACCTL1 = CCIE; /* Interrupt after X ms. */ - TACCR1 = INTERVAL; + TACCR1 = INTERVAL; /* Start Timer_A in continuous mode. */ TACTL |= MC1; @@ -99,12 +119,12 @@ clock_init(void) BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */ /* Enable interrupts. */ - eint(); + eint(); } /*---------------------------------------------------------------------------*/ /** - * Delay the CPU for a multiple of 2.83 us. + * Delay the CPU for a multiple of 2.83 us. */ void clock_delay(unsigned int i)