Skip to content
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

sys/ztimer/xtimer_compat: fix bug introduced in #17690 #17705

Merged
merged 2 commits into from
Feb 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions sys/include/ztimer/xtimer_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,29 @@ extern "C" {
#define XTIMER_WIDTH (32)
#define XTIMER_MASK (0)

/**
* a default XTIMER_BACKOFF value, this is not used by ztimer, but other code
* uses this value to set timers
*/

#ifndef XTIMER_BACKOFF
#define XTIMER_BACKOFF 1
#endif

typedef ztimer_t xtimer_t;
typedef uint32_t xtimer_ticks32_t;
typedef uint64_t xtimer_ticks64_t;

static inline void xtimer_init(void)
{
ztimer_init();
}

static inline bool xtimer_is_set(const xtimer_t *timer)
{
return ztimer_is_set(ZTIMER_USEC, timer);
}

static inline xtimer_ticks32_t xtimer_ticks(uint32_t ticks)
{
return ticks;
Expand Down Expand Up @@ -142,16 +161,16 @@ static inline void xtimer_tsleep32(xtimer_ticks32_t ticks)
xtimer_usleep(xtimer_usec_from_ticks(ticks));
}

static inline uint64_t xtimer_tsleep64(xtimer_ticks64_t ticks)
static inline void xtimer_tsleep64(xtimer_ticks64_t ticks)
{
const uint32_t max_sleep = UINT32_MAX;
uint64_t time = xtimer_usec_from_ticks64(ticks);

while (time > max_sleep) {
xtimer_usleep(clock, max_sleep);
xtimer_usleep(max_sleep);
time -= max_sleep;
}
xtimer_usleep(clock, time);
xtimer_usleep(time);
}

static inline void xtimer_set(xtimer_t *timer, uint32_t offset)
Expand Down Expand Up @@ -197,6 +216,16 @@ static inline int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t us)
return 0;
}

static inline int xtimer_rmutex_lock_timeout(rmutex_t *rmutex, uint64_t us)
{
assert(us <= UINT32_MAX);
if (ztimer_rmutex_lock_timeout(ZTIMER_USEC, rmutex, us)) {
/* Impedance matching required: Convert -ECANCELED error code to -1: */
return -1;
}
return 0;
}

static inline void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout)
{
ztimer_set_timeout_flag(ZTIMER_USEC, t, timeout);
Expand Down