-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Wait API updated to remove deepsleep lock #8189
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As stated by Kevin, we could use the low power ticker in that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't want to use additional ticker for backwards compatibility, we should be discouraging users from using
I am not sure how we do this, I have updated the API description and will make sure code does not get in patch release. Do let me know how we can communicate this in better way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok we either trap or not, having it error out in one mode, but happily work without even a warning, in other doesn't make much sense to me. I don't get this part and I really hope every use of
I'm happy to show a warning and change the behaviour for next major. |
||
#endif | ||
} else { | ||
rtos::ThisThread::sleep_for(ms); | ||
} | ||
} | ||
|
||
/* The actual time delay may be 1 less usec */ | ||
void wait_us(int us) | ||
{ | ||
if (us > 10000) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kjbracey-arm - 0.1s / 0.01s? I would like to keep it same for https://github.com/ARMmbed/mbed-os/pull/8189/files#diff-5a106edf0944ae7ba2d1bf95153fb0a0R30 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, 0.01s makes more sense. I think I probably meant to type that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0.01s seems fine |
||
MBED_WARNING(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_UNKNOWN), | ||
"wait_us blocks deep sleep, wait_ms recommended for long delays\n"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was suggesting dropping the sleep functionality from this entirely - restoring it to be the same as the non-RTOS version, hence the message above. What's your thought on that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, that's kind of my design point. I also prefer yielding to other threads, but I want to define whether a call yields or not - and we would already have the yielding call, which is This is a call which already spins for up to a millisecond to do its business, so is already inherently thread-unfriendly - I want people to be using Uses of this should be rare. (Can we do a quick audit - how many actual direct wait_us users are there in tree? Most examples I can think of are GPIO "reset" pulses on init.) And there are some occasions where it is important not to yield, so I'd like to have an API explicitly defined as that, not dependent on parameter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets get more opinions over here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, and this behaviour was my original reason to have my value warning above - we're saying "you do realise you're spinning for 10ms, right?". Not just the deep sleep issue. I also think you've got a better chance of getting the time you were hoping each time with the spin than if you yield, where you might suddenly be hit with a full 10ms timeslice from another running thread. Basically anyone wanting sub-millisecond resolution is having special requirements that can't really be catered for if you start dragging the RTOS into it. My feeling is that the current There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the intent here to have Also agree that current There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, just searched through the in-tree source, and I can see around a 100 calls to Actually, no, I see a couple in one of the "onboard_modem_api.c" files, in "wiggle the reset line" code. They're a full second, so would hit the error/warning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more thought, we can change |
||
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