public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] net/net.c: correct timeout function
@ 2008-11-28 16:25 Daniel Mack
  2008-12-03  0:31 ` Daniel Mack
  2008-12-03  0:58 ` Daniel Mack
  0 siblings, 2 replies; 16+ messages in thread
From: Daniel Mack @ 2008-11-28 16:25 UTC (permalink / raw)
  To: u-boot

Hi,

the net/net.c implemenation of timeouts assumes that get_timer() returns
values in milliseconds. As this is true for most platforms, it does not
apply to PXA3x where the OSCR register increments with more than 3MHz.

The following patch fixes the problem by calculation with the
CONFIG_SYS_HZ variable.

Best regards,
Daniel


diff --git a/net/net.c b/net/net.c
index 77e83b5..b9326de 100644
--- a/net/net.c
+++ b/net/net.c
@@ -206,6 +206,11 @@ uchar		NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN];
 ulong		NetArpWaitTimerStart;
 int		NetArpWaitTry;
 
+static long net_get_timer(long base)
+{
+	return get_timer(base) / (CONFIG_SYS_HZ / 1000);
+}
+
 void ArpRequest (void)
 {
 	int i;
@@ -256,7 +261,7 @@ void ArpTimeoutCheck(void)
 	if (!NetArpWaitPacketIP)
 		return;
 
-	t = get_timer(0);
+	t = net_get_timer(0);
 
 	/* check for arp timeout */
 	if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT) {
@@ -517,7 +522,7 @@ restart:
 		 *	Check for a timeout, and run the timeout handler
 		 *	if we have one.
 		 */
-		if (timeHandler && ((get_timer(0) - timeStart) > timeDelta)) {
+		if (timeHandler && ((net_get_timer(0) - timeStart) > timeDelta)) {
 			thand_f *x;
 
 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
@@ -639,7 +644,7 @@ NetSetTimeout(ulong iv, thand_f * f)
 		timeHandler = (thand_f *)0;
 	} else {
 		timeHandler = f;
-		timeStart = get_timer(0);
+		timeStart = net_get_timer(0);
 		timeDelta = iv;
 	}
 }
@@ -684,7 +689,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
 
 		/* and do the ARP request */
 		NetArpWaitTry = 1;
-		NetArpWaitTimerStart = get_timer(0);
+		NetArpWaitTimerStart = net_get_timer(0);
 		ArpRequest();
 		return 1;	/* waiting */
 	}
@@ -755,7 +760,7 @@ int PingSend(void)
 
 	/* and do the ARP request */
 	NetArpWaitTry = 1;
-	NetArpWaitTimerStart = get_timer(0);
+	NetArpWaitTimerStart = net_get_timer(0);
 	ArpRequest();
 	return 1;	/* waiting */
 }

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2008-12-06 16:53 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-28 16:25 [U-Boot] [PATCH] net/net.c: correct timeout function Daniel Mack
2008-12-03  0:31 ` Daniel Mack
2008-12-03  0:43   ` Ben Warren
2008-12-03  1:05     ` Daniel Mack
2008-12-03 17:57       ` Ben Warren
2008-12-03  0:58 ` Daniel Mack
2008-12-05  6:48   ` Ben Warren
2008-12-05 14:40     ` [U-Boot] [PATCH] net/net.c: add get_timer_ms() Daniel Mack
2008-12-05 20:26       ` Wolfgang Denk
2008-12-05 20:43         ` Daniel Mack
2008-12-05 21:01           ` Wolfgang Denk
2008-12-05 21:07             ` Daniel Mack
2008-12-05 21:16               ` Wolfgang Denk
2008-12-06 16:53                 ` Daniel Mack
2008-12-05 20:29     ` [U-Boot] [PATCH] net/net.c: correct timeout function Wolfgang Denk
2008-12-05 21:01       ` Ben Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox