summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cpu/samsung/exynos5250/monotonic_timer.c28
-rw-r--r--src/cpu/samsung/exynos5420/monotonic_timer.c28
-rw-r--r--src/include/timer.h12
3 files changed, 20 insertions, 48 deletions
diff --git a/src/cpu/samsung/exynos5250/monotonic_timer.c b/src/cpu/samsung/exynos5250/monotonic_timer.c
index 57e3ae3104..267d9c3aef 100644
--- a/src/cpu/samsung/exynos5250/monotonic_timer.c
+++ b/src/cpu/samsung/exynos5250/monotonic_timer.c
@@ -18,40 +18,20 @@
*/
#include <stdint.h>
-#include <delay.h>
#include <timer.h>
#include "clk.h"
-static struct monotonic_counter {
- int initialized;
- struct mono_time time;
- uint64_t last_value;
-} mono_counter;
+static int initialized;
static const uint32_t clocks_per_usec = MCT_HZ/1000000;
void timer_monotonic_get(struct mono_time *mt)
{
- uint64_t current_tick;
- uint64_t usecs_elapsed;
-
- if (!mono_counter.initialized) {
+ if (!initialized) {
mct_start();
- mono_counter.last_value = mct_raw_value();
- mono_counter.initialized = 1;
- }
-
- current_tick = mct_raw_value();
- usecs_elapsed = (current_tick - mono_counter.last_value) /
- clocks_per_usec;
-
- /* Update current time and tick values only if a full tick occurred. */
- if (usecs_elapsed) {
- mono_time_add_usecs(&mono_counter.time, usecs_elapsed);
- mono_counter.last_value = current_tick;
+ initialized = 1;
}
- /* Save result. */
- *mt = mono_counter.time;
+ mono_time_set_usecs(mt, mct_raw_value() / clocks_per_usec);
}
diff --git a/src/cpu/samsung/exynos5420/monotonic_timer.c b/src/cpu/samsung/exynos5420/monotonic_timer.c
index 57e3ae3104..267d9c3aef 100644
--- a/src/cpu/samsung/exynos5420/monotonic_timer.c
+++ b/src/cpu/samsung/exynos5420/monotonic_timer.c
@@ -18,40 +18,20 @@
*/
#include <stdint.h>
-#include <delay.h>
#include <timer.h>
#include "clk.h"
-static struct monotonic_counter {
- int initialized;
- struct mono_time time;
- uint64_t last_value;
-} mono_counter;
+static int initialized;
static const uint32_t clocks_per_usec = MCT_HZ/1000000;
void timer_monotonic_get(struct mono_time *mt)
{
- uint64_t current_tick;
- uint64_t usecs_elapsed;
-
- if (!mono_counter.initialized) {
+ if (!initialized) {
mct_start();
- mono_counter.last_value = mct_raw_value();
- mono_counter.initialized = 1;
- }
-
- current_tick = mct_raw_value();
- usecs_elapsed = (current_tick - mono_counter.last_value) /
- clocks_per_usec;
-
- /* Update current time and tick values only if a full tick occurred. */
- if (usecs_elapsed) {
- mono_time_add_usecs(&mono_counter.time, usecs_elapsed);
- mono_counter.last_value = current_tick;
+ initialized = 1;
}
- /* Save result. */
- *mt = mono_counter.time;
+ mono_time_set_usecs(mt, mct_raw_value() / clocks_per_usec);
}
diff --git a/src/include/timer.h b/src/include/timer.h
index 06128ce6c3..b37cea45da 100644
--- a/src/include/timer.h
+++ b/src/include/timer.h
@@ -67,6 +67,18 @@ int timers_run(void);
* 0 returned on success, < 0 on error. */
int timer_sched_callback(struct timeout_callback *tocb, unsigned long us);
+/* Set an absolute time to a number of microseconds. */
+static inline void mono_time_set_usecs(struct mono_time *mt, long us)
+{
+ mt->microseconds = us;
+}
+
+/* Set an absolute time to a number of milliseconds. */
+static inline void mono_time_set_msecs(struct mono_time *mt, long ms)
+{
+ mt->microseconds = ms * USECS_PER_MSEC;
+}
+
/* Add microseconds to an absolute time. */
static inline void mono_time_add_usecs(struct mono_time *mt, long us)
{