From 1d916d7c6b25de10c870cf7f35a44d3654d9f099 Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Fri, 26 Oct 2012 14:31:47 -0700 Subject: 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 Reviewed-on: https://gerrit.chromium.org/gerrit/36726 --- core/cortex-m/timer.c | 98 ++++++++++++++++++++++-------------------------- core/cortex-m/watchdog.c | 2 +- 2 files changed, 45 insertions(+), 55 deletions(-) (limited to 'core') diff --git a/core/cortex-m/timer.c b/core/cortex-m/timer.c index 5038706a24..de4310a88e 100644 --- a/core/cortex-m/timer.c +++ b/core/cortex-m/timer.c @@ -15,24 +15,25 @@ #include "task.h" #include "timer.h" -/* high word of the 64-bit timestamp counter */ +#define TIMER_SYSJUMP_TAG 0x4d54 /* "TM" */ + +/* High word of the 64-bit timestamp counter */ static volatile uint32_t clksrc_high; -/* bitmap of currently running timers */ +/* Bitmap of currently running timers */ static uint32_t timer_running = 0; -/* deadlines of all timers */ +/* Deadlines of all timers */ static timestamp_t timer_deadline[TASK_ID_COUNT]; static uint32_t next_deadline = 0xffffffff; /* Hardware timer routine IRQ number */ static int timer_irq; - static void expire_timer(task_id_t tskid) { /* we are done with this timer */ - atomic_clear(&timer_running, 1<le.hi; + timer_irq = __hw_clock_source_init(ts->le.lo); + } else { + clksrc_high = 0; + timer_irq = __hw_clock_source_init(0); + } +} + +/* Preserve time across a sysjump */ +static void timer_sysjump(void) +{ + timestamp_t ts = get_time(); + + system_add_jump_tag(TIMER_SYSJUMP_TAG, 1, sizeof(ts), &ts); +} +DECLARE_HOOK(HOOK_SYSJUMP, timer_sysjump, HOOK_PRIO_DEFAULT); + static int command_wait(int argc, char **argv) { char *e; @@ -221,7 +244,6 @@ DECLARE_CONSOLE_COMMAND(waitms, command_wait, "Busy-wait for msec", NULL); - static int command_get_time(int argc, char **argv) { timestamp_t ts = get_time(); @@ -234,45 +256,13 @@ DECLARE_CONSOLE_COMMAND(gettime, command_get_time, "Print current time", NULL); - int command_timer_info(int argc, char **argv) { timer_print_info(); + return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(timerinfo, command_timer_info, NULL, "Print timer info", NULL); - - -#define TIMER_SYSJUMP_TAG 0x4d54 /* "TM" */ - -/* Preserve time across a sysjump */ -static void timer_sysjump(void) -{ - timestamp_t ts = get_time(); - system_add_jump_tag(TIMER_SYSJUMP_TAG, 1, sizeof(ts), &ts); -} -DECLARE_HOOK(HOOK_SYSJUMP, timer_sysjump, HOOK_PRIO_DEFAULT); - -int timer_init(void) -{ - const timestamp_t *ts; - int size, version; - - BUILD_ASSERT(TASK_ID_COUNT < sizeof(timer_running) * 8); - - /* Restore time from before sysjump */ - ts = (const timestamp_t *)system_get_jump_tag(TIMER_SYSJUMP_TAG, - &version, &size); - if (ts && version == 1 && size == sizeof(timestamp_t)) { - clksrc_high = ts->le.hi; - timer_irq = __hw_clock_source_init(ts->le.lo); - } else { - clksrc_high = 0; - timer_irq = __hw_clock_source_init(0); - } - - return EC_SUCCESS; -} diff --git a/core/cortex-m/watchdog.c b/core/cortex-m/watchdog.c index 36e0ae43e1..fe8ba776bf 100644 --- a/core/cortex-m/watchdog.c +++ b/core/cortex-m/watchdog.c @@ -44,7 +44,7 @@ void watchdog_trace(uint32_t excep_lr, uint32_t excep_sp) void watchdog_task(void) { while (1) { - usleep(WATCHDOG_RELOAD_MS * 1000); + msleep(WATCHDOG_RELOAD_MS); watchdog_reload(); } } -- cgit v1.2.1