cc2538: Allow for configuration of processor speed
This commit is contained in:
parent
730bda2001
commit
d8efa8428c
7 changed files with 107 additions and 38 deletions
|
@ -37,12 +37,12 @@
|
|||
* 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. 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.
|
||||
* 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.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
|
@ -62,7 +62,19 @@
|
|||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define RTIMER_CLOCK_TICK_RATIO (RTIMER_SECOND / CLOCK_SECOND)
|
||||
#define RELOAD_VALUE (125000 - 1) /** Fire 128 times / sec */
|
||||
|
||||
/* Prescaler for GPT0:Timer A used for clock_delay_usec(). */
|
||||
#if SYS_CTRL_SYS_CLOCK < SYS_CTRL_1MHZ
|
||||
#error System clock speeds below 1MHz are not supported
|
||||
#endif
|
||||
#define PRESCALER_VALUE (SYS_CTRL_SYS_CLOCK / SYS_CTRL_1MHZ - 1)
|
||||
|
||||
/* Reload value for SysTick counter */
|
||||
#if SYS_CTRL_SYS_CLOCK % CLOCK_SECOND
|
||||
/* Too low clock speeds will lead to reduced accurracy */
|
||||
#error System clock speed too slow for CLOCK_SECOND, accuracy reduced
|
||||
#endif
|
||||
#define RELOAD_VALUE (SYS_CTRL_SYS_CLOCK / CLOCK_SECOND - 1)
|
||||
|
||||
static volatile uint64_t rt_ticks_startup = 0, rt_ticks_epoch = 0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -74,8 +86,8 @@ static volatile uint64_t rt_ticks_startup = 0, rt_ticks_epoch = 0;
|
|||
*
|
||||
* 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
|
||||
* The prescaler is computed according to the system clock in order to get 1
|
||||
* tick per usec.
|
||||
*/
|
||||
void
|
||||
clock_init(void)
|
||||
|
@ -98,15 +110,14 @@ clock_init(void)
|
|||
/* Make sure GPT0 is off */
|
||||
REG(GPT_0_BASE + GPTIMER_CTL) = 0;
|
||||
|
||||
|
||||
/* 16-bit */
|
||||
REG(GPT_0_BASE + GPTIMER_CFG) = 0x04;
|
||||
|
||||
/* One-Shot, Count Down, No Interrupts */
|
||||
REG(GPT_0_BASE + GPTIMER_TAMR) = GPTIMER_TAMR_TAMR_ONE_SHOT;
|
||||
|
||||
/* Prescale by 16 (thus, value 15 in TAPR) */
|
||||
REG(GPT_0_BASE + GPTIMER_TAPR) = 0x0F;
|
||||
/* Prescale depending on system clock used */
|
||||
REG(GPT_0_BASE + GPTIMER_TAPR) = PRESCALER_VALUE;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
CCIF clock_time_t
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue