[−][src]Function rpi_pico_sdk::best_effort_wfe_or_timeout
pub unsafe extern "C" fn best_effort_wfe_or_timeout(
timeout_timestamp: absolute_time_t
) -> bool
\brief Helper method for blocking on a timeout \ingroup sleep
This method will return in response to a an event (as per __wfe) or when the target time is reached, or at any point before.
This method can be used to implement a lower power polling loop waiting on some condition signalled by an event (__sev()).
This is called \a best_effort because under certain circumstances (notably the default timer pool being disabled or full) the best effort is simply to return immediately without a __wfe, thus turning the calling code into a busy wait.
Example usage:
bool my_function_with_timeout_us(uint64_t timeout_us) {
absolute_time_t timeout_time = make_timeout_time_us(timeout_us);
do {
// each time round the loop, we check to see if the condition
// we are waiting on has happened
if (my_check_done()) {
// do something
return true;
}
// will try to sleep until timeout or the next processor event
} while (!best_effort_wfe_or_timeout(timeout_time));
return false; // timed out
}
@param timeout_timestamp the timeout time @return true if the target time is reached, false otherwise