summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-10-26 14:31:47 -0700
committerGerrit <chrome-bot@google.com>2012-10-29 16:52:49 -0700
commit1d916d7c6b25de10c870cf7f35a44d3654d9f099 (patch)
tree5d7337654d86766324103217ab61ae0b71d65e0f /core
parent67aadcf614513353d7c9a0216fc70f7af18d8d05 (diff)
downloadchrome-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 'core')
-rw-r--r--core/cortex-m/timer.c98
-rw-r--r--core/cortex-m/watchdog.c2
2 files changed, 45 insertions, 55 deletions
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<<tskid);
+ atomic_clear(&timer_running, 1 << tskid);
/* wake up the taks waiting for this timer */
task_set_event(tskid, TASK_EVENT_TIMER, 0);
}
@@ -59,7 +60,7 @@ void process_timers(int overflow)
clksrc_high++;
do {
- next.val = 0xffffffffffffffff;
+ next.val = -1ull;
now = get_time();
do {
/* read atomically the current state of timer running */
@@ -93,7 +94,6 @@ void process_timers(int overflow)
} while (next.val <= get_time().val);
}
-
void udelay(unsigned us)
{
timestamp_t deadline = get_time();
@@ -102,7 +102,6 @@ void udelay(unsigned us)
while (get_time().val < deadline.val) {}
}
-
int timer_arm(timestamp_t tstamp, task_id_t tskid)
{
ASSERT(tskid < TASK_ID_COUNT);
@@ -113,7 +112,7 @@ int timer_arm(timestamp_t tstamp, task_id_t tskid)
timer_deadline[tskid] = tstamp;
atomic_or(&timer_running, 1<<tskid);
- /* modify the next event if needed */
+ /* Modify the next event if needed */
if ((tstamp.le.hi < clksrc_high) ||
((tstamp.le.hi == clksrc_high) && (tstamp.le.lo <= next_deadline)))
task_trigger_irq(timer_irq);
@@ -121,20 +120,17 @@ int timer_arm(timestamp_t tstamp, task_id_t tskid)
return EC_SUCCESS;
}
-
-int timer_cancel(task_id_t tskid)
+void timer_cancel(task_id_t tskid)
{
ASSERT(tskid < TASK_ID_COUNT);
- atomic_clear(&timer_running, 1<<tskid);
- /* don't bother about canceling the interrupt:
- * it would be slow, just do it on the next IT
+ atomic_clear(&timer_running, 1 << tskid);
+ /*
+ * Don't need to cancel the interrupt: it would be slow, just do it on
+ * the next IT
*/
-
- return EC_SUCCESS;
}
-
void usleep(unsigned us)
{
uint32_t evt = 0;
@@ -149,13 +145,13 @@ void usleep(unsigned us)
do {
evt |= task_wait_event(us);
} while (!(evt & TASK_EVENT_TIMER));
- /* re-queue other events which happened in the meanwhile */
+
+ /* Re-queue other events which happened in the meanwhile */
if (evt)
atomic_or(task_get_event_bitmap(task_get_current()),
evt & ~TASK_EVENT_TIMER);
}
-
timestamp_t get_time(void)
{
timestamp_t ts;
@@ -168,7 +164,6 @@ timestamp_t get_time(void)
return ts;
}
-
void force_time(timestamp_t ts)
{
clksrc_high = ts.le.hi;
@@ -200,6 +195,34 @@ void timer_print_info(void)
}
}
+void 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);
+ }
+}
+
+/* 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();
}
}