Contiki-NG
Files | Functions

Implementation of the clock module for the cc2538. More...

Files

file  clock.c
 Clock driver implementation for the TI cc2538.
 

Functions

void clock_init (void)
 Arch-specific implementation of clock_init for the cc2538. More...
 
clock_time_t clock_time (void)
 Get the current clock time. More...
 
void clock_set_seconds (unsigned long sec)
 Set the value of the platform seconds. More...
 
unsigned long clock_seconds (void)
 Get the current value of the platform seconds. More...
 
void clock_wait (clock_time_t i)
 Wait for a given number of ticks. More...
 
void clock_delay_usec (uint16_t dt)
 Delay a given number of microseconds. More...
 
void clock_delay (unsigned int i)
 Obsolete delay function but we implement it here since some code still uses it.
 
static void update_ticks (void)
 Update the software clock ticks and seconds. More...
 
void clock_adjust (void)
 Adjust the clock following missed SysTick ISRs. More...
 
void clock_isr (void)
 The clock Interrupt Service Routine. More...
 

Detailed Description

Implementation of the clock module for the cc2538.

To implement the clock functionality, we use the SysTick peripheral on the cortex-M3. We run the system clock at a configurable speed and set the SysTick to give us 128 interrupts / sec. However, the Sleep Timer counter value is used for the number of elapsed ticks in order to avoid a significant time drift caused by PM1/2. Contrary to the Sleep Timer, the SysTick peripheral is indeed frozen during PM1/2, so adjusting upon wake-up a tick counter based on this peripheral would hardly be accurate.

Function Documentation

◆ clock_adjust()

void clock_adjust ( void  )

Adjust the clock following missed SysTick ISRs.

This function is useful when coming out of PM1/2, during which the system clock is stopped. We adjust the clock counters like after any SysTick ISR.

Note
This function is only meant to be used by lpm_exit(). Applications should really avoid calling this

Definition at line 224 of file clock.c.

References SysTick, SysTick_CTRL_ENABLE_Msk, and update_ticks().

◆ clock_delay_usec()

void clock_delay_usec ( uint16_t  dt)

Delay a given number of microseconds.

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

Definition at line 150 of file clock.c.

◆ clock_init()

void clock_init ( void  )

Arch-specific implementation of clock_init for the cc2538.

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 prescaler is computed according to the system clock in order to get 1 tick per usec.

Definition at line 93 of file clock.c.

Referenced by soc_init().

◆ clock_isr()

void clock_isr ( void  )

The clock Interrupt Service Routine.

It polls the etimer process if an etimer has expired. It also updates the software clock tick and seconds counter.

Definition at line 242 of file clock.c.

References update_ticks().

◆ clock_seconds()

unsigned long clock_seconds ( void  )

Get the current value of the platform seconds.

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

Returns
The value.

Definition at line 130 of file clock.c.

Referenced by platform_idle().

◆ clock_set_seconds()

void clock_set_seconds ( unsigned long  sec)

Set the value of the platform seconds.

Parameters
secThe value to set.

Definition at line 124 of file clock.c.

◆ clock_time()

clock_time_t clock_time ( void  )

Get the current clock time.

This function returns the current system clock time.

Returns
The current clock time, measured in system ticks.

Definition at line 118 of file clock.c.

Referenced by clock_seconds(), and gpiote_event_handler().

◆ clock_wait()

void clock_wait ( clock_time_t  t)

Wait for a given number of ticks.

Parameters
tHow many ticks.

Definition at line 136 of file clock.c.

Referenced by platform_init_stage_two().

◆ update_ticks()

static void update_ticks ( void  )
static

Update the software clock ticks and seconds.

This function is used to update the software tick counters whenever the system clock might have changed, which can occur upon a SysTick ISR or upon wake-up from PM1/2.

For the software clock ticks counter, the Sleep Timer counter value is used as the base tick value, and extended to a 64-bit value thanks to a detection of wraparounds.

For the seconds counter, the changes of the Sleep Timer counter value are added to the reference time, which is either the startup time or the value passed to clock_set_seconds().

This function polls the etimer process if an etimer has expired.

Definition at line 187 of file clock.c.

References RTIMER_NOW.

Referenced by clock_adjust(), and clock_isr().