Skip to content

Commit 493e378

Browse files
Merge pull request #5216 from kjbracey-arm/UARTSerial_wait
Avoid wait_ms() spin
2 parents 0b796cd + de4ced3 commit 493e378

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

drivers/UARTSerial.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
#include <errno.h>
2020
#include "UARTSerial.h"
2121
#include "platform/mbed_poll.h"
22+
23+
#if MBED_CONF_RTOS_PRESENT
24+
#include "rtos/Thread.h"
25+
#else
2226
#include "platform/mbed_wait_api.h"
27+
#endif
2328

2429
namespace mbed {
2530

@@ -277,6 +282,17 @@ void UARTSerial::tx_irq(void)
277282
}
278283
}
279284

285+
void UARTSerial::wait_ms(uint32_t millisec)
286+
{
287+
/* wait_ms implementation for RTOS spins until exact microseconds - we
288+
* want to just sleep until next tick.
289+
*/
290+
#if MBED_CONF_RTOS_PRESENT
291+
rtos::Thread::wait(millisec);
292+
#else
293+
::wait_ms(millisec);
294+
#endif
295+
}
280296
} //namespace mbed
281297

282298
#endif //(DEVICE_SERIAL && DEVICE_INTERRUPTIN)

drivers/UARTSerial.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ class UARTSerial : private SerialBase, public FileHandle, private NonCopyable<UA
166166

167167
private:
168168

169+
void wait_ms(uint32_t millisec);
170+
169171
/** SerialBase lock override */
170172
virtual void lock(void);
171173

platform/mbed_poll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
6666
#ifdef MBED_CONF_RTOS_PRESENT
6767
// TODO - proper blocking
6868
// wait for condition variable, wait queue whatever here
69-
rtos::Thread::yield();
69+
rtos::Thread::wait(1);
7070
#endif
7171
}
7272
return count;

0 commit comments

Comments
 (0)