Contiki-Inga 3.x
|
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... | |
CCIF 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... | |
CCIF 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 len) |
Arch-specific implementation of clock_delay_usec for the cc2538. More... | |
void | clock_delay (unsigned int i) |
Obsolete delay function but we implement it here since some code still uses it. More... | |
void | clock_adjust (clock_time_t ticks) |
Adjust the clock by moving it forward by a number of ticks. More... | |
void | clock_isr (void) |
The clock Interrupt Service Routine. More... | |
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 16 MHz and we set the SysTick to give us 128 interrupts / sec
void clock_adjust | ( | clock_time_t | ticks | ) |
Adjust the clock by moving it forward by a number of ticks.
ticks | The number of ticks |
This function is useful when coming out of PM1/2, during which the system clock is stopped. We adjust the clock by moving it forward by a number of ticks equal to the deep sleep duration. We update the seconds counter if we have to and we also do some housekeeping so that the next second will increment when it is meant to.
|
inline |
Obsolete delay function but we implement it here since some code still uses it.
Delay the CPU for a multiple of TODO.
Definition at line 157 of file clock.c.
References clock_delay_usec().
void clock_delay_usec | ( | uint16_t | len | ) |
Arch-specific implementation of clock_delay_usec for the cc2538.
Delay a given number of microseconds.
len | Delay len uSecs |
See clock_init() for GPT0 Timer A's configuration
Definition at line 143 of file clock.c.
References GPT_0_BASE, GPTIMER_CTL, GPTIMER_CTL_TAEN, and GPTIMER_TAILR.
Referenced by cc2430_rf_command(), clock_delay(), clock_delay_msec(), and mrf24j40_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 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
Definition at line 76 of file clock.c.
References GPT_0_BASE, GPTIMER_CFG, GPTIMER_CTL, GPTIMER_TAMR, GPTIMER_TAPR, SYS_CTRL_RCGCGPT, and SYS_CTRL_RCGCGPT_GPT0.
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 since reset.
Definition at line 208 of file clock.c.
References CLOCK_SECOND, DISABLE_INTERRUPTS, etimer_next_expiration_time(), etimer_pending(), and etimer_request_poll().
CCIF 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.
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.
void clock_set_seconds | ( | unsigned long | sec | ) |
CCIF clock_time_t clock_time | ( | void | ) |
Get the current clock time.
Return the tick counter.
This function returns the current system 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.
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.
void clock_wait | ( | clock_time_t | i | ) |
Wait for a given number of ticks.
Wait for a number of clock ticks.
t | How many ticks. |
Definition at line 128 of file clock.c.
References clock_time().