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 /include | |
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 'include')
-rw-r--r-- | include/charge_state.h | 6 | ||||
-rw-r--r-- | include/timer.h | 85 |
2 files changed, 70 insertions, 21 deletions
diff --git a/include/charge_state.h b/include/charge_state.h index eda78abfd9..0a4cd869da 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -9,12 +9,6 @@ #ifndef __CROS_EC_CHARGE_STATE_H #define __CROS_EC_CHARGE_STATE_H -/* Time constants */ -#define MSEC (1000ULL) -#define SECOND (MSEC * 1000) -#define MINUTE (SECOND * 60) -#define HOUR (MINUTE * 60) - /* Update period to prevent charger watchdog timeout */ #define CHARGER_UPDATE_PERIOD (SECOND * 10) diff --git a/include/timer.h b/include/timer.h index 0a4273ff25..b13e0a62a0 100644 --- a/include/timer.h +++ b/include/timer.h @@ -11,6 +11,12 @@ #include "common.h" #include "task_id.h" +/* Time units in microseconds */ +#define MSEC 1000 +#define SECOND 1000000 +#define MINUTE 60000000 +#define HOUR 3600000000ull /* Too big to fit in a signed int */ + /* Microsecond timestamp. */ typedef union { uint64_t val; @@ -20,15 +26,27 @@ typedef union { } le /* little endian words */; } timestamp_t; -/* Initializes the Timer module. */ -int timer_init(void); +/** + * Initialize the timer module. + */ +void timer_init(void); -/* Launch a one-shot timer for task <tskid> which expires at timestamp - * <tstamp>. */ +/** + * Launch a one-shot timer for a task. + * + * Note that each task can have only a single active timer. + * + * @param tstamp Expiration timestamp for timer + * @param tskid Task to set timer for + * + * @return EC_SUCCESS, or non-zero if error. + */ int timer_arm(timestamp_t tstamp, task_id_t tskid); -/* Cancel a running timer for the specified task id. */ -int timer_cancel(task_id_t tskid); +/** + * Cancel a running timer for the specified task id. + */ +void timer_cancel(task_id_t tskid); /** * Check if a timestamp has passed / expired @@ -39,30 +57,67 @@ int timer_cancel(task_id_t tskid); */ int timestamp_expired(timestamp_t deadline, const timestamp_t *now); -/* Busy-wait the selected number of microseconds. Note that calling this - * with us>1000 may impact system performance; use usleep for longer delays. */ +/** + * Busy-wait. + * + * Note that calling this with us>1000 may impact system performance; use + * usleep() for longer delays. + * + * @param us Number of microseconds to delay. + */ void udelay(unsigned us); -/* Sleep during the selected number of microseconds. The current task will be - * de-scheduled until the delay expires. +/** + * Sleep. + * + * The current task will be de-scheduled for at least the specified delay (and + * perhaps longer, if a higher-priority task is running when the delay + * expires). * - * Note: if an event happens before the end of sleep, the function will return. + * @param us Number of microseconds to sleep. */ void usleep(unsigned us); -/* Get the current timestamp from the system timer. */ +/** + * Sleep for milliseconds + * + * @param ms Number of milliseconds to sleep. + */ +static inline void msleep(unsigned ms) +{ + usleep(ms * MSEC); +} + +/** + * Sleep for seconds + * + * @param sec Number of seconds to sleep. + */ +static inline void sleep(unsigned sec) +{ + usleep(sec * SECOND); +} + +/** + * Get the current timestamp from the system timer. + */ timestamp_t get_time(void); -/* Force the current value of the system timer. +/** + * Force the current value of the system timer. * * This function is for the power management implementation which wants to fix * the system time when waking up from a mode with clocks turned off. + * * Note: must be called with interrupts disabled. */ void force_time(timestamp_t ts); -/* Print the current timer information using the command output channel. This - * may be called from interrupt level. */ +/** + * Print the current timer information using the command output channel. + * + * This may be called from interrupt level. + */ void timer_print_info(void); /** |