From abe9516fdc2f7ac08153e7980af3ea6b130dbb0e Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 16 Aug 2017 14:58:30 +0800 Subject: [PATCH] newlib: implement usleep --- components/console/linenoise/linenoise.c | 2 +- components/newlib/time.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/components/console/linenoise/linenoise.c b/components/console/linenoise/linenoise.c index 5e39866ba..c0f551d67 100644 --- a/components/console/linenoise/linenoise.c +++ b/components/console/linenoise/linenoise.c @@ -898,7 +898,7 @@ int linenoiseProbe() { int timeout_ms = 200; size_t read_bytes = 0; while (timeout_ms > 0 && read_bytes < 4) { // response is ESC[0n or ESC[3n - usleep(1000); + usleep(10000); char c; int cb = fread(&c, 1, 1, stdin); read_bytes += cb; diff --git a/components/newlib/time.c b/components/newlib/time.c index 8764c4076..a729288f5 100644 --- a/components/newlib/time.c +++ b/components/newlib/time.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -244,6 +245,20 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) #endif } +int usleep(useconds_t us) +{ + const int us_per_tick = portTICK_PERIOD_MS * 1000; + if (us < us_per_tick) { + ets_delay_us((uint32_t) us); + } else { + /* since vTaskDelay(1) blocks for anywhere between 0 and portTICK_PERIOD_MS, + * round up to compensate. + */ + vTaskDelay((us + us_per_tick - 1) / us_per_tick); + } + return 0; +} + uint32_t system_get_time(void) { #if defined( WITH_FRC1 ) || defined( WITH_RTC )