41 #include "sys/clock.h"
48 #define TICK_VAL (32768/128)
50 #if CLOCK_CONF_STACK_FRIENDLY
51 volatile uint8_t sleep_flag;
55 __xdata
__at(0x0000) static
unsigned long timer_value = 0;
57 static volatile CC_AT_DATA clock_time_t count = 0;
58 static volatile CC_AT_DATA clock_time_t seconds = 0;
112 CLKCONCMD = CLKCONCMD_OSC32K | CLKCONCMD_OSC;
115 CLKCONCMD &= ~CLKCONCMD_OSC;
116 while(CLKCONSTA & CLKCONCMD_OSC);
119 CLKCONCMD |= CLKCONCMD_TICKSPD2 | CLKCONCMD_TICKSPD1;
120 while(CLKCONSTA != CLKCONCMD);
124 timer_value += ((
unsigned long int)ST1) << 8;
125 timer_value += ((
unsigned long int)ST2) << 16;
126 timer_value += TICK_VAL;
127 ST2 = (
unsigned char)(timer_value >> 16);
128 ST1 = (
unsigned char)(timer_value >> 8);
129 ST0 = (
unsigned char)timer_value;
136 #if CC_CONF_OPTIMIZE_STACK_SIZE
143 ENERGEST_ON(ENERGEST_TYPE_IRQ);
150 timer_value += ((
unsigned long int)ST1) << 8;
151 timer_value += ((
unsigned long int)ST2) << 16;
152 timer_value += TICK_VAL;
153 ST2 = (
unsigned char)(timer_value >> 16);
154 ST1 = (
unsigned char)(timer_value >> 8);
155 ST0 = (
unsigned char)timer_value;
163 #if (CLOCK_CONF_SECOND & (CLOCK_CONF_SECOND - 1)) != 0
164 #error CLOCK_CONF_SECOND must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...).
165 #error Change CLOCK_CONF_SECOND in contiki-conf.h.
167 if(count % CLOCK_CONF_SECOND == 0) {
171 #if CLOCK_CONF_STACK_FRIENDLY
181 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
Definitions for TI/Chipcon cc2530, cc2531 and cc2533 SFR registers.
void clock_init(void)
Initialize the clock library.
Header file with definitions of bit masks for some cc2530 SFRs
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.
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
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.
#define DISABLE_INTERRUPTS()
Disable interrupts, saving the previous state so it can be later restored with RESTORE_INTERRUPTS().
void clock_wait(clock_time_t t)
Wait for a given number of ticks.
__xdata __at(0x0000)
Each iteration is ~1.0xy usec, so this function delays for roughly len usec.
void clock_isr(void)
The clock Interrupt Service Routine.