Patchwork [3/3] udelay.c: usleep() not found in MinGW, used Sleep()

login
register
about
Submitter Carl-Daniel Hailfinger
Date 2013-04-02 23:21:11
Message ID <515B67E7.2000302@gmx.net>
Download mbox | patch
Permalink /patch/3929/
State Accepted
Commit r1667
Headers show

Comments

Carl-Daniel Hailfinger - 2013-04-02 23:21:11
Am 03.04.2013 00:27 schrieb Carl-Daniel Hailfinger:
> Am 02.04.2013 22:58 schrieb Stefan Tauner:
>> On Mon, 1 Apr 2013 19:08:30 +0400
>> Maksim Kuleshov <mmcx@ucs.ru> wrote:
>>
>>> From 62ffe98744aba140e5959635abb46c32a47887d2 Mon Sep 17 00:00:00 2001
>>> From: Maksim Kuleshov <mmcx@mail.ru>
>>> Date: Mon, 1 Apr 2013 19:03:43 +0400
>>> Subject: [PATCH 3/3] udelay.c: usleep() not found in MinGW, used Sleep()
>>>
>>> Signed-off-by: Maksim Kuleshov <mmcx@mail.ru>
>> I don't think that we ever had a problem with that. (Please correct
>> me... Idwer?). What version of MinGW are you using? What's your make
>> command and what does it print as error?
> If it fixes a real problem (I didn't need the patch in my
> cross-compile-for-mingw environment), this looks sane.
> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>

I now see that the patch is correct. However, the code for non-Windows
was broken as well (too big values for udelay), so I extended your patch
a bit.

usleep() is not found in all versions of MinGW, use Sleep() on Windows.
Handle long sleeps on non-Windows correctly.

Signed-off-by: Maksim Kuleshov <mmcx@mail.ru>
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Stefan Tauner - 2013-04-04 00:20:03
On Wed, 03 Apr 2013 01:21:11 +0200
Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> wrote:

> I now see that the patch is correct. However, the code for non-Windows
> was broken as well (too big values for udelay), so I extended your patch
> a bit.
> 
> usleep() is not found in all versions of MinGW, use Sleep() on Windows.
> Handle long sleeps on non-Windows correctly.
> 
> Signed-off-by: Maksim Kuleshov <mmcx@mail.ru>
> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>

Looks good to me.
Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>

Everybody is invited to work on the following when the patch has been
merged:
http://www.flashrom.org/Easy_projects#Replace_programmer_delay.28.29_with_internal_sleep.28.29_where_appropriate
Carl-Daniel Hailfinger - 2013-04-05 08:15:38
Am 04.04.2013 02:20 schrieb Stefan Tauner:
> On Wed, 03 Apr 2013 01:21:11 +0200
> Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> wrote:
>
>> I now see that the patch is correct. However, the code for non-Windows
>> was broken as well (too big values for udelay), so I extended your patch
>> a bit.
>>
>> usleep() is not found in all versions of MinGW, use Sleep() on Windows.
>> Handle long sleeps on non-Windows correctly.
>>
>> Signed-off-by: Maksim Kuleshov <mmcx@mail.ru>
>> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
> Looks good to me.
> Acked-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at>

Thanks, committed in r1667.


> Everybody is invited to work on the following when the patch has been
> merged:
> http://www.flashrom.org/Easy_projects#Replace_programmer_delay.28.29_with_internal_sleep.28.29_where_appropriate

Indeed.

Regards,
Carl-Daniel

Patch

Index: flashrom-long_delay_fix/buspirate_spi.c
===================================================================
--- flashrom-long_delay_fix/buspirate_spi.c	(Revision 1666)
+++ flashrom-long_delay_fix/buspirate_spi.c	(Arbeitskopie)
@@ -286,7 +286,7 @@ 
 		/* The Bus Pirate can't handle UART input buffer overflow in BBIO mode, and sending a sequence
 		 * of 0x00 too fast apparently triggers such an UART input buffer overflow.
 		 */
-		usleep(10000);
+		internal_sleep(10000);
 	}
 	/* We know that 20 commands of \0 should elicit at least one BBIO1 response. */
 	if ((ret = buspirate_wait_for_string(bp_commbuf, "BBIO")))
Index: flashrom-long_delay_fix/programmer.h
===================================================================
--- flashrom-long_delay_fix/programmer.h	(Revision 1666)
+++ flashrom-long_delay_fix/programmer.h	(Arbeitskopie)
@@ -250,6 +250,7 @@ 
 /* udelay.c */
 void myusec_delay(int usecs);
 void myusec_calibrate_delay(void);
+void internal_sleep(int usecs);
 void internal_delay(int usecs);
 
 #if CONFIG_INTERNAL == 1
Index: flashrom-long_delay_fix/udelay.c
===================================================================
--- flashrom-long_delay_fix/udelay.c	(Revision 1666)
+++ flashrom-long_delay_fix/udelay.c	(Arbeitskopie)
@@ -169,13 +169,23 @@ 
 	msg_pinfo("OK.\n");
 }
 
+/* Not very precise sleep. */
+void internal_sleep(int usecs)
+{
+#ifdef _WIN32
+	Sleep((usecs + 999) / 1000);
+#else
+	sleep(usecs / 1000000);
+	usleep(usecs % 1000000);
+#endif
+}
+
+/* Precise delay. */
 void internal_delay(int usecs)
 {
-	/* If the delay is >1 s, use usleep because timing does not need to
-	 * be so precise.
-	 */
+	/* If the delay is >1 s, use internal_sleep because timing does not need to be so precise. */
 	if (usecs > 1000000) {
-		usleep(usecs);
+		internal_sleep(usecs);
 	} else {
 		myusec_delay(usecs);
 	}