Merge pull request #15076 from benpicco/xtimer_msleep
xtimer: introduce xtimer_msleep()
This commit is contained in:
commit
010925d77d
@ -146,6 +146,13 @@ void xtimer_init(void);
|
|||||||
*/
|
*/
|
||||||
static inline void xtimer_sleep(uint32_t seconds);
|
static inline void xtimer_sleep(uint32_t seconds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Pause the execution of a thread for some milliseconds
|
||||||
|
*
|
||||||
|
* @param[in] milliseconds the amount of milliseconds the thread should sleep
|
||||||
|
*/
|
||||||
|
static inline void xtimer_msleep(uint32_t milliseconds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Pause the execution of a thread for some microseconds
|
* @brief Pause the execution of a thread for some microseconds
|
||||||
*
|
*
|
||||||
|
|||||||
@ -172,6 +172,11 @@ static inline void xtimer_spin(xtimer_ticks32_t ticks) {
|
|||||||
_xtimer_spin(ticks.ticks32);
|
_xtimer_spin(ticks.ticks32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void xtimer_msleep(uint32_t milliseconds)
|
||||||
|
{
|
||||||
|
_xtimer_tsleep64(_xtimer_ticks_from_usec64(milliseconds * US_PER_MS));
|
||||||
|
}
|
||||||
|
|
||||||
static inline void xtimer_usleep(uint32_t microseconds)
|
static inline void xtimer_usleep(uint32_t microseconds)
|
||||||
{
|
{
|
||||||
_xtimer_tsleep32(_xtimer_ticks_from_usec(microseconds));
|
_xtimer_tsleep32(_xtimer_ticks_from_usec(microseconds));
|
||||||
|
|||||||
@ -68,10 +68,35 @@ static inline uint64_t xtimer_now_usec64(void)
|
|||||||
return ztimer_now(ZTIMER_USEC);
|
return ztimer_now(ZTIMER_USEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void _ztimer_sleep_scale(ztimer_clock_t *clock, uint32_t time, uint32_t scale)
|
||||||
|
{
|
||||||
|
const uint32_t max_sleep = UINT32_MAX / scale;
|
||||||
|
|
||||||
|
while (time > max_sleep) {
|
||||||
|
ztimer_sleep(clock, max_sleep * scale);
|
||||||
|
time -= max_sleep;
|
||||||
|
}
|
||||||
|
|
||||||
|
ztimer_sleep(clock, time * scale);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void xtimer_sleep(uint32_t seconds)
|
static inline void xtimer_sleep(uint32_t seconds)
|
||||||
{
|
{
|
||||||
/* TODO: use ZTIMER_SEC */
|
/* TODO: use ZTIMER_SEC */
|
||||||
ztimer_sleep(ZTIMER_USEC, seconds * 1000000LU);
|
if (IS_ACTIVE(MODULE_ZTIMER_MSEC)) {
|
||||||
|
_ztimer_sleep_scale(ZTIMER_MSEC, seconds, 1000);
|
||||||
|
} else {
|
||||||
|
_ztimer_sleep_scale(ZTIMER_USEC, seconds, 1000000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void xtimer_msleep(uint32_t milliseconds)
|
||||||
|
{
|
||||||
|
if (IS_ACTIVE(MODULE_ZTIMER_MSEC)) {
|
||||||
|
ztimer_sleep(ZTIMER_MSEC, milliseconds);
|
||||||
|
} else {
|
||||||
|
_ztimer_sleep_scale(ZTIMER_USEC, seconds, 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void xtimer_usleep(uint32_t microseconds)
|
static inline void xtimer_usleep(uint32_t microseconds)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user