Contiki-Inga 3.x
Macros | Functions
Clock library

The clock library is the interface between Contiki and the platform specific clock functionality. More...

Macros

#define CLOCK_SECOND
 A second, measured in system clock time.
 

Functions

void clock_init (void)
 Initialize the clock library. More...
 
CCIF clock_time_t clock_time (void)
 Get the current clock time. More...
 
CCIF unsigned long clock_seconds (void)
 Get the current value of the platform seconds. More...
 
void clock_set_seconds (unsigned long sec)
 Set the value of the platform seconds. More...
 
void clock_wait (clock_time_t t)
 Wait for a given number of ticks. More...
 
void clock_delay_usec (uint16_t dt)
 Delay a given number of microseconds. More...
 
int clock_fine_max (void)
 Deprecated platform-specific routines.
 
void clock_delay (unsigned int delay)
 Delay the CPU for a multiple of TODO. More...
 

Detailed Description

The clock library is the interface between Contiki and the platform specific clock functionality.

The clock library defines a macro, CLOCK_SECOND, to convert seconds into the tick resolution of the platform. Typically this is 1-10 milliseconds, e.g. 4*CLOCK_SECOND could be 512. A 16 bit counter would thus overflow every 1-10 minutes. Platforms use the tick interrupt to maintain a long term count of seconds since startup.

Platforms may also implement rtimers for greater time resolution and for real-time interrupts, These use a corresponding RTIMER_SECOND.

Note
These timers do not necessarily have a common divisor or are phase locked. One may be crystal controlled and the other may not. Low power operation or sleep will often use one for wake and disable the other, then give it a tick correction after wakeup.
The clock library need in many cases not be used directly. Rather, the timer library, event timers, or rtimer library should be used.
See Also
Timer library
Event timers
Realtime library

Function Documentation

void clock_delay ( unsigned int  i)
inline

Delay the CPU for a multiple of TODO.

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 150 of file clock.c.

References clock_delay_usec().

Referenced by leds_blink().

void clock_delay_usec ( uint16_t  len)

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!

Delay a given number of microseconds.

Parameters
lenDelay len uSecs

See clock_init() for GPT0 Timer A's configuration

Definition at line 196 of file clock.c.LOCAL.2341.c.

References DISABLE_INTERRUPTS, GPT_0_BASE, GPTIMER_CTL, GPTIMER_CTL_TAEN, GPTIMER_TAILR, and pic32_clock_get_system_clock().

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

void clock_init ( void  )

Initialize the clock library.

Start the clock by enabling the timer comparison interrupts.

This function initializes the clock library and should be called from the main() function of the system.

Initialize the clock library.

We initialise the SysTick to fire 128 interrupts per second, giving us a value of 128 for CLOCK_SECOND

We also initialise GPT0:Timer A, which is used by clock_delay_usec(). We use 16-bit range (individual), count-down, one-shot, no interrupts. The system clock is at 16MHz giving us 62.5 nano sec ticks for Timer A. Prescaled by 16 gives us a very convenient 1 tick per usec

set Timer/Counter0 to be asynchronous from the CPU clock with a second external clock(32,768kHz) driving it.

Wait for TCN0UB, OCR0UB, and TCR0UB.

Definition at line 116 of file clock.c.LOCAL.2341.c.

References ATOMIC, BIT, CLOCK_SECOND, GPT_0_BASE, GPTIMER_CFG, GPTIMER_CTL, GPTIMER_TAMR, GPTIMER_TAPR, NULL, RTIMER_NOW, rtimer_set(), SYS_CTRL_RCGCGPT, SYS_CTRL_RCGCGPT_GPT0, SysTick_CLKSourceConfig(), SysTick_CounterCmd(), SysTick_ITConfig(), and SysTick_SetReload().

Referenced by main().

unsigned long clock_seconds ( void  )

Get the current value of the platform seconds.

Return seconds, default is time since startup.

This could be the number of seconds since startup, or since a standard epoch.

Returns
The value.

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

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.LOCAL.2341.c.

References NULL.

Referenced by stimer_elapsed(), stimer_expired(), stimer_remaining(), stimer_restart(), and stimer_set().

void clock_set_seconds ( unsigned long  sec)

Set the value of the platform seconds.

Set seconds, e.g.

Parameters
secThe value to set.

to a standard epoch for an absolute date/time.

Set the value of the platform seconds.

to a standard epoch for an absolute date/time.

Definition at line 157 of file clock.c.LOCAL.2341.c.

clock_time_t clock_time ( void  )

Get the current clock time.

Return the tick counter.

This function returns the current system clock time.

Returns
The current clock time, measured in system ticks.

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.

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.

Examples:
example-rucb.c, and example-rudolph2.c.

Definition at line 129 of file clock.c.LOCAL.2341.c.

References NULL.

Referenced by clock_wait(), timer_expired(), timer_remaining(), timer_restart(), and timer_set().

void clock_wait ( clock_time_t  i)

Wait for a given number of ticks.

Wait for a number of clock ticks.

Parameters
tHow many ticks.

Definition at line 166 of file clock.c.LOCAL.2341.c.

References clock_time().