Added experimental clock_fine() function

This commit is contained in:
adamdunkels 2007-03-25 21:51:31 +00:00
parent 48f467a685
commit 6a8d8e3abf
2 changed files with 53 additions and 29 deletions

View File

@ -53,7 +53,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $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__ #ifndef __CLOCK_H__
#define __CLOCK_H__ #define __CLOCK_H__
@ -91,6 +91,10 @@ void clock_delay(unsigned int);
#define CLOCK_SECOND (clock_time_t)32 #define CLOCK_SECOND (clock_time_t)32
#endif #endif
int clock_fine_max(void);
unsigned short clock_fine(void);
#endif /* __CLOCK_H__ */ #endif /* __CLOCK_H__ */
/** @} */ /** @} */

View File

@ -1,34 +1,34 @@
/* /*
* Copyright (c) 2005, Swedish Institute of Computer Science * 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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors * 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 * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* This file is part of the Contiki operating system. * 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) #define MAX_TICKS (~((clock_time_t)0) / 2)
static volatile clock_time_t count = 0; static volatile clock_time_t count = 0;
static unsigned short last_tar = 0;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
interrupt(TIMERA1_VECTOR) timera1 (void) { interrupt(TIMERA1_VECTOR) timera1 (void) {
if(TAIV == 2) { if(TAIV == 2) {
TACCR1 += INTERVAL; TACCR1 += INTERVAL;
last_tar = TAR;
++count; ++count;
if(etimer_pending() if(etimer_pending()
@ -69,12 +71,30 @@ clock_time(void)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
clock_set(clock_time_t clock, clock_time_t fclock) clock_set(clock_time_t clock, clock_time_t fclock)
{ {
TAR = fclock; TAR = fclock;
TACCR1 = fclock + INTERVAL; TACCR1 = fclock + INTERVAL;
count = clock; 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 void
clock_init(void) clock_init(void)
{ {
@ -89,7 +109,7 @@ clock_init(void)
TACCTL1 = CCIE; TACCTL1 = CCIE;
/* Interrupt after X ms. */ /* Interrupt after X ms. */
TACCR1 = INTERVAL; TACCR1 = INTERVAL;
/* Start Timer_A in continuous mode. */ /* Start Timer_A in continuous mode. */
TACTL |= MC1; TACTL |= MC1;
@ -99,12 +119,12 @@ clock_init(void)
BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */ BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */
/* Enable interrupts. */ /* 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 void
clock_delay(unsigned int i) clock_delay(unsigned int i)