Skip to content

Avoid wait_ms() spin #5216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions drivers/UARTSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
#include <errno.h>
#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 {

Expand Down Expand Up @@ -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)
2 changes: 2 additions & 0 deletions drivers/UARTSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class UARTSerial : private SerialBase, public FileHandle, private NonCopyable<UA

private:

void wait_ms(uint32_t millisec);

/** SerialBase lock override */
virtual void lock(void);

Expand Down
2 changes: 1 addition & 1 deletion platform/mbed_poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down