33 #include "contiki-conf.h"
35 #include "sys/clock.h"
37 #include "rtimer-arch.h"
38 #include "isr_compat.h"
42 #define INTERVAL (RTIMER_ARCH_SECOND / CLOCK_SECOND)
44 #define MAX_TICKS (~((clock_time_t)0) / 2)
46 #define CLOCK_LT(a, b) ((int16_t)((a)-(b)) < 0)
48 static volatile unsigned long seconds;
50 static volatile clock_time_t count = 0;
52 static unsigned short last_tar = 0;
54 static inline uint16_t
66 ISR(TIMER1_A1, timera1)
68 ENERGEST_ON(ENERGEST_TYPE_IRQ);
74 while(TA1CTL & MC1 && TA1CCR1 - TA1R == 1);
76 last_tar = read_tar();
78 while(!CLOCK_LT(last_tar, TA1CCR1)) {
88 #if (CLOCK_CONF_SECOND & (CLOCK_CONF_SECOND - 1)) != 0
89 #error CLOCK_CONF_SECOND must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...).
90 #error Change CLOCK_CONF_SECOND in contiki-conf.h.
92 if(count % CLOCK_CONF_SECOND == 0) {
96 last_tar = read_tar();
110 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
125 clock_set(clock_time_t clock, clock_time_t fclock)
128 TA1CCR1 = fclock + INTERVAL;
145 return (
unsigned short) (TA1R - t);
159 #if INTERVAL==32768/CLOCK_SECOND
160 TA1CTL = TASSEL0 | TACLR;
161 #elif INTERVAL==16384/CLOCK_SECOND
162 TA1CTL = TASSEL0 | TACLR | ID_1;
164 #error NEED TO UPDATE clock.c to match interval!
199 #ifdef __IAR_SYSTEMS_ICC__
235 while(
clock_time() - start < (clock_time_t)i);
247 unsigned long t1, t2;
void clock_init(void)
Initialize the clock library.
Header file for the energy estimation mechanism
CCIF clock_time_t clock_time(void)
Get the current clock time.
clock_time_t etimer_next_expiration_time(void)
Get next event timer expiration time.
#define __delay_cycles(x)
__delay_cycles() is an intrinsic IAR call; however, we have explicity disallowed it since it is too s...
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
void clock_set_seconds(unsigned long sec)
Set the value of the platform seconds.
CCIF unsigned long clock_seconds(void)
Get the current value of the platform seconds.
int etimer_pending(void)
Check if there are any non-expired event timers.
void clock_delay(unsigned int delay)
Obsolete delay function but we implement it here since some code still uses it.
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
int clock_fine_max(void)
Deprecated platform-specific routines.