33 #include "sys/clock.h" 36 #include "rtimer-arch.h" 37 #include "dev/watchdog.h" 38 #include "isr_compat.h" 40 #define INTERVAL (RTIMER_ARCH_SECOND / CLOCK_SECOND) 42 #define MAX_TICKS (~((clock_time_t)0) / 2) 44 #define CLOCK_LT(a, b) ((int16_t)((a)-(b)) < 0) 46 static volatile unsigned long seconds;
48 static volatile clock_time_t count = 0;
50 static volatile uint16_t last_tar = 0;
52 static inline uint16_t
72 while(TACTL & MC1 && TACCR1 - read_tar() == 1);
74 last_tar = read_tar();
76 while(!CLOCK_LT(last_tar, TACCR1)) {
84 #if (CLOCK_CONF_SECOND & (CLOCK_CONF_SECOND - 1)) != 0 85 #error CLOCK_CONF_SECOND must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...). 86 #error Change CLOCK_CONF_SECOND in contiki-conf.h. 88 if(count % CLOCK_CONF_SECOND == 0) {
92 last_tar = read_tar();
121 clock_set(clock_time_t clock, clock_time_t fclock)
124 TACCR1 = fclock + INTERVAL;
141 return (
unsigned short) (TAR - t);
158 #if INTERVAL==32768/CLOCK_SECOND 159 TACTL = TASSEL0 | TACLR;
160 #elif INTERVAL==16384/CLOCK_SECOND 161 TACTL = TASSEL0 | TACLR | ID_1;
163 #error NEED TO UPDATE clock.c to match interval! 204 while(
clock_time() - start < (clock_time_t)i);
219 unsigned long t1, t2;
230 rtimer_clock_t t1, t2;
Header file for the energy estimation mechanism
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
void clock_wait(clock_time_t i)
Wait for a given number of ticks.
unsigned long clock_seconds(void)
Get the current value of the platform seconds.
clock_time_t etimer_next_expiration_time(void)
Get next event timer expiration time.
int clock_fine_max(void)
Deprecated platform-specific routines.
static void start(void)
Start measurement.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
int etimer_pending(void)
Check if there are any non-expired event timers.
void clock_delay(unsigned int i)
Obsolete delay function but we implement it here since some code still uses it.
clock_time_t clock_time(void)
Get the current clock time.
void clock_set_seconds(unsigned long sec)
Set the value of the platform seconds.
void clock_init(void)
Arch-specific implementation of clock_init for the cc2538.
void watchdog_stop(void)
Stops the WDT such that it won't timeout and cause MCU reset.