-
Notifications
You must be signed in to change notification settings - Fork 3k
Wait API updated to remove deepsleep lock #8189
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,21 +23,18 @@ | |
#include "rtos/rtos.h" | ||
#include "platform/mbed_critical.h" | ||
#include "platform/mbed_power_mgmt.h" | ||
#include "platform/mbed_error.h" | ||
#include "rtos/ThisThread.h" | ||
|
||
void wait(float s) | ||
{ | ||
wait_us(s * 1000000.0f); | ||
} | ||
|
||
void wait_ms(int ms) | ||
{ | ||
wait_us(ms * 1000); | ||
} | ||
if ((s >= 0.01f) && core_util_are_interrupts_enabled()) { | ||
wait_ms(s * 1000.0f); | ||
return; | ||
} | ||
|
||
void wait_us(int us) | ||
{ | ||
uint32_t us = (s * 1000000.0f); | ||
const ticker_data_t *const ticker = get_us_ticker_data(); | ||
|
||
uint32_t start = ticker_read(ticker); | ||
if ((us >= 1000) && core_util_are_interrupts_enabled()) { | ||
// Use the RTOS to wait for millisecond delays if possible | ||
|
@@ -50,5 +47,32 @@ void wait_us(int us) | |
while ((ticker_read(ticker) - start) < (uint32_t)us); | ||
} | ||
|
||
/* The actual time delay may be up to one timer tick less - 1 msec */ | ||
void wait_ms(int ms) | ||
{ | ||
if (core_util_is_isr_active() || !core_util_are_interrupts_enabled()) { | ||
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED | ||
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_INVALID_OPERATION), | ||
"Deprecated behavior: milli-sec delay should not be used in interrupt.\n"); | ||
#else | ||
wait_us(ms * 1000); | ||
|
||
#endif | ||
} else { | ||
rtos::ThisThread::sleep_for(ms); | ||
} | ||
} | ||
|
||
/* The actual time delay may be 1 less usec */ | ||
void wait_us(int us) | ||
{ | ||
if (us > 10000) { | ||
|
||
MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_UNKNOWN), | ||
"wait_us blocks deep sleep, wait_ms recommended for long delays\n"); | ||
} | ||
|
||
const ticker_data_t *const ticker = get_us_ticker_data(); | ||
uint32_t start = ticker_read(ticker); | ||
while ((ticker_read(ticker) - start) < (uint32_t)us); | ||
} | ||
|
||
#endif // #if MBED_CONF_RTOS_PRESENT | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If wait is used from an interrupt handler it will only trap if the delay is
>= 10ms
. Is this acceptable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.. wait will not trap