Contiki 2.6

AVR clock implementation

Files

file  clock.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.
clock_time_t clock_time (void)
 Return the tick counter.
unsigned long clock_seconds (void)
 Return seconds, default is time since startup.
void clock_set_seconds (unsigned long sec)
 Set seconds, e.g.
void clock_wait (clock_time_t t)
 Wait for a number of clock ticks.
void clock_delay_usec (uint16_t howlong)
 Delay a given number of microseconds.
void clock_delay_msec (uint16_t howlong)
 Delay up to 65535 milliseconds.
void clock_adjust_ticks (clock_time_t howmany)
 Adjust the system current clock time.
void AVR_OUTPUT_COMPARE_INT (void)
 ISR for the TIMER0 or TIMER2 interrupt as defined in clock-avr.h for the particular MCU.

Function Documentation

void clock_adjust_ticks ( clock_time_t  howmany)

Adjust the system current clock time.

Adjust clock ticks after a cpu sleep.

Parameters:
dtHow 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.

void clock_delay_msec ( uint16_t  howlong)

Delay up to 65535 milliseconds.

Delay the CPU for up to 65535 milliseconds.

Parameters:
dtHow many milliseconds to delay.

Neither interrupts nor the watchdog timer is disabled over the delay. Platforms are not required to implement this call.

Note:
This will break for CPUs clocked above 260 MHz.

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.

Parameters:
dtHow many microseconds to delay.
Note:
Interrupts could increase the delay by a variable amount.

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!

Definition at line 196 of file clock.c.

Referenced by cc2430_rf_command(), clock_delay(), clock_delay_msec(), and main().

void clock_init ( void  )

Start the clock by enabling the timer comparison interrupts.

Initialize the clock library.

Definition at line 116 of file clock.c.

unsigned long clock_seconds ( void  )

Return seconds, default is time since startup.

Get the current value of the platform seconds.

The comparison avoids the need to disable clock interrupts for an atomic read of the four-byte variable.

Definition at line 144 of file clock.c.

void clock_set_seconds ( unsigned long  sec)

Set seconds, e.g.

Set the value of the platform seconds.

to a standard epoch for an absolute date/time.

Definition at line 157 of file clock.c.

clock_time_t clock_time ( void  )

Return the tick counter.

Get the current clock time.

When 16 bit it typically wraps every 10 minutes. The comparison avoids the need to disable clock interrupts for an atomic read of the multi-byte variable.

Definition at line 129 of file clock.c.

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().