From b18332cb4da89a2f533d46f8ea54c46dcdd774fb Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Thu, 28 Sep 2017 10:44:43 +0300 Subject: [PATCH 1/2] Avoid wait_ms() spin System's wait_ms() spins to achieve a precise delay - we don't want this. Call Thread::wait directly. --- drivers/UARTSerial.cpp | 16 ++++++++++++++++ drivers/UARTSerial.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/drivers/UARTSerial.cpp b/drivers/UARTSerial.cpp index 96cdc831d8..5cad4ffc82 100644 --- a/drivers/UARTSerial.cpp +++ b/drivers/UARTSerial.cpp @@ -19,7 +19,12 @@ #include #include "UARTSerial.h" #include "platform/mbed_poll.h" + +#if MBED_CONF_RTOS_PRESENT +#include "rtos/Thread.h" +#else #include "platform/mbed_wait_api.h" +#endif namespace mbed { @@ -277,6 +282,17 @@ void UARTSerial::tx_irq(void) } } +void UARTSerial::wait_ms(uint32_t millisec) +{ + /* wait_ms implementation for RTOS spins until exact microseconds - we + * want to just sleep until next tick. + */ +#if MBED_CONF_RTOS_PRESENT + rtos::Thread::wait(millisec); +#else + ::wait_ms(millisec); +#endif +} } //namespace mbed #endif //(DEVICE_SERIAL && DEVICE_INTERRUPTIN) diff --git a/drivers/UARTSerial.h b/drivers/UARTSerial.h index ebb5779c1c..df07f2e075 100644 --- a/drivers/UARTSerial.h +++ b/drivers/UARTSerial.h @@ -160,6 +160,8 @@ public: private: + void wait_ms(uint32_t millisec); + /** SerialBase lock override */ virtual void lock(void); From de4ced33a6c6f181081ddde7f3258410cc4c47ac Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Mon, 2 Oct 2017 09:59:24 +0300 Subject: [PATCH 2/2] Make poll() use wait(1) rather than yield() Spinning while polling is overly CPU intensive, and inconsistent with the current blocking behaviour of UARTSerial. Change to use Thread::wait(1) to match UARTSerial. --- platform/mbed_poll.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/mbed_poll.cpp b/platform/mbed_poll.cpp index 28492010d4..c2a08fa3dd 100644 --- a/platform/mbed_poll.cpp +++ b/platform/mbed_poll.cpp @@ -66,7 +66,7 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout) #ifdef MBED_CONF_RTOS_PRESENT // TODO - proper blocking // wait for condition variable, wait queue whatever here - rtos::Thread::yield(); + rtos::Thread::wait(1); #endif } return count;