Added experimental clock_fine() function
This commit is contained in:
parent
48f467a685
commit
6a8d8e3abf
@ -53,7 +53,7 @@
|
||||
*
|
||||
* 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__
|
||||
#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__ */
|
||||
|
||||
/** @} */
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user