Contiki-Inga 3.x
|
Files | |
file | clock.c |
This file contains AVR-specific code to implement the Contiki core clock functions. | |
file | clock.c.BACKUP.2341.c |
This file contains AVR-specific code to implement the Contiki core clock functions. | |
file | clock.c.LOCAL.2341.c |
This file contains AVR-specific code to implement the Contiki core clock functions. | |
Functions | |
void | clock_init (void) |
Start the clock by enabling the timer comparison interrupts. More... | |
clock_time_t | clock_time (void) |
Return the tick counter. More... | |
unsigned long | clock_seconds (void) |
Return seconds, default is time since startup. More... | |
void | clock_set_seconds (unsigned long sec) |
Set seconds, e.g. More... | |
void | clock_wait (clock_time_t t) |
Wait for a number of clock ticks. More... | |
void | clock_delay_usec (uint16_t howlong) |
Delay a given number of microseconds. More... | |
void | clock_delay (unsigned int howlong) |
Legacy delay. More... | |
void | clock_delay_msec (uint16_t howlong) |
Delay up to 65535 milliseconds. More... | |
void | clock_adjust_ticks (clock_time_t howmany) |
Adjust the system current clock time. More... | |
void | AVR_OUTPUT_COMPARE_INT (void) |
ISR for the TIMER0 or TIMER2 interrupt as defined in clock-avr.h for the particular MCU. | |
int | clock_fine_max (void) |
Deprecated platform-specific routines. | |
Variables | |
<<<<<<< HEADstaticvolatileclock_time_tcount;=======staticvolatileclock_time_tcount;staticvolatileuint8_tscount;> >>>>> Adjust sleep time by ticks instead of | seconds |
These routines define the AVR-specific calls declared in /core/sys/clock.h CLOCK_SECOND is the number of ticks per second. More... | |
volatile unsigned long | seconds |
These routines define the AVR-specific calls declared in /core/sys/clock.h CLOCK_SECOND is the number of ticks per second. More... | |
void clock_adjust_ticks | ( | clock_time_t | howmany | ) |
Adjust the system current clock time.
Adjust clock ticks after a cpu sleep.
dt | How many ticks to add |
Typically used to add ticks after an MCU sleep clock_seconds will increment if necessary to reflect the tick addition. Leap ticks or seconds can (rarely) be introduced if the ISR is not blocked.
Definition at line 289 of file clock.c.
References CLOCK_SECOND.
|
inline |
Legacy delay.
Delay the CPU for a multiple of TODO.
The original clock_delay for the msp430 used a granularity of 2.83 usec. This approximates that delay for values up to 1456 usec. (The largest core call in leds.c uses 400).
Definition at line 244 of file clock.c.
References clock_delay_usec().
void clock_delay_msec | ( | uint16_t | howlong | ) |
Delay up to 65535 milliseconds.
Delay the CPU for up to 65535 milliseconds.
dt | How many milliseconds to delay. |
Neither interrupts nor the watchdog timer is disabled over the delay. Platforms are not required to implement this call.
Definition at line 260 of file clock.c.
References clock_delay_usec().
void clock_delay_usec | ( | uint16_t | howlong | ) |
Delay a given number of microseconds.
dt | How many microseconds to delay. |
Delay a given number of microseconds.
Use the 250KHz MACA clock for longer delays to avoid interrupt effects. However that can't be used if the radio is being power cycled!
void clock_init | ( | void | ) |
unsigned long clock_seconds | ( | void | ) |
void clock_set_seconds | ( | unsigned long | sec | ) |
clock_time_t clock_time | ( | void | ) |
void clock_wait | ( | clock_time_t | t | ) |
Wait for a number of clock ticks.
Wait for a given number of ticks.
Definition at line 166 of file clock.c.
References clock_time().
volatile unsigned long seconds |
These routines define the AVR-specific calls declared in /core/sys/clock.h CLOCK_SECOND is the number of ticks per second.
It is defined through CONF_CLOCK_SECOND in the contiki-conf.h for each platform. The usual AVR defaults are 128 or 125 ticks per second, counting a prescaled CPU clock using the 8 bit timer0.
clock_time_t is usually declared by the platform as an unsigned 16 bit data type, thus intervals up to 512 or 524 seconds can be measured with ~8 millisecond precision. For longer intervals the 32 bit clock_seconds() is available.
Since a carry to a higer byte can occur during an interrupt, declaring them non-static for direct examination can cause occasional time reversals!
clock-avr.h contains the specific setup code for each mcu.
Definition at line 86 of file clock.c.LOCAL.2341.c.
<<<<<<<HEADvoidclock_init(void){cli();OCRSetup();sei();}clock_time_tclock_time(void){clock_time_ttmp;do{tmp=count;}while(tmp!=count);returntmp;}unsignedlongclock_seconds(void){unsignedlongtmp;do{tmp=seconds;}while(tmp!=seconds);returntmp;}voidclock_set_seconds(unsignedlongsec){seconds=sec;}voidclock_wait(clock_time_tt){clock_time_tendticks=clock_time()+t;if(sizeof(clock_time_t)==1){while((signedchar)(clock_time()-endticks)<0){;}}elseif(sizeof(clock_time_t)==2){while((signedshort)(clock_time()-endticks)<0){;}}else{while((signedlong)(clock_time()-endticks)<0){;}}}staticinlinevoidmy_delay_loop_2(uint16_t__count)__attribute__((always_inline));voidmy_delay_loop_2(uint16_t__count){__asm__volatile("1:sbiw%0,1""\n\t""brne1b":"=w"(__count):"0"(__count));}voidclock_delay_usec(uint16_thowlong){howlong>>5;if(howlong<1)return;my_delay_loop_2(howlong);}voidclock_delay_msec(uint16_thowlong){uint16_ti=983;while(howlong--){clock_delay_usec(i);i=999;}}=======voidclock_adjust_ticks(uint16_thowmany){count+=howmany;scount+=howmany;while(scount>=CLOCK_SECOND){scount-=CLOCK_SECOND;seconds++;sleepseconds++;}}voidAVR_OUTPUT_COMPARE_INT(void);<<<<<<<HEAD=======voidclock_init(void){cli();OCRSetup();sei();}clock_time_tclock_time(void){clock_time_ttmp;do{tmp=count;}while(tmp!=count);returntmp;}>>>>>>>5e18239...Adjustsleeptimebyticksinsteadofseconds,proposedbyIvanDelamer=======>>>>>>> Adjust sleep time by ticks instead of seconds |
These routines define the AVR-specific calls declared in /core/sys/clock.h CLOCK_SECOND is the number of ticks per second.
It is defined through CONF_CLOCK_SECOND in the contiki-conf.h for each platform. The usual AVR defaults are 128 or 125 ticks per second, counting a prescaled CPU clock using the 8 bit timer0.
clock_time_t is usually declared by the platform as an unsigned 16 bit data type, thus intervals up to 512 or 524 seconds can be measured with ~8 millisecond precision. For longer intervals the 32 bit clock_seconds() is available.
Since a carry to a higer byte can occur during an interrupt, declaring them non-static for direct examination can cause occasional time reversals!
clock-avr.h contains the specific setup code for each mcu.
Definition at line 107 of file clock.c.BACKUP.2341.c.