All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] sh: Update sh2/sh2a timer
Date: Tue, 09 Dec 2008 11:32:46 +0900	[thread overview]
Message-ID: <493DD8CE.9090604@renesas.com> (raw)

Renesas SH2/SH2A timer broken.
This patch fix timer function.

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
---
 lib_sh/time_sh2.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib_sh/time_sh2.c b/lib_sh/time_sh2.c
index fcbb921..4f893c8 100644
--- a/lib_sh/time_sh2.c
+++ b/lib_sh/time_sh2.c
@@ -65,8 +65,8 @@ unsigned long long get_ticks(void)
 	return cmt0_timer;
 }

-static vu_long cmcnt;
-ulong get_timer(ulong base)
+static vu_long cmcnt = 0;
+static unsigned long get_usec (void)
 {
 	ulong data = readw(CMCNT_0);

@@ -81,7 +81,13 @@ ulong get_timer(ulong base)
 		cmt0_timer += cmcnt;

 	cmcnt = data;
-	return cmt0_timer - base;
+	return cmt0_timer;
+}
+
+/* return msec */
+ulong get_timer(ulong base)
+{
+	return (get_usec()/1000) - base;
 }

 void set_timer(ulong t)
@@ -99,9 +105,9 @@ void reset_timer(void)

 void udelay(unsigned long usec)
 {
-	unsigned int start = get_timer(0);
+	unsigned long end = get_usec() + usec;

-	while (get_timer((ulong) start) < (usec * (CONFIG_SYS_HZ / 1000000)))
+	while (get_usec() < end)
 		continue;
 }

-- 1.5.6.5

                 reply	other threads:[~2008-12-09  2:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=493DD8CE.9090604@renesas.com \
    --to=iwamatsu.nobuhiro@renesas.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.