diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-10-26 14:31:47 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-10-29 16:52:49 -0700 |
commit | 1d916d7c6b25de10c870cf7f35a44d3654d9f099 (patch) | |
tree | 5d7337654d86766324103217ab61ae0b71d65e0f /chip/lm4/hwtimer.c | |
parent | 67aadcf614513353d7c9a0216fc70f7af18d8d05 (diff) | |
download | chrome-ec-1d916d7c6b25de10c870cf7f35a44d3654d9f099.tar.gz |
Use SECOND and MSEC constants
We'd defined them in a number of different files. This moves
definitions to timer.h, and uses them everywhere we have large delays
(since 10*SECOND is less typo-prone than 10000000).
Also add msleep() and sleep() inline functions. No need for mdelay()
or delay(), since any delays that long should use sleep funcs instead
of spin-waiting.
BUG=chrome-os-partner:15579
BRANCH=none
TEST=boot system; taskinfo displays similar numbers to before
Change-Id: I2a92a9f10f46b6b7b6571759b1f8ab4ecfbf8259
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/36726
Diffstat (limited to 'chip/lm4/hwtimer.c')
-rw-r--r-- | chip/lm4/hwtimer.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/chip/lm4/hwtimer.c b/chip/lm4/hwtimer.c index 45166f2194..cbf28f5294 100644 --- a/chip/lm4/hwtimer.c +++ b/chip/lm4/hwtimer.c @@ -5,14 +5,13 @@ /* Hardware timers driver */ -#include "board.h" #include "clock.h" +#include "common.h" #include "hooks.h" #include "hwtimer.h" #include "registers.h" #include "task.h" - -#define US_PER_SECOND 1000000 +#include "timer.h" void __hw_clock_event_set(uint32_t deadline) { @@ -22,63 +21,60 @@ void __hw_clock_event_set(uint32_t deadline) LM4_TIMER_IMR(6) |= 0x10; } - uint32_t __hw_clock_event_get(void) { return 0xffffffff - LM4_TIMER_TAMATCHR(6); } - void __hw_clock_event_clear(void) { /* Disable the match interrupt */ LM4_TIMER_IMR(6) &= ~0x10; } - uint32_t __hw_clock_source_read(void) { return 0xffffffff - LM4_TIMER_TAV(6); } - void __hw_clock_source_set(uint32_t ts) { LM4_TIMER_TAV(6) = 0xffffffff - ts; } - static void __hw_clock_source_irq(void) { uint32_t status = LM4_TIMER_RIS(6); - /* clear interrupt */ + /* Clear interrupt */ LM4_TIMER_ICR(6) = status; /* - * Find expired timers and set the new timer deadline - * get from the IRQ status if the free running counter as overflowed + * Find expired timers and set the new timer deadline; check the IRQ + * status to determine if the free-running counter overflowed. */ process_timers(status & 0x01); } DECLARE_IRQ(LM4_IRQ_TIMERW0A, __hw_clock_source_irq, 1); - static void update_prescaler(void) { - /* Set the prescaler to increment every microsecond. This takes - * effect immediately, because the TAILD bit in TAMR is clear. */ - LM4_TIMER_TAPR(6) = clock_get_freq() / US_PER_SECOND; + /* + * Set the prescaler to increment every microsecond. This takes + * effect immediately, because the TAILD bit in TAMR is clear. + */ + LM4_TIMER_TAPR(6) = clock_get_freq() / SECOND; } DECLARE_HOOK(HOOK_FREQ_CHANGE, update_prescaler, HOOK_PRIO_DEFAULT); - int __hw_clock_source_init(uint32_t start_t) { volatile uint32_t scratch __attribute__((unused)); - /* Use WTIMER0 (timer 6) configured as a free running counter with 1 us - * period */ + /* + * Use WTIMER0 (timer 6) configured as a free running counter with 1 us + * period. + */ /* Enable WTIMER0 clock */ LM4_SYSTEM_RCGCWTIMER |= 1; @@ -101,8 +97,11 @@ int __hw_clock_source_init(uint32_t start_t) LM4_TIMER_TAILR(6) = 0xffffffff; /* Starts counting in timer A */ LM4_TIMER_CTL(6) |= 0x1; - /* Override the count with the start value now that counting has - * started. */ + + /* + * Override the count with the start value now that counting has + * started. + */ __hw_clock_source_set(start_t); /* Enable interrupt */ |