summaryrefslogtreecommitdiffstats
path: root/common/clock.c
diff options
context:
space:
mode:
authorNishanth Menon <x0nishan@ti.com>2008-06-05 19:45:08 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2008-06-05 19:45:08 +0200
commiteb208c746dc7a28237a24ffe50e31d4f829ead90 (patch)
tree9c2d6f6696a9888b1f1d60310c7c8e96234fc7bf /common/clock.c
parent9a364f5157fe73e3e1d5ce5f66b2408a94c40eca (diff)
downloadbarebox-eb208c746dc7a28237a24ffe50e31d4f829ead90.tar.gz
002-clock-overflow
[Patch 02/17] U-Boot-V2: Handle case of clock rollover for get_time_ns get_time_ns does a simplistic delta = cycle_now - cycle_last. It is possible that the h/w counter reached max and reset back to 0. This patch addresses this issue by checking for rollover condition. NOTE 1: This does not guarentee that you cannot confuse get_time_ns. You could possibly wait for two reset cycles and then get a messed up value. To fix that we may need interrupt mode timer tick - something on the lines of jiffies on linux. NOTE 2: the question of cs->mask is not clear. if the mask is for the tick, then it is better done with (cycle_now & cs->mask) - (cs->cycle_last & cs->mask). Signed-off-by: Nishanth Menon<x0nishan@ti.com>
Diffstat (limited to 'common/clock.c')
-rw-r--r--common/clock.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/common/clock.c b/common/clock.c
index 4069d4e..e22b6a5 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -41,7 +41,7 @@ uint64_t get_time_ns(void)
uint64_t ns_offset;
/* read clocksource: */
- cycle_now = cs->read();
+ cycle_now = cs->read() & cs->mask;
/* calculate the delta since the last call: */
cycle_delta = (cycle_now - cs->cycle_last) & cs->mask;