From: Tomohiro Masubuchi <tomohiro_masubuchi@tripeaks.co.jp>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH][iMX31] Change to use "do_div" macro
Date: Mon, 20 Oct 2008 16:06:25 +0900 [thread overview]
Message-ID: <48FC2DF1.6020300@tripeaks.co.jp> (raw)
I tryed to build u-boot by Sourcery G++ Lite 2008q3-41 for ARM GNU/Linux.
But, it was failed with some link error of divide function.
Thus, I changed to use the "do_div" macro to calculate the dividing.
In my environment, the "next" branch with this patch worked correctly.
Signed-off-by: Tomohiro Masubuchi <tomohiro_masubuchi@tripeaks.co.jp>
----
Change to use the "do_div" macro.
cpu/arm1136/mx31/interrupts.c | 36 ++++++++++++++++++++++++++++++------
1 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/cpu/arm1136/mx31/interrupts.c b/cpu/arm1136/mx31/interrupts.c
index b36c58c..807e791 100644
--- a/cpu/arm1136/mx31/interrupts.c
+++ b/cpu/arm1136/mx31/interrupts.c
@@ -23,6 +23,7 @@
#include <common.h>
#include <asm/arch/mx31-regs.h>
+#include <div64.h>
#define TIMER_BASE 0x53f90000 /* General purpose timer 1 */
@@ -41,17 +42,40 @@
/* "time" is measured in 1 / CONFIG_SYS_HZ seconds, "tick" is internal timer period */
#ifdef CONFIG_MX31_TIMER_HIGH_PRECISION
/* ~0.4% error - measured with stop-watch on 100s boot-delay */
-#define TICK_TO_TIME(t) ((t) * CONFIG_SYS_HZ / CONFIG_MX31_CLK32)
-#define TIME_TO_TICK(t) ((unsigned long long)(t) * CONFIG_MX31_CLK32 / CONFIG_SYS_HZ)
-#define US_TO_TICK(t) (((unsigned long long)(t) * CONFIG_MX31_CLK32 + \
- 999999) / 1000000)
+#define TICK_TO_TIME(t) ({ \
+ unsigned long long tmp = (t); \
+ t *= CONFIG_SYS_HZ; \
+ do_div(tmp, CONFIG_MX31_CLK32); \
+ tmp; \
+ })
+#define TIME_TO_TICK(t) ({ \
+ unsigned long long tmp = (t); \
+ tmp *= CONFIG_MX31_CLK32; \
+ do_div(tmp, CONFIG_SYS_HZ); \
+ tmp; \
+ })
+#define US_TO_TICK(t) ({ \
+ unsigned long long tmp = (t); \
+ tmp = tmp * CONFIG_MX31_CLK32 + 999999; \
+ do_div(tmp, 1000000); \
+ tmp; \
+ })
#else
/* ~2% error */
#define TICK_PER_TIME ((CONFIG_MX31_CLK32 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ)
#define US_PER_TICK (1000000 / CONFIG_MX31_CLK32)
-#define TICK_TO_TIME(t) ((t) / TICK_PER_TIME)
+#define TICK_TO_TIME(t) ({ \
+ unsigned long long tmp = (t); \
+ do_div(tmp, TICK_PER_TIME); \
+ tmp; \
+ })
#define TIME_TO_TICK(t) ((unsigned long long)(t) * TICK_PER_TIME)
-#define US_TO_TICK(t) (((t) + US_PER_TICK - 1) / US_PER_TICK)
+#define US_TO_TICK(t) ({ \
+ unsigned long long tmp = (t); \
+ tmp += US_PER_TICK - 1; \
+ do_div(tmp, US_PER_TICK); \
+ tmp; \
+ })
#endif
static ulong timestamp;
next reply other threads:[~2008-10-20 7:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-20 7:06 Tomohiro Masubuchi [this message]
2008-10-20 11:21 ` [U-Boot] [PATCH][iMX31] Change to use "do_div" macro Jean-Christophe PLAGNIOL-VILLARD
2008-10-21 4:17 ` [U-Boot] [PATCHv2][iMX31] " Tomohiro Masubuchi
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=48FC2DF1.6020300@tripeaks.co.jp \
--to=tomohiro_masubuchi@tripeaks.co.jp \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox