mirror of https://github.com/ARMmbed/mbed-os.git
Improved logic in wait_us to avoid division operation in sub-millisec case
parent
93340828ae
commit
101cade4e3
|
@ -39,11 +39,10 @@ void wait_us(int us)
|
||||||
const ticker_data_t *const ticker = get_us_ticker_data();
|
const ticker_data_t *const ticker = get_us_ticker_data();
|
||||||
|
|
||||||
uint32_t start = ticker_read(ticker);
|
uint32_t start = ticker_read(ticker);
|
||||||
|
if ((us >= 1000) && core_util_are_interrupts_enabled()) {
|
||||||
// Use the RTOS to wait for millisecond delays if possible
|
// Use the RTOS to wait for millisecond delays if possible
|
||||||
int ms = us / 1000;
|
|
||||||
if ((ms > 0) && core_util_are_interrupts_enabled()) {
|
|
||||||
sleep_manager_lock_deep_sleep();
|
sleep_manager_lock_deep_sleep();
|
||||||
Thread::wait((uint32_t)ms);
|
Thread::wait((uint32_t)us / 1000);
|
||||||
sleep_manager_unlock_deep_sleep();
|
sleep_manager_unlock_deep_sleep();
|
||||||
}
|
}
|
||||||
// Use busy waiting for sub-millisecond delays, or for the whole
|
// Use busy waiting for sub-millisecond delays, or for the whole
|
||||||
|
|
Loading…
Reference in New Issue