Skip to content

Commit 506f6b4

Browse files
SenRamakriCruz Monrreal II
authored andcommitted
Improved logic in wait_us to avoid division operation in sub-millisec case
1 parent 922eddf commit 506f6b4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

platform/mbed_wait_api_rtos.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ void wait_us(int us)
3939
const ticker_data_t *const ticker = get_us_ticker_data();
4040

4141
uint32_t start = ticker_read(ticker);
42-
// Use the RTOS to wait for millisecond delays if possible
43-
int ms = us / 1000;
44-
if ((ms > 0) && core_util_are_interrupts_enabled()) {
42+
if ((us >= 1000) && core_util_are_interrupts_enabled()) {
43+
// Use the RTOS to wait for millisecond delays if possible
4544
sleep_manager_lock_deep_sleep();
46-
Thread::wait((uint32_t)ms);
45+
Thread::wait((uint32_t)us / 1000);
4746
sleep_manager_unlock_deep_sleep();
4847
}
4948
// Use busy waiting for sub-millisecond delays, or for the whole

0 commit comments

Comments
 (0)