Skip to contentSkip to conversation

mx5/6 timer: Round up tick_to_time() value

PATCH New Benoît Thébaudeau 2 participants 3 messages Aug 14, 2012 – Aug 20, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mx5/6 timer: Round up tick_to_time() value

Round up tick_to_time() value instead of truncating it. This avoids stopping waits instantly for low usec values, and this generally guarantees that the code always waits for at least the requested duration.

---
 .../arch/arm/cpu/armv7/imx-common/timer.c          |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/cpu/armv7/imx-common/timer.c +1 -1
index 1645ff8..e2725e1 100644
@@ -61,7 +61,7 @@ static inline unsigned long long tick_to_time(unsigned long long tick)
 
 static inline unsigned long long us_to_tick(unsigned long long usec)
 {
-	usec *= CLK_32KHZ;
+	usec = usec * CLK_32KHZ + 999999;
 	do_div(usec, 1000000);
 
 	return usec;
#1 lore raw

PATCH 1/1 mx5/6 timer: Round up tick_to_time() value

Quoted 16 lines · Beno?t Th?baudeau

Round up tick_to_time() value instead of truncating it. This avoids stopping waits instantly for low usec values, and this generally guarantees that the code always waits for at least the requested duration.

---
 .../arch/arm/cpu/armv7/imx-common/timer.c          |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/cpu/armv7/imx-common/timer.c +0 -0
index 1645ff8..e2725e1 100644

arch/arm/cpu/armv7/imx-common/timer.c static inline unsigned long long tick_to_time(unsigned long long tick) · line 67

Quoted 8 lines
arch/arm/cpu/armv7/imx-common/timer.c +1 -1
@@ -61,7 +61,7 @@ static inline unsigned long long tick_to_time(unsigned long long tick)
 
 static inline unsigned long long us_to_tick(unsigned long long usec)
 {
-	usec *= CLK_32KHZ;
+	usec = usec * CLK_32KHZ + 999999;
 	do_div(usec, 1000000);
 
 	return usec;

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#2 lore raw

PATCH 1/1 mx5/6 timer: Round up tick_to_time() value

In reply to Benoît Thébaudeau
Quoted 16 lines · Beno?t Th?baudeau

Round up tick_to_time() value instead of truncating it. This avoids stopping waits instantly for low usec values, and this generally guarantees that the code always waits for at least the requested duration.

---
 .../arch/arm/cpu/armv7/imx-common/timer.c          |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/cpu/armv7/imx-common/timer.c +0 -0
index 1645ff8..e2725e1 100644

arch/arm/cpu/armv7/imx-common/timer.c static inline unsigned long long tick_to_time(unsigned long long tick) · line 67

Quoted 8 lines
arch/arm/cpu/armv7/imx-common/timer.c +1 -1
@@ -61,7 +61,7 @@ static inline unsigned long long tick_to_time(unsigned long long tick)
 
 static inline unsigned long long us_to_tick(unsigned long long usec)
 {
-	usec *= CLK_32KHZ;
+	usec = usec * CLK_32KHZ + 999999;
 	do_div(usec, 1000000);
 
 	return usec;

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================