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

@ -28,7 +28,7 @@
* *
* 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()
@ -75,6 +77,24 @@ clock_set(clock_time_t clock, clock_time_t fclock)
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)
{ {