Author: hailfinger Date: Fri Apr 5 10:06:10 2013 New Revision: 1667 URL: http://flashrom.org/trac/flashrom/changeset/1667
Log: 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 Acked-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at
Modified: trunk/buspirate_spi.c trunk/programmer.h trunk/udelay.c
Modified: trunk/buspirate_spi.c ============================================================================== --- trunk/buspirate_spi.c Mon Apr 1 21:34:53 2013 (r1666) +++ trunk/buspirate_spi.c Fri Apr 5 10:06:10 2013 (r1667) @@ -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")))
Modified: trunk/programmer.h ============================================================================== --- trunk/programmer.h Mon Apr 1 21:34:53 2013 (r1666) +++ trunk/programmer.h Fri Apr 5 10:06:10 2013 (r1667) @@ -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
Modified: trunk/udelay.c ============================================================================== --- trunk/udelay.c Mon Apr 1 21:34:53 2013 (r1666) +++ trunk/udelay.c Fri Apr 5 10:06:10 2013 (r1667) @@ -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); }